From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388538; b=gLqMA/tmZmm13IPFnveeYb0I07GJ5VekOsnCEMcf3BfDrOoID3w+DvCkGzUQy3zNXrAs zYRIKAe2Id8F86DLch/+jgJgImc5h0XbwK905zeJHAKY3DucRdB911DfquCK6f9J2yfkd /MO7rVSAmNiFzG6+xNmjnfqr0dvEt3ZxS+VaH5gJUEmkyTepZpA7UTgEQ3O1h2Owicoij t37XaGm16eXkmNKnnSZQz97ZyTumraonZJxAmZo93WWARmArlERih4rwgG63TN2Bptvh6 b7PLISV2kOUtdLUviJ6auHfhmOCCSf+R0zYTP5wywVtR8hdBtU/WTGm0I6vJjsIdPNA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388538; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=ZKI8u6yixYRsNG16/XOlb2NVv9fDIUwMXHAYzhtO+EA=; b=hb//W80YinsgQXpchr4+NzdGDSpBQs4KkagQmoEYXLBGf6b+lop6Thh1ZaOB9MJHIJ2v IRJbzM5fObCtD4TFT7y43ecP7/S3AoPs8h97Qy4SG/ZgvFNqjY9wDB+ztkzNKgl6vSROk L9bpLnJj7FO2xDe8e+m82cZQhh4akE3/+D+aL1aNcrNt8Ey8Y8/k2+M7wk6BRWoOMYaq/ VvSvTclnNMq493H2ZrzB1JVqFz0ZAzdXM8rnc6cH9BZe9WD9WhOhVnlxtoI6oNn7HIrmm sj38TImk95H+ZKZi6XmzXFrUWId6XfI0fj/X9iXDIMa3pYB7MzIuCrwy+gW/1fGg1kQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=E0m112PB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D271606A322; Fri, 4 Dec 2026 12:48:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=E0m112PB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D4B01F00897; Fri, 4 Dec 2026 12:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388537; bh=ZKI8u6yixYRsNG16/XOlb2NVv9fDIUwMXHAYzhtO+EA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=E0m112PBcBb8TPoU6KUpvhYNJshIjfEW4okslTgqCuv6qOAinrXU6suuCM+UXfVdL e5BOoC24bjlPKnIXLpd7V1K5z9qQDSuBpDoo9PwAI8bETAbb5p8y26ugUpH4YgYtDv N8vQCPZi3FAPeaOiiVpvrakS2jDsFDc82aYqFJMw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+6df45dd3d03e1a9aca96@syzkaller.appspotmail.com, Krystian Kaniewski , Luiz Augusto von Dentz , Dickson Wu , Sasha Levin Subject: [PATCH 6.1 0655/1059] Bluetooth: hci_sysfs: Fix NULL pointer dereference in device_del() Date: Fri, 4 Dec 2026 19:03:06 +0900 Message-ID: <20261204100701.020094710@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Krystian Kaniewski commit 9b851b09b392da68bd715601f10a5adb2d8d19b8 upstream. A NULL pointer dereference in klist_put() occurs when a child device (such as a BNEP network device in bnep_session) is concurrently being unregistered while hci_conn_del_sysfs() reparents child devices. This is caused by a race condition between hci_conn_del_sysfs() and concurrent child device unregistration (e.g. bnep_session calling unregister_netdev()). During device unregistration, device_del() snapshots a non-NULL parent pointer. Concurrently, hci_conn_del_sysfs() finds the child device using device_find_any_child() and calls device_move() to reparent it to NULL, which removes the node from its parent's klist and clears knode_parent. Subsequently, device_del() calls klist_del(&dev->p->knode_parent) using the stale parent snapshot, causing klist_put() to dereference knode_klist(n)->put on an already removed node, resulting in a NULL pointer dereference. This race was introduced by commit 27aabf27fd01 ("Bluetooth: fix use-after-free in device_for_each_child()"), which replaced device_find_child(..., __match_tty) with device_find_any_child() in hci_conn_del_sysfs(). That change was intended to avoid a use-after-free where conn->dev outlived its parent hdev->dev when child devices held references to conn->dev, because conn->dev only held a reference to hdev->dev while registered in sysfs. Fix the issue properly by taking an explicit reference to the parent device with get_device(&hdev->dev) in hci_conn_init_sysfs() and dropping it with put_device(parent) in bt_link_release() when the conn device is freed. This ensures that hdev->dev remains valid for the entire lifecycle of conn->dev, resolving the underlying use-after-free. With the parent reference held properly, restore the __match_tty filter in hci_conn_del_sysfs() so that device_move() is only invoked on persistent RFCOMM TTY devices as originally intended, eliminating the race condition with unregistering network devices. Fixes: 27aabf27fd01 ("Bluetooth: fix use-after-free in device_for_each_child()") Assisted-by: Gemini:gemini-3.7-flash syzbot Reported-by: syzbot+6df45dd3d03e1a9aca96@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=6df45dd3d03e1a9aca96 Link: https://syzkaller.appspot.com/ai_job?id=f1c0e740-db21-40af-a9ff-84db0fd8b8bd Signed-off-by: Krystian Kaniewski Signed-off-by: Luiz Augusto von Dentz [ adapted to 6.1.y: device_find_child() match callback takes void * ] Signed-off-by: Dickson Wu Signed-off-by: Sasha Levin --- net/bluetooth/hci_sysfs.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c index b1886e517a78b..89cd9ea1ba439 100644 --- a/net/bluetooth/hci_sysfs.c +++ b/net/bluetooth/hci_sysfs.c @@ -11,7 +11,10 @@ static struct class *bt_class; static void bt_link_release(struct device *dev) { struct hci_conn *conn = to_hci_conn(dev); + struct device *parent = dev->parent; + kfree(conn); + put_device(parent); } static const struct device_type bt_link = { @@ -19,6 +22,16 @@ static const struct device_type bt_link = { .release = bt_link_release, }; +/* + * The rfcomm tty device will possibly retain even when conn + * is down, and sysfs doesn't support move zombie device, + * so we should move the device before conn device is destroyed. + */ +static int __match_tty(struct device *dev, void *data) +{ + return !strncmp(dev_name(dev), "rfcomm", 6); +} + void hci_conn_init_sysfs(struct hci_conn *conn) { struct hci_dev *hdev = conn->hdev; @@ -27,7 +40,7 @@ void hci_conn_init_sysfs(struct hci_conn *conn) conn->dev.type = &bt_link; conn->dev.class = bt_class; - conn->dev.parent = &hdev->dev; + conn->dev.parent = get_device(&hdev->dev); device_initialize(&conn->dev); } @@ -67,7 +80,7 @@ void hci_conn_del_sysfs(struct hci_conn *conn) while (1) { struct device *dev; - dev = device_find_any_child(&conn->dev); + dev = device_find_child(&conn->dev, NULL, __match_tty); if (!dev) break; device_move(dev, NULL, DPM_ORDER_DEV_LAST); -- 2.53.0