Message ID | 20230210041030.865478-1-zyytlz.wz@163.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp747319wrn; Thu, 9 Feb 2023 20:25:53 -0800 (PST) X-Google-Smtp-Source: AK7set9husPx8s+ECm6EE75qWxcrzq752EORNimLC04DiRIMVfiqpPt+0pDf+uzuOZ1yGE9vY5p3 X-Received: by 2002:a50:c05e:0:b0:4ab:250d:fd74 with SMTP id u30-20020a50c05e000000b004ab250dfd74mr3846062edd.9.1676003153075; Thu, 09 Feb 2023 20:25:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676003153; cv=none; d=google.com; s=arc-20160816; b=Ro5nq9W/xmCjuy1XRTEJiI4ZKWAV17/31zt+XWzNMqLfN5nqz7DJjUhFcv8TKhDIfp vwQQy8Z7lULNrEh+bE0BXx7IGS0F0asOqc9/mOGJE4bygBQyqbag0IOm7fOS+dcXZcln Ezew4hngqk3KnLHVSRxyfWKgPT0NMJVKZy+qWisuNUJAr8A5Aijekk90fdPO4XWuo1/Z lstys/XsBmh/bo2+iaUUbGiUyv3cSR7JXwczLeF5LMTqHLH046oPqkI0dPN/tKs8bO5/ bzV8Mwq41/DpTGVeQPr89XUUr6PeCEGvs16PPrLwXuGPsp3uhDFXcypvhE2HjPCGe167 S7fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=oGikcNFZc3el4R4e5AyREsNxJCPuWtBQAXD7oOnxock=; b=xIjb+d2cJjKTt5LNN2ckO5ipB03HBrwk2L+zTTHYH1PKUL4rL7STWEBjWf1n2cDDIO clA6s68XOpc3y+rFMebO5e2OXwaLTO33aa6HsiIKkLsQqxXPN6rzkrP6fOrXdev53qTe tED3kgRM7lv71gRSmFbYULyC3ucTHHR/og1JId7JRx8mDGHJfWvAcWFK7DwjaKCr6FRc Tc4ib0s42WeX7ip2/pJv1zyGenn8v72VGpIJ1k2EUy2wAI4aBx7f18GbgrJNUlC/1i7O DPyNEBWn6xtyXAP116FqPAjcoi9/qyKElALdgsMRzaxy6JacflBflo8dgQZYLLkq7cm5 +Fwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=n3l44jrq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fm20-20020a1709072ad400b007c07d0dbe85si3839850ejc.463.2023.02.09.20.25.29; Thu, 09 Feb 2023 20:25:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=n3l44jrq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231246AbjBJEL3 (ORCPT <rfc822;ybw1215001957@gmail.com> + 99 others); Thu, 9 Feb 2023 23:11:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230262AbjBJEL0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 9 Feb 2023 23:11:26 -0500 Received: from m12.mail.163.com (m12.mail.163.com [123.126.96.234]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 138E08A5E; Thu, 9 Feb 2023 20:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=oGikc NFZc3el4R4e5AyREsNxJCPuWtBQAXD7oOnxock=; b=n3l44jrqs7cmBamNxL3+B qz0YihQC74inQu5cPZ0cYhj/UesFBgdV09BAYdfDTtzl6rXIB8iflL2zi5nH2aaG fX/67H4MqYjbjjMVVbyvHB06+EahnHdCIezXVd1pFCtIW5dMst4q269Sh42EuRjt rnZWLYVv/AGLD3mxb8Kpxo= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by smtp20 (Coremail) with SMTP id H91pCgC3gba3w+VjdWhCDg--.52843S2; Fri, 10 Feb 2023 12:10:32 +0800 (CST) From: Zheng Wang <zyytlz.wz@163.com> To: marcel@holtmann.org Cc: hackerzheng666@gmail.com, alex000young@gmail.com, johan.hedberg@gmail.com, luiz.dentz@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Zheng Wang <zyytlz.wz@163.com> Subject: [PATCH] Bluetooth: hci_core: Fix poential Use-after-Free bug in hci_remove_adv_monitor Date: Fri, 10 Feb 2023 12:10:30 +0800 Message-Id: <20230210041030.865478-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: H91pCgC3gba3w+VjdWhCDg--.52843S2 X-Coremail-Antispam: 1Uf129KBjvdXoWrZw47GF47trWxWw4UGF43trb_yoWfuFbE9r 1xAryfWr4UGF15AF47ZFW5Zr1Utw1rZF4fta4fXFWYq34qgwnxtr1IvwnxZFyxuw4qyry3 AanxW34Y9w15tjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRKBT5JUUUUU== X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXBgSU1Xl5kpygQAAsq X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757416682466481541?= X-GMAIL-MSGID: =?utf-8?q?1757416682466481541?= |
Series |
Bluetooth: hci_core: Fix poential Use-after-Free bug in hci_remove_adv_monitor
|
|
Commit Message
Zheng Wang
Feb. 10, 2023, 4:10 a.m. UTC
In hci_remove_adv_monitor, if it gets into HCI_ADV_MONITOR_EXT_MSFT case,
the function will free the monitor and print its handle after that.
Fix it by switch the order.
Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
net/bluetooth/hci_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi Zheng, On Thu, Feb 9, 2023 at 8:11 PM Zheng Wang <zyytlz.wz@163.com> wrote: > > In hci_remove_adv_monitor, if it gets into HCI_ADV_MONITOR_EXT_MSFT case, > the function will free the monitor and print its handle after that. > > Fix it by switch the order. > > Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor") > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > --- > net/bluetooth/hci_core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > index b65c3aabcd53..db3352c60de6 100644 > --- a/net/bluetooth/hci_core.c > +++ b/net/bluetooth/hci_core.c > @@ -1980,9 +1980,9 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, > goto free_monitor; > > case HCI_ADV_MONITOR_EXT_MSFT: > - status = msft_remove_monitor(hdev, monitor); > bt_dev_dbg(hdev, "%s remove monitor %d msft status %d", > hdev->name, monitor->handle, status); > + status = msft_remove_monitor(hdev, monitor); I wonder if it is not a good idea to move the logging inside msft_remove_monitor? > break; > } > > -- > 2.25.1 >
Luiz Augusto von Dentz <luiz.dentz@gmail.com> 于2023年2月11日周六 03:53写道: > > Hi Zheng, > > On Thu, Feb 9, 2023 at 8:11 PM Zheng Wang <zyytlz.wz@163.com> wrote: > > > > In hci_remove_adv_monitor, if it gets into HCI_ADV_MONITOR_EXT_MSFT case, > > the function will free the monitor and print its handle after that. > > > > Fix it by switch the order. > > > > Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor") > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > > --- > > net/bluetooth/hci_core.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > > index b65c3aabcd53..db3352c60de6 100644 > > --- a/net/bluetooth/hci_core.c > > +++ b/net/bluetooth/hci_core.c > > @@ -1980,9 +1980,9 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, > > goto free_monitor; > > > > case HCI_ADV_MONITOR_EXT_MSFT: > > - status = msft_remove_monitor(hdev, monitor); > > bt_dev_dbg(hdev, "%s remove monitor %d msft status %d", > > hdev->name, monitor->handle, status); > > + status = msft_remove_monitor(hdev, monitor); > > I wonder if it is not a good idea to move the logging inside > msft_remove_monitor? > > > break; > > } > > Hello Luiz, Thanks for your quick reply. I think moving it inside msft_remove_monitor is a good idea. Because the variable status is returned by msft_remove_monitor. The call chain is msft_remove_monitor ->msft_remove_monitor_sync ->msft_le_cancel_monitor_advertisement_cb ->hci_free_adv_monitor ->kfree(monitor); We could mov the bt_dev_dbg to the location before hci_free_adv_monitor calling and delete the releated code in hci_remove_adv_monitor. If you agree with that, I'll make another patch. Best regards, Zheng Wang
Dear Zheng, Thank you for your patch. Am 10.02.23 um 05:10 schrieb Zheng Wang: > In hci_remove_adv_monitor, if it gets into HCI_ADV_MONITOR_EXT_MSFT case, > the function will free the monitor and print its handle after that. > > Fix it by switch the order. … by switch*ing* … There is a small typo in the commit message summary/title: po*t*ential > Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor") > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > --- > net/bluetooth/hci_core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) […] Kind regards, Paul
Paul Menzel <pmenzel@molgen.mpg.de> 于2023年2月13日周一 16:19写道: > > Dear Zheng, > > > Thank you for your patch. > > Am 10.02.23 um 05:10 schrieb Zheng Wang: > > In hci_remove_adv_monitor, if it gets into HCI_ADV_MONITOR_EXT_MSFT case, > > the function will free the monitor and print its handle after that. > > > > Fix it by switch the order. > > … by switch*ing* … > > There is a small typo in the commit message summary/title: po*t*ential > Hi Paul, Thanks for pointing that out ^^. Will correct it in the next version of patch. Best regards, Zheng Wang
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index b65c3aabcd53..db3352c60de6 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1980,9 +1980,9 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, goto free_monitor; case HCI_ADV_MONITOR_EXT_MSFT: - status = msft_remove_monitor(hdev, monitor); bt_dev_dbg(hdev, "%s remove monitor %d msft status %d", hdev->name, monitor->handle, status); + status = msft_remove_monitor(hdev, monitor); break; }