[v2] Bluetooth: hci_core: Fix poential Use-after-Free bug in hci_remove_adv_monitor
Message ID | 20230217100223.702330-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 s9csp804755wrn; Fri, 17 Feb 2023 02:14:17 -0800 (PST) X-Google-Smtp-Source: AK7set9V065z7I4pzyXZxcBjkOUener4cTtVyuQt+UYWj7fADHaroDaQbr3bu6Pn6+uOiXMHtFoL X-Received: by 2002:a17:907:7f8b:b0:88f:a23e:6f0d with SMTP id qk11-20020a1709077f8b00b0088fa23e6f0dmr923687ejc.37.1676628857053; Fri, 17 Feb 2023 02:14:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676628857; cv=none; d=google.com; s=arc-20160816; b=Yz5TPVrAzDdlQR+qN9viAzjwsyuxEzSH4qOTDndRngFJYGN00huUOgy/XworfrVPnb i7xlCrwhDQqQTgdAEolUgLWtvqfS4XQIyd5bqN55MsBLN4Hk3pxpHlaQHF8htvQ6StQp dV42IKPQ1WCinhxZrHUixCwroIh73b6R1FE2edMlEoKa+YcwTgMurkX/Z/1jqItt+Qus gwk+4XQLdFdliO8hPitx2CAE0Ug0lp+WYUpaU2wPZ5HKe/2dwAZkDGnQCP1bZj68iUv2 IeIeI2i5I8yObdrY96LQITO+rueP2O+UP8vhH5NjxNJqVRr/VT9cW/i9OoACTO1FKYzY MS7g== 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=ZBdy2Nmsi/nHTRTs/Crmb7sXfqr4oP2fZCHYUPlE0fE=; b=0Ah6FfBjwY182F09IvLBLclmncdXRD8k1U+5GiGLpRked9t92rKSnoeEDcrt1TNxN5 nwn6AUxHGoajTWgKETP/4kZlzA5c4SU7NWQfbr49tWOMdHjY4vPGkU5YqLkAu+iRWUGJ qAyeNyVWM4MzCCgCNV6MRBEQgK1g5owIPIud6Rse78A1/Sls3h3KxV6SU+jB4UyvLMOK DL8Bp/ezmPWbiSQRc94bMryzOFDSnjNU1DLnzHoXROTj1qWT/oFVleWIuErz1V19hH0r 2RXaDBcTLQ3XbVB8GJOg5btEoIujbBGZ/E5dK3ahGAtIypn5UbNOQtq27wy3i+lCZ2vA HRhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jpqmdvt3; 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 wj18-20020a170907051200b00887dee61405si3839377ejb.967.2023.02.17.02.13.53; Fri, 17 Feb 2023 02:14:17 -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=jpqmdvt3; 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 S229724AbjBQKFA (ORCPT <rfc822;aimixsaka@gmail.com> + 99 others); Fri, 17 Feb 2023 05:05:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229826AbjBQKEu (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 17 Feb 2023 05:04:50 -0500 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 899635D3F6; Fri, 17 Feb 2023 02:04:46 -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=ZBdy2 Nmsi/nHTRTs/Crmb7sXfqr4oP2fZCHYUPlE0fE=; b=jpqmdvt3VRjTBFF+F1o2/ ETijjOy1/NtIbri5pGeailC3GPWj1GMVzRdzwnY5O+yyUhfus5MJCMAMzet19JT0 Jcmdke172WyFBBYQcpQXfWU8anHOXcl7M4QSMO5BQ2lSp6kzdrZCE08OHVf7HhTc OcGZv9LjgDO4l8dKr1RJDo= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g4-4 (Coremail) with SMTP id _____wA3b7+xUO9jalZ3AA--.3246S2; Fri, 17 Feb 2023 18:02:25 +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, pmenzel@molgen.mpg.de, Zheng Wang <zyytlz.wz@163.com> Subject: [PATCH v2] Bluetooth: hci_core: Fix poential Use-after-Free bug in hci_remove_adv_monitor Date: Fri, 17 Feb 2023 18:02:23 +0800 Message-Id: <20230217100223.702330-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wA3b7+xUO9jalZ3AA--.3246S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7urWUArW8Cw4fKr15GF47XFb_yoW8XFyxpF W5JF1Y9rW8tr17XF1xAa1fWFyUJw4YgFZ7Cr98A34fJwsxt3yktw18Ga4qqFyfuFZ5tF42 vF1ktrs8WayDWFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziX_-dUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXAQZU1Xl5pZyywABsq 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,RCVD_IN_MSPIKE_H2, 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?1758072780570695951?= X-GMAIL-MSGID: =?utf-8?q?1758072780570695951?= |
Series |
[v2] Bluetooth: hci_core: Fix poential Use-after-Free bug in hci_remove_adv_monitor
|
|
Commit Message
Zheng Wang
Feb. 17, 2023, 10:02 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 removing the logging into msft_le_cancel_monitor_advertisement_cb
before calling hci_free_adv_monitor.
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
v2:
- move the logging inside msft_remove_monitor suggested by Luiz
---
net/bluetooth/hci_core.c | 2 --
net/bluetooth/msft.c | 2 ++
2 files changed, 2 insertions(+), 2 deletions(-)
Comments
friendly ping Zheng Wang <zyytlz.wz@163.com> 于2023年2月17日周五 18:05写道: > > 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 removing the logging into msft_le_cancel_monitor_advertisement_cb > before calling hci_free_adv_monitor. > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > --- > v2: > - move the logging inside msft_remove_monitor suggested by Luiz > --- > net/bluetooth/hci_core.c | 2 -- > net/bluetooth/msft.c | 2 ++ > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > index b65c3aabcd53..69b82c2907ff 100644 > --- a/net/bluetooth/hci_core.c > +++ b/net/bluetooth/hci_core.c > @@ -1981,8 +1981,6 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, > > 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); > break; > } > > diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c > index bee6a4c656be..4b35f0ed1360 100644 > --- a/net/bluetooth/msft.c > +++ b/net/bluetooth/msft.c > @@ -286,6 +286,8 @@ static int msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev, > * suspend. It will be re-monitored on resume. > */ > if (!msft->suspending) { > + bt_dev_dbg(hdev, "%s remove monitor %d status %d", hdev->name, > + monitor->handle, status); > hci_free_adv_monitor(hdev, monitor); > > /* Clear any monitored devices by this Adv Monitor */ > -- > 2.25.1 >
On Mon, Mar 13, 2023 at 05:55:35PM +0800, Zheng Hacker wrote: > friendly ping > > Zheng Wang <zyytlz.wz@163.com> 于2023年2月17日周五 18:05写道: > > > > 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 removing the logging into msft_le_cancel_monitor_advertisement_cb > > before calling hci_free_adv_monitor. > > > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > > --- > > v2: > > - move the logging inside msft_remove_monitor suggested by Luiz > > --- > > net/bluetooth/hci_core.c | 2 -- > > net/bluetooth/msft.c | 2 ++ > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > > index b65c3aabcd53..69b82c2907ff 100644 > > --- a/net/bluetooth/hci_core.c > > +++ b/net/bluetooth/hci_core.c > > @@ -1981,8 +1981,6 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, > > > > 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); > > break; I'm probably missing something obvious. But from my perspective a simpler fix would be to move the msft_remove_monitor() call to below the bt_dev_dbg() call. > > } > > > > diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c > > index bee6a4c656be..4b35f0ed1360 100644 > > --- a/net/bluetooth/msft.c > > +++ b/net/bluetooth/msft.c > > @@ -286,6 +286,8 @@ static int msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev, > > * suspend. It will be re-monitored on resume. > > */ > > if (!msft->suspending) { > > + bt_dev_dbg(hdev, "%s remove monitor %d status %d", hdev->name, > > + monitor->handle, status); > > hci_free_adv_monitor(hdev, monitor); > > > > /* Clear any monitored devices by this Adv Monitor */ > > -- > > 2.25.1 > > >
On Tue, Mar 14, 2023 at 04:06:11PM +0100, Simon Horman wrote: > On Mon, Mar 13, 2023 at 05:55:35PM +0800, Zheng Hacker wrote: > > friendly ping > > > > Zheng Wang <zyytlz.wz@163.com> 于2023年2月17日周五 18:05写道: > > > > > > 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 removing the logging into msft_le_cancel_monitor_advertisement_cb > > > before calling hci_free_adv_monitor. > > > > > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > > > --- > > > v2: > > > - move the logging inside msft_remove_monitor suggested by Luiz > > > --- > > > net/bluetooth/hci_core.c | 2 -- > > > net/bluetooth/msft.c | 2 ++ > > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > > > index b65c3aabcd53..69b82c2907ff 100644 > > > --- a/net/bluetooth/hci_core.c > > > +++ b/net/bluetooth/hci_core.c > > > @@ -1981,8 +1981,6 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, > > > > > > 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); > > > break; > > I'm probably missing something obvious. > But from my perspective a simpler fix would be to > move the msft_remove_monitor() call to below the bt_dev_dbg() call. The obvious thing I was missing is that was what was done in v1 but Luiz suggested moving the logging to msft_le_cancel_monitor_advertisement_cb(). Sorry for the noise. Link: https://lore.kernel.org/all/CABBYNZL_gZ+kr_OEqjYgMmt+=91=jC88g310F-ScMC=kLh0xdw@mail.gmail.com/ > > > > } > > > > > > diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c > > > index bee6a4c656be..4b35f0ed1360 100644 > > > --- a/net/bluetooth/msft.c > > > +++ b/net/bluetooth/msft.c > > > @@ -286,6 +286,8 @@ static int msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev, > > > * suspend. It will be re-monitored on resume. > > > */ > > > if (!msft->suspending) { > > > + bt_dev_dbg(hdev, "%s remove monitor %d status %d", hdev->name, > > > + monitor->handle, status); > > > hci_free_adv_monitor(hdev, monitor); > > > > > > /* Clear any monitored devices by this Adv Monitor */ > > > -- > > > 2.25.1 > > > > >
Simon Horman <simon.horman@corigine.com> 于2023年3月14日周二 23:22写道: > > On Tue, Mar 14, 2023 at 04:06:11PM +0100, Simon Horman wrote: > > On Mon, Mar 13, 2023 at 05:55:35PM +0800, Zheng Hacker wrote: > > > friendly ping > > > > > > Zheng Wang <zyytlz.wz@163.com> 于2023年2月17日周五 18:05写道: > > > > > > > > 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 removing the logging into msft_le_cancel_monitor_advertisement_cb > > > > before calling hci_free_adv_monitor. > > > > > > > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > > > > --- > > > > v2: > > > > - move the logging inside msft_remove_monitor suggested by Luiz > > > > --- > > > > net/bluetooth/hci_core.c | 2 -- > > > > net/bluetooth/msft.c | 2 ++ > > > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > > > > index b65c3aabcd53..69b82c2907ff 100644 > > > > --- a/net/bluetooth/hci_core.c > > > > +++ b/net/bluetooth/hci_core.c > > > > @@ -1981,8 +1981,6 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, > > > > > > > > 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); > > > > break; > > > > I'm probably missing something obvious. > > But from my perspective a simpler fix would be to > > move the msft_remove_monitor() call to below the bt_dev_dbg() call. > > The obvious thing I was missing is that was what was done in v1 > but Luiz suggested moving the logging to > msft_le_cancel_monitor_advertisement_cb(). > Sorry for the noise. Hi Simon, Thanks for your reply and detailed review :) Best regards, Zheng > > Link: https://lore.kernel.org/all/CABBYNZL_gZ+kr_OEqjYgMmt+=91=jC88g310F-ScMC=kLh0xdw@mail.gmail.com/ > > > > > > > } > > > > > > > > diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c > > > > index bee6a4c656be..4b35f0ed1360 100644 > > > > --- a/net/bluetooth/msft.c > > > > +++ b/net/bluetooth/msft.c > > > > @@ -286,6 +286,8 @@ static int msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev, > > > > * suspend. It will be re-monitored on resume. > > > > */ > > > > if (!msft->suspending) { > > > > + bt_dev_dbg(hdev, "%s remove monitor %d status %d", hdev->name, > > > > + monitor->handle, status); > > > > hci_free_adv_monitor(hdev, monitor); > > > > > > > > /* Clear any monitored devices by this Adv Monitor */ > > > > -- > > > > 2.25.1 > > > > > > >
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index b65c3aabcd53..69b82c2907ff 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1981,8 +1981,6 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, 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); break; } diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c index bee6a4c656be..4b35f0ed1360 100644 --- a/net/bluetooth/msft.c +++ b/net/bluetooth/msft.c @@ -286,6 +286,8 @@ static int msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev, * suspend. It will be re-monitored on resume. */ if (!msft->suspending) { + bt_dev_dbg(hdev, "%s remove monitor %d status %d", hdev->name, + monitor->handle, status); hci_free_adv_monitor(hdev, monitor); /* Clear any monitored devices by this Adv Monitor */