From patchwork Thu Mar 24 02:39:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lin Ma X-Patchwork-Id: 12790321 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84BF8C433EF for ; Thu, 24 Mar 2022 02:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347843AbiCXCqH (ORCPT ); Wed, 23 Mar 2022 22:46:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347840AbiCXCqG (ORCPT ); Wed, 23 Mar 2022 22:46:06 -0400 X-Greylist: delayed 314 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 23 Mar 2022 19:44:33 PDT Received: from zju.edu.cn (spam.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 458705D5D5; Wed, 23 Mar 2022 19:44:32 -0700 (PDT) Received: from localhost.localdomain (unknown [222.205.7.202]) by mail-app4 (Coremail) with SMTP id cS_KCgD3eRDJ2TtieeI_AA--.6621S4; Thu, 24 Mar 2022 10:39:05 +0800 (CST) From: Lin Ma To: jk@codeconstruct.com.au, matt@codeconstruct.com.au, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Lin Ma Subject: [PATCH v0] mctp: fix netdev reference bug Date: Thu, 24 Mar 2022 10:39:04 +0800 Message-Id: <20220324023904.7173-1-linma@zju.edu.cn> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-CM-TRANSID: cS_KCgD3eRDJ2TtieeI_AA--.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vtljo62m3hxhgxhubq/ Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In extended addressing mode, function mctp_local_output() fetch netdev through dev_get_by_index_rcu, which won't increase netdev's reference counter. Hence, the reference may underflow when mctp_local_output calls dev_put(), results in possible use after free. This patch adds dev_hold() to fix the reference bug. Fixes: 99ce45d5e7db ("mctp: Implement extended addressing") Signed-off-by: Lin Ma --- net/mctp/route.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/mctp/route.c b/net/mctp/route.c index e52cef750500..a9e5d6c40c65 100644 --- a/net/mctp/route.c +++ b/net/mctp/route.c @@ -817,6 +817,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt, return rc; } + dev_hold(dev); rt->dev = __mctp_dev_get(dev); rcu_read_unlock();