]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Bluetooth: MGMT: Fix dangling pointer on mgmt_add_adv_patterns_monitor_complete
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 16 Mar 2026 19:03:27 +0000 (15:03 -0400)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 19 Mar 2026 18:42:57 +0000 (14:42 -0400)
This fixes the condition checking so mgmt_pending_valid is executed
whenever status != -ECANCELED otherwise calling mgmt_pending_free(cmd)
would kfree(cmd) without unlinking it from the list first, leaving a
dangling pointer. Any subsequent list traversal (e.g.,
mgmt_pending_foreach during __mgmt_power_off, or another
mgmt_pending_valid call) would dereference freed memory.

Link: https://lore.kernel.org/linux-bluetooth/20260315132013.75ab40c5@kernel.org/T/#m1418f9c82eeff8510c1beaa21cf53af20db96c06
Fixes: 302a1f674c00 ("Bluetooth: MGMT: Fix possible UAFs")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
net/bluetooth/mgmt.c

index d52238ce6a9a69221263b6b6e5bb7332a6db0075..e5f9287fb826acc55f9b25a6c01e503981f0999d 100644 (file)
@@ -5355,7 +5355,7 @@ static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev,
         * hci_adv_monitors_clear is about to be called which will take care of
         * freeing the adv_monitor instances.
         */
-       if (status == -ECANCELED && !mgmt_pending_valid(hdev, cmd))
+       if (status == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
                return;
 
        monitor = cmd->user_data;