From nobody Fri Dec 19 08:23:02 2025 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8555168BD for ; Tue, 9 Dec 2025 07:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765264651; cv=none; b=FcysZQvX6JwnHNKNe4NR/xXw7aX4KXrvj1eolWAuAq2296TEsx2DD2DSetplcy0CAmwuESYGBn3wfiRHqMGIVhPRU0He9XQbRqAXL8ciaDyrYa2gf4LGQyIVp0T3NLYBDSEBD6TA5THSCmfu6Fm6WuUhlXpysdZ+0wX+ilEwJgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765264651; c=relaxed/simple; bh=n6G313WPiJejO+ZpvTBGsvbRiJHvypVyUn0r7HF48jg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=LPm/3+IkeXeeYsibqUAuav2f60nvA80t1eiocvAOLQjdwcExw//JUvCpixx3Ugy/Yzh6qZafOw2ZtXiibP/BmOkxPsFgUnDup3KvWwKWdnSKjuphyyZ1d9jS0zotpB1tLlsxzJYVarRqdDFF5HriGdsp6Hh6S5Tq4gzJEJ6MO1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RJanU7Kw; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RJanU7Kw" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7b7828bf7bcso6082442b3a.2 for ; Mon, 08 Dec 2025 23:17:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765264649; x=1765869449; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PjJGCdCeBeoefMULktLbEhsWf3L0qKXXM/mrlsCWH18=; b=RJanU7KwATxWiKrRFRonLLbR1vtroEoY/a+6YPv+ADeH/4RAzd2VnLyCqspHhfjrGs Fs5yDK8LEgvoQig30swj2GW7/LehRab99bBnwc01FVtVE7PrU1YPQjBBKmYKQxJkxVNU 6Ch4KQW7WDE36XK0GfOeqxrl47Iq2K/x0Cpnk9lsMUvZP6fuKJp0vGdR+UViHJbuomP+ G1d3XczpGuZji93vhjWxohT65koUtgmOvbbE2oYwRXuwOv6+n6Icw+VfQlleQ9OAc/zw qsgcTo9mQRH2GtcusNcBqUhVZ9tNmSgISnwmh0hLOa7ggoPrvC8kfuPlpFeJT+PQLyvu YFgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765264649; x=1765869449; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PjJGCdCeBeoefMULktLbEhsWf3L0qKXXM/mrlsCWH18=; b=BVKs0bUJipgw8vM+8wwa8C1BqJNRYfsDE18fkMn10esj+yZac0BEKhiL5ecuDU6l7r OXRhsHan7wQ2CdDY2DGc4vokCrjyDvbk9KiUdVZzXQnhljCYKU811754pJGugbmNNmTU F+sxPbygypXgDSC3HiMJiVkjhdzt5tco8TE3B7Vkw2kxTYP7uvEDjyU46p0EJPCxMhFy kB5W20ZbOnmfP5K1S8aTMcP1lKJ9cSiwJBL26YYA/Hj101LrIIWl8SccLSNBauWkWt3l YFBBYd0Zq92cFavYi/8VvpmH+r3gIT2YfSpBvaf0u9ZfXZ5AD+ed/I6TNLid2Ix3iSOX VqsQ== X-Gm-Message-State: AOJu0YxJ0LNiEtXR8B8x7xIFRN4aSExxgZ0n1Kmt01UIXya6eD5scPF0 34ODkzRMSmzPLmHTzKTXdVacp8AXmRa67WgNa1ivWRUoN6/15o0n6z1y X-Gm-Gg: ASbGncukvjL/18psAOXBHuPF1qS++vCRM/1W6NKwkPcGnnWcu6CqywNKaaALjKMrA2G JB8ains0O11/i3CWCPbIJHw1Cy26AgfG91SRpKQVpF61PI6/cJc5z3kPISAfT021sYnkUp0sS5B vYTUKXUbedT6i5OAX7gp+Bp1FChPqXu203DR/1gwfnxrHsn2btTaxP3tu41uRQ34cUlN2LjEV/M nK5gXCYSeksTSgpMs5Itm2sMQw+7GaubW8w+Ck1dfJyaKhd2mFe4jpYbGT7VlL/k4a9QM3wnH14 p1F9zJ/HWsqpbdlAlViQQjtqfJqxqRrHxLSDDuRdjS9JGdfgJbHagl4rm8HZMiC4NbqXXfY5uws 1yTTHAaC9FT9fQsGYIzUtlXLboIu+Rxg5JcwEJdXAAeT52mBT3+iOmZzUFPuGuQVpUBygTDYVbQ xF7OJhhm/lPQt/YJl7YJpzfg/UgJE= X-Google-Smtp-Source: AGHT+IHhpnodgm0X3Kb5hZSr10+4m7fcJqMPZJ3NYoPgYBczSRs6Bbm0JQF7xsfK35+Ujwut0MgMdA== X-Received: by 2002:a05:6a20:1611:b0:34f:c83b:b3ea with SMTP id adf61e73a8af0-36617e6c5f7mr10014926637.18.1765264648685; Mon, 08 Dec 2025 23:17:28 -0800 (PST) Received: from lavm-prs74opxn5.. ([111.228.63.84]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34a4a1fab4bsm766871a91.1.2025.12.08.23.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Dec 2025 23:17:28 -0800 (PST) From: Cen Zhang To: luiz.dentz@gmail.com, marcel@holtmann.org Cc: linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, pav@iki.fi, baijiaju1990@gmail.com, r33s3n6@gmail.com, gality369@gmail.com, zhenghaoran154@gmail.com, Cen Zhang Subject: [PATCH] Bluetooth: btintel: serialize hw error recovery with req_lock Date: Tue, 9 Dec 2025 15:12:48 +0800 Message-Id: <20251209071248.3575845-1-zzzccc427@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable btintel_hw_error() issues two __hci_cmd_sync() calls to reset the controller and fetch the Intel exception report. Unlike the shutdown path, this helper ran without hci_req_sync_lock(), so it could race against hci_dev_do_close() and both sides would manipulate hdev->req_status/req_rsp concurrently.When the close path freed the shared response buffer first, the still running hw_error path hit a slab-use-after-free inside kfree_skb() (skb_unref =E2=86=92 atomic_read) and KASAN reported the crash in the trace. Acquire hci_req_sync_lock() around the hw_error recovery sequence and make sure all error/cleanup paths release it. This serializes the Intel handler with every other synchronous command issuer and prevents the req_* bookkeeping from being double-touched. Below is the data race report and the kasan report: BUG: data-race in __hci_cmd_sync_sk / btintel_shutdown_combined read of hdev->req_rsp at net/bluetooth/hci_sync.c:199 by task kworker/u17:1= /83 write/free of same SKB at drivers/bluetooth/btintel.c:3660 by task ioctl/22= 580 Call Trace (reader): __hci_cmd_sync_sk+0x12f2/0x1c30 net/bluetooth/hci_sync.c:200 __hci_cmd_sync+0x55/0x80 net/bluetooth/hci_sync.c:223 btintel_hw_error+0x114/0x670 drivers/bluetooth/btintel.c:254 hci_error_reset+0x348/0xa30 net/bluetooth/hci_core.c:1030 ... Call Trace (writer): btintel_shutdown_combined+0xd0/0x360 drivers/bluetooth/btintel.c:3648 hci_dev_close_sync+0x9ae/0x2c10 net/bluetooth/hci_sync.c:5246 hci_dev_do_close+0x232/0x460 net/bluetooth/hci_core.c:526 ... BUG: KASAN: slab-use-after-free in sk_skb_reason_drop+0x43/0x380 net/core/s= kbuff.c:1202 Read of size 4 at addr ffff888144a738dc by task kworker/u17:1/83 Call Trace: __hci_cmd_sync_sk+0x12f2/0x1c30 net/bluetooth/hci_sync.c:200 __hci_cmd_sync+0x55/0x80 net/bluetooth/hci_sync.c:223 btintel_hw_error+0x186/0x670 drivers/bluetooth/btintel.c:260 ... Allocated by task 84: skb_clone+0x212/0x3a0 net/core/skbuff.c:2049 hci_event_packet+0x66c/0x2da0 net/bluetooth/hci_event.c:7614 ... Freed by task 22580: btintel_shutdown_combined+0xd0/0x360 drivers/bluetooth/btintel.c:3648 hci_dev_close_sync+0x9ae/0x2c10 net/bluetooth/hci_sync.c:5246 hci_dev_do_close+0x232/0x460 net/bluetooth/hci_core.c:526 ... Signed-off-by: Cen Zhang --- drivers/bluetooth/btintel.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 9d29ab811..baa3ee510 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -251,10 +251,12 @@ void btintel_hw_error(struct hci_dev *hdev, u8 code) =20 bt_dev_err(hdev, "Hardware error 0x%2.2x", code); =20 + hci_req_sync_lock(hdev); skb =3D __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); if (IS_ERR(skb)) { bt_dev_err(hdev, "Reset after hardware error failed (%ld)", PTR_ERR(skb)); + hci_req_sync_unlock(hdev); return; } kfree_skb(skb); @@ -263,18 +265,22 @@ void btintel_hw_error(struct hci_dev *hdev, u8 code) if (IS_ERR(skb)) { bt_dev_err(hdev, "Retrieving Intel exception info failed (%ld)", PTR_ERR(skb)); + hci_req_sync_unlock(hdev); return; } =20 if (skb->len !=3D 13) { bt_dev_err(hdev, "Exception info size mismatch"); kfree_skb(skb); + hci_req_sync_unlock(hdev); return; } =20 bt_dev_err(hdev, "Exception info %s", (char *)(skb->data + 1)); =20 kfree_skb(skb); + + hci_req_sync_unlock(hdev); } EXPORT_SYMBOL_GPL(btintel_hw_error); =20 --=20 2.34.1