From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 3F107469828 for ; Fri, 7 Aug 2026 10:15:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786097738; cv=none; b=qMBWmZ+GiVSvRi44q5wXAOA1xZzAdB3tKmmLo7qSmUIpz0S0JSjart+EO25SyI2UtqWJjQoR4Pf2zG3AFPhys2QFORiyZoSP5azH1GoPgFOn33UcrJjkHIgWbxpv5euhafRV9BW4CFpdEuLkFrnbXaLmzYwIJY+DpWok5E7MuVo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786097738; c=relaxed/simple; bh=XU7SBVwoZ2gmzDIRGG1/wevQLi+4spBoLxZ+LV157CY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JrthDomCY/aYCt5eSBGnBV2ccnoDfg8RE9gahGZ3znbkklF+ETORjb5dCAifLOcnlmeqCn/TgfvbVR5AA5kZSszz2iTGlvTx+eMcW+A6xWpuT/R5zzMwjv1MnGtKmmbwXCiFaE4XWxKTJUAi8QtlOCS5ReQn9xXFD1Q4MnkwDB4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xbow.com; spf=pass smtp.mailfrom=xbow.com; dkim=pass (2048-bit key) header.d=xbow.com header.i=@xbow.com header.b=AKLIrrns; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xbow.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xbow.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=xbow.com header.i=@xbow.com header.b="AKLIrrns" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-3810c5d691bso2939707a91.1 for ; Fri, 07 Aug 2026 03:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xbow.com; s=google; t=1786097736; x=1786702536; 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:content-type; bh=dU0nW0nnnYVIBF5ljLRaJDGaH50na6JSFZ8vlLoM0Gw=; b=AKLIrrnsgqvF8+GR/aupTJptHWVR81SJpeyoMs+2CPYyqi5WcdI7sOjJsUC/kV39A5 RL6oUISVXqfxsErlwfE+EQdAhgFAPq9YhhI7n0SIJitKgnffrMZ3/Jj4l2i6RmJqFqSU jgV0dhKNcpe0ZHkAVrAWantrKDhW2p32KRKs4UwXIh0Jc+JaJBBE/bSTRKPqQGS8+2q7 azGkkCz9LPUDfvNSzdocUh4sS/wunQEMvYxJja+/BO4nSKS1aWC0RGYrTSt5wsasV9bc 2YKpBzANESy2nuPYcizY6uWGUg8QSm60jBoqQFVgqn040/2+W5KAdEvTpAZQq/Xw5Uf1 yRAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786097736; x=1786702536; 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:content-type; bh=dU0nW0nnnYVIBF5ljLRaJDGaH50na6JSFZ8vlLoM0Gw=; b=VjWpgzpq6kTFBL1NmTZS5KPZu5sdrvw0UK7Y/AkfpG4+7okF/L+9G4w/XBEmzky/Ju qzN9v1AHoHulBjO2eCJnTx+GgtND50StQs41ntPyqpii8/EHtLcHuBzNAwFSACfet/A1 AXJhCURt4yVUKV++3ZYbkXxemPW/OiyyWJEmffwB4xgHL/ac/v0r7yFhLmJ/9UTjrN2C w8/4o9rSM8PFKqkdy7O1sNNDc1exlz1hkOoY59BEH0TR40lN188hndnhPagidViow5+z /E5oyG/eelHrwDjJ+LFU8sQRy+ecLCb/sBMGFghNVvEkZzJKH3A/7QFqfzXitcS7a9wc nA7Q== X-Forwarded-Encrypted: i=1; AHgh+RrT4eU64emq1yuIxrMX3YC8K1mqUI02VaPMr05zHrcqNUxaVpJoCdZady11iA0vheZxg4OEcIwmdCbNt+0=@vger.kernel.org X-Gm-Message-State: AOJu0YyeNPAHYcbWm1R6j3P0BEWFREPZNWnTWZf+aODWCkOvxpIdR5BH sexCaNh/j56VaAXrCwKMVJ0vwYlefulDjb7S8lh5e3rFRwXWeeabUZdPfj6SEITVFTI= X-Gm-Gg: AR+sD102IdFR2oS4Ii6HDh2npF/9DUtJNRliKzV5yYZkHjz9W3Smjidy+1GkIy8jok0 a0TNl5t35UZD0S+PMQP2ROcUvPLWd9lXMriPV58E5DV1ThmKnhYs3JDvk+rbOdQDa56Y7Rb6dEs WiWUAryk35u+hUux0ryPuiVP2NddLj7TGoFxAAwT5pSWkWAFm/iPYeSMkLKqYDcvjphyB40CAm/ Hx4Yfqf5lmZ18JZ+o7WIVLr6BZwMXH/sE9ypyGP3XuYS+5+5zfyt3FhkdFYKJ9X7xsuExEHR2E8 Moty06MikqqDh3gU+1q/HOZp6ObxwOaAoKmkfJhqIY9AY2/jLeZn0TDUO3raljtoy7a1TgVmeAK IyqFjHU/BD0m1TyKnmj11CZsBW+xsrfvw8iZkUedddh50ZxILIWEFvY3Aw8Xb3wUkK2kV+NMVY9 hDViLnIsbDobC7/+iq1fbXUroGLv5i//vZBM1LjjerCPMoX1RlR17n64pl/wiqQG2zhz7ocC6+e +sbPxwu8vjcYonZWklJRhaMHCTLwnSdhdWQiNxcntIGHRw92L7TZDs= X-Received: by 2002:a17:90b:264c:b0:36d:9e0b:3801 with SMTP id 98e67ed59e1d1-3903c59936cmr23131603a91.8.1786097736542; Fri, 07 Aug 2026 03:15:36 -0700 (PDT) Received: from localhost.localdomain ([1.220.41.130]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39085dea04bsm4399162a91.8.2026.08.07.03.15.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 07 Aug 2026 03:15:36 -0700 (PDT) From: Baul Lee To: Luiz Augusto von Dentz , Marcel Holtmann , Brian Gix Cc: Baul Lee , Luiz Augusto von Dentz , Dmitry Antipov , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, federico.kirschbaum@xbow.com Subject: [PATCH v2 0/3] Bluetooth: MGMT: fix use-after-free of struct mgmt_mesh_tx Date: Fri, 7 Aug 2026 19:15:26 +0900 Message-ID: <20260807101529.17348-1-baul.lee@xbow.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit hdev->mesh_pending is extended and walked from syscall context under hdev->lock, and unlinked and freed from the hci_cmd_sync worker under hci_req_sync_lock, so the list has no protection; the objects on it are also handed to hci_cmd_sync_queue() as raw pointers, and those work entries outlive the list. Three use-after-frees follow, all reproduced under KASAN. Patch 1 removes mgmt_cleanup(), the one walker of the list that cannot take hdev->lock. Patch 2 puts the list under hdev->lock on the worker side and asserts it in the helpers. Patch 3 gives the object a reference count for the work entry. The order matters: the assertions in patch 2 have no violating caller left once patch 1 is in, and the reference in patch 3 is only well defined once every unlink happens under one lock. Reaching any of this needs CAP_NET_ADMIN in the init user namespace. hci_sock.c sets HCI_SOCK_TRUSTED at bind under capable() rather than ns_capable() and gates every later mgmt command on it, and the mesh commands additionally need HCI_MESH_EXPERIMENTAL. Nothing in hci_event.c touches hdev->mesh_pending. Each reproducer was run at identical parameters on the unpatched and the patched kernel, built with KASAN, PROVE_LOCKING, DEBUG_LIST and DEBUG_ATOMIC_SLEEP: every splat the unpatched kernel produces is gone. v2: rebased onto bluetooth-next, where send_cancel() no longer ends in mgmt_pending_free(), so v1 did not apply for the CI. Context only, no other change; v1 applies as posted to the bluetooth tree, which still has that line. Baul Lee (3): Bluetooth: MGMT: remove the mesh walk from the socket destructor Bluetooth: MGMT: protect hdev->mesh_pending with hdev->lock Bluetooth: MGMT: reference-count struct mgmt_mesh_tx include/net/bluetooth/bluetooth.h | 1 - net/bluetooth/hci_sock.c | 1 - net/bluetooth/mgmt.c | 72 ++++++++++++++++++++++++--------------- net/bluetooth/mgmt_util.c | 31 +++++++++++++++-- net/bluetooth/mgmt_util.h | 3 ++ 5 files changed, 76 insertions(+), 32 deletions(-) -- 2.50.1 (Apple Git-155)