From nobody Mon Jun 8 06:36:21 2026 Received: from mail-dl1-f68.google.com (mail-dl1-f68.google.com [74.125.82.68]) (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 3789D1D5AD4 for ; Wed, 3 Jun 2026 04:40:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780461636; cv=none; b=rOUqYnHupVL72xUDBM8asLd1xzF/l2BptcPIh/HaRMqBdRAJAzmYJ3YJjCb/98MOyPZdsALNQOoqjSGGueb6DGmoaqIeijZTJS5hFA32pfxS1nIZRnIzvza4mnGti21u7uejlC5l475VmEijneKBollsabiBHaWZ1qZXDcX6oyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780461636; c=relaxed/simple; bh=jbJB+R4ozivXYHQOOPDuj5qPhGaHKfeIF476MxWyL5Q=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=cmDuMKvmm51Mp0w1hSMDyBogvIoeiNsgK74N6r1cayeKOuxVsorRaYV4cQ/lA9izhbWEx7jxDwozAQIsGANGuuOJmKAl1nW3V8UxgDQyLMPrJVZ3Xfnmkf0oqC8Bit8FVv9Cxg7hVtUh0MfcFaZilQtziVrtplXtSIA0OUjXeHQ= 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=L0WC0o9b; arc=none smtp.client-ip=74.125.82.68 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="L0WC0o9b" Received: by mail-dl1-f68.google.com with SMTP id a92af1059eb24-1363fe80fe8so14972754c88.0 for ; Tue, 02 Jun 2026 21:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780461634; x=1781066434; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=YP63hiu04Z6Bd+ZfkWnYMNBnsF0xwtb8q+rYnz3wXwE=; b=L0WC0o9bVV1BxvKZeWtb9E7UklVK5+rXBhNz8Ze1P3Do2tJeX2IL2lNUBKF90zQyFU E9zWaBiX2M9NBM9aFHNblpdrKJdfyC28OLFI0vhj2NdyNyAHEkx+opSRJp1z3VkKQ1EO oQ304ODZPDOmtd6teV0xpYKIhktNOQrE+H55jrMR5RTQyRAHvuo4pOmAtLDG2o6Dx95R rZws0p7xtY2/cHIb0HWL/1gPdgptS/pGMBfk7O4hyYwmfsO7UUc21AJlIXcG0kceKVaA Rm7Bdjm+rpweRQtb5U0bJZXh5Ej9ZIGkntWK9p1ylJaS0gQIW40mslSjQILdWCSoTxE+ sGOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780461634; x=1781066434; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YP63hiu04Z6Bd+ZfkWnYMNBnsF0xwtb8q+rYnz3wXwE=; b=HnqxkyqwKxPaa4ECpHDMNKCCo6ZWxkzCSmNHXNEeyiR7snSSPIuVOR8FYpEBH6b5DJ o1z2EczEK5Zsvka/FRGeC+YZ/C+DMac5tyEwAcslccB0C/HrKB/wRyVHbnAuqhorxLj0 xTwr6fhdIUUKsx/c9wrIyhdcQQ9Mi86sbYskLP4BPoLZNoWHb5EBNq1VhXBkGP2nwwNK 9j7nEG/v6SqvT+JoAEOwfLjnoySpY4LUVsyUAKUl0GUtozgmJxDFxjC1vKjerKkMW2ws 0A4aCyqMJtKHgSel0ZGsDetLUibe9vdXjK2EOtBYx4gUZjVsTE817YqYdAPF4fyoNeML //gw== X-Forwarded-Encrypted: i=1; AFNElJ+ONDXLdSDMTCUdPPFq+fWoi+rh8lq70QYmBjkcrZKmYFuBTPaslNQ3NqCCMpBxj5bc09c4DCQycuvAu14=@vger.kernel.org X-Gm-Message-State: AOJu0YzG4G+xaZ9l6k/XyXUm3xF8OpDMqe1CSnBWSYaYbI9cC270TFj2 ZIwCPKHskKpwOJrpJZ5d9cuxFyJ/4WFf/9pggKKI6ttyD7nSCbjQ7eDlA7gvPdGrS7cF X-Gm-Gg: Acq92OGHwK6j8ELduUsX5VYv4JST1tQqjQWgPz13ir8cNDpxKxABHirnziKcXzkmLvM ph3kKHddKS1kVBxyJn0lq0e1/zqhlxNwQz/8g+wAJTtmaKb2WuBqRVYBJIQGRgP9zt8ZFwzt+hp BsJHtyYvCH3NaHUjgBiblZQu7vi7BayaXEHAOZzoepDp62zWmCx7bc+8l3IZFIME5iUk+4iMhMv gvEr1fqw2I+4aXDTBVQdsqVHnIJYcMgjGbJNqYAUU80+8xWEW2oWaBFEP6h/NF+FQKWUPU7MKNs DcX+aCA1qIvfe71MR0BotbswiN3fuLwJrLAiPrV5qRadbLISjEvke4i/XSAfFNoEzJ87vJn7J5c raRuJAQ1ZxhTxPmY3CrOlEmq5QBMlPTNWGmlJZZQzhEnnCZ/I7FtTWZbouGYX9giSbehQhcMLoD FrGQ2RYfyM8C1CIZjCc1zaCkArEtWFH3axBipB X-Received: by 2002:a05:701b:2918:b0:133:1d3d:f93e with SMTP id a92af1059eb24-137f6bff151mr240434c88.42.1780461634153; Tue, 02 Jun 2026 21:40:34 -0700 (PDT) Received: from rainbow ([142.147.89.221]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-137f549fa04sm1180687c88.5.2026.06.02.21.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 21:40:33 -0700 (PDT) From: Jordan Walters To: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] Bluetooth: Fix Use-After-Free in hci_unregister_dev Date: Wed, 3 Jun 2026 00:39:25 -0400 Message-ID: <20260603043925.228091-1-jaggyaur@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The hci_unregister_dev() function fails to safely cancel the cmd_timer and ncmd_timer before freeing the hci_dev structure. If an asynchronous event or timeout occurs during device teardown, the timer callbacks may execute after the device has been freed, leading to a KASAN slab-use-after-free panic. In v1, the timers were disabled too early in the teardown sequence, which caused deadlocks in CI testing (mgmt-tester and mesh-tester) because the HCI teardown process relies on these timers to safely time out the HCI_OP_RESET command. This patch adds cancel_delayed_work_sync() calls at the very end of hci_unregister_dev() after all teardown procedures have completed, guaranteeing the timers are fully flushed before the struct is freed. Signed-off-by: Jordan Walters --- net/bluetooth/hci_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 28d7929dc59..3db1b3738b5 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2698,6 +2698,9 @@ void hci_unregister_dev(struct hci_dev *hdev) rfkill_unregister(hdev->rfkill); rfkill_destroy(hdev->rfkill); } =20 + cancel_delayed_work_sync(&hdev->cmd_timer); + cancel_delayed_work_sync(&hdev->ncmd_timer); + hci_dev_put(hdev); }