All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Mazin Alhaddad" <mazin@getstate.dev>
To: "syzbot" <syzbot+479aff51bb361ef5aa18@syzkaller.appspotmail.com>,
	<linux-kernel@vger.kernel.org>, <syzkaller-bugs@googlegroups.com>
Subject: Re: [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in mgmt_remove_adv_monitor_sync
Date: Sun, 08 Dec 2024 21:24:44 +0300	[thread overview]
Message-ID: <D66J2UCA2K95.14GOLVW7ECBK2@getstate.dev> (raw)
In-Reply-To: <6755cc1f.050a0220.2477f.002b.GAE@google.com>


[-- Attachment #1.1: Type: text/plain, Size: 84 bytes --]

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

[-- Attachment #2: 0001-TEST.patch --]
[-- Type: text/plain, Size: 2055 bytes --]

From f3a0a68f150f2aa333b1822f0b0fcf103fb5209c Mon Sep 17 00:00:00 2001
From: Mazin AlHaddad <mazin@getstate.dev>
Date: Sun, 8 Dec 2024 18:52:54 +0300
Subject: [PATCH] TEST

---
 net/bluetooth/hci_sync.c |  5 +++--
 net/bluetooth/mgmt.c     | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index c86f4e42e..aa5aa3fed 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -5197,6 +5197,9 @@ int hci_dev_close_sync(struct hci_dev *hdev)
 	 */
 	drain_workqueue(hdev->workqueue);
 
+	/* flush cmd  work */
+	flush_work(&hdev->cmd_work);
+
 	hci_dev_lock(hdev);
 
 	hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
@@ -5234,8 +5237,6 @@ int hci_dev_close_sync(struct hci_dev *hdev)
 		clear_bit(HCI_INIT, &hdev->flags);
 	}
 
-	/* flush cmd  work */
-	flush_work(&hdev->cmd_work);
 
 	/* Drop queues */
 	skb_queue_purge(&hdev->rx_q);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index b31192d47..661bbe7e0 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5519,9 +5519,18 @@ static void mgmt_remove_adv_monitor_complete(struct hci_dev *hdev,
 {
 	struct mgmt_rp_remove_adv_monitor rp;
 	struct mgmt_pending_cmd *cmd = data;
-	struct mgmt_cp_remove_adv_monitor *cp = cmd->param;
+	struct mgmt_cp_remove_adv_monitor *cp;
+	
+	if (status == -EINVAL || cmd != pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev)){
+		return;
+	}
 
 	hci_dev_lock(hdev);
+	// if called while device is closing, status will be invalid.
+	// and cmd is cleared by __mgmt_power_off
+	
+
+	cp = cmd->param;
 
 	rp.monitor_handle = cp->monitor_handle;
 
@@ -5540,6 +5549,8 @@ static void mgmt_remove_adv_monitor_complete(struct hci_dev *hdev,
 static int mgmt_remove_adv_monitor_sync(struct hci_dev *hdev, void *data)
 {
 	struct mgmt_pending_cmd *cmd = data;
+	if (cmd != pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev))
+		return -EINVAL;
 	struct mgmt_cp_remove_adv_monitor *cp = cmd->param;
 	u16 handle = __le16_to_cpu(cp->monitor_handle);
 
-- 
2.46.0


  reply	other threads:[~2024-12-08 18:24 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <D63E89JWB8QV.38E70BVWNMMVL@getstate.dev>
2024-12-05  2:24 ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in mgmt_remove_adv_monitor_sync syzbot
2024-12-05  2:43   ` Mazin Alhaddad
2024-12-05  3:06     ` syzbot
2024-12-05  8:36       ` [PATCH] [PATCH] TEST Pei Xiao
2024-12-05  8:50         ` Aleksandr Nogikh
2024-12-05  9:47           ` Pei Xiao
2024-12-05 11:38       ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in mgmt_remove_adv_monitor_sync Mazin Alhaddad
2024-12-05 12:04         ` syzbot
2024-12-05 12:18           ` Mazin Alhaddad
2024-12-05 12:39             ` syzbot
2024-12-05 12:20           ` Mazin Alhaddad
2024-12-05 12:48             ` syzbot
2024-12-05 13:01               ` Mazin Alhaddad
2024-12-05 13:44                 ` syzbot
2024-12-05 13:51                   ` Mazin Alhaddad
2024-12-05 14:10                     ` syzbot
2024-12-05 14:26                       ` Mazin Alhaddad
2024-12-05 15:06                         ` syzbot
2024-12-05 15:51                           ` Mazin Alhaddad
2024-12-05 16:42                             ` syzbot
2024-12-08 15:56                               ` Mazin Alhaddad
2024-12-08 16:41                                 ` syzbot
2024-12-08 18:24                                   ` Mazin Alhaddad [this message]
2024-12-08 18:47                                     ` syzbot
2024-12-08 19:12                                     ` Mazin Alhaddad
2024-12-08 21:42                                       ` syzbot
2024-12-08 21:44                                         ` Mazin Alhaddad
2024-12-08 22:06                                           ` syzbot
     [not found] <D6JFGS83KL11.2PX1Q2EA60PMZ@getstate.dev>
2024-12-23 22:43 ` syzbot
2024-12-05  9:45 [patch] test Pei Xiao
2024-12-05  9:55 ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in mgmt_remove_adv_monitor_sync syzbot
  -- strict thread matches above, loose matches on Subject: below --
2024-12-05  9:30 [PATCH] test Pei Xiao
2024-12-05  9:38 ` [syzbot] [bluetooth?] KASAN: slab-use-after-free Read in mgmt_remove_adv_monitor_sync syzbot
     [not found] <de7743c9-1fd1-4dc3-9ed4-31c32a9118eb@kylinos.cn>
2024-12-05  9:13 ` syzbot
2024-07-24  8:59 syzbot
2024-11-28  6:53 ` syzbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D66J2UCA2K95.14GOLVW7ECBK2@getstate.dev \
    --to=mazin@getstate.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+479aff51bb361ef5aa18@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.