<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/net/bluetooth/hci_core.c, branch v6.6</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.6</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.6'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2023-09-20T18:03:11+00:00</updated>
<entry>
<title>Bluetooth: hci_codec: Fix leaking content of local_codecs</title>
<updated>2023-09-20T18:03:11+00:00</updated>
<author>
<name>Luiz Augusto von Dentz</name>
<email>luiz.von.dentz@intel.com</email>
</author>
<published>2023-09-15T20:24:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b938790e70540bf4f2e653dcd74b232494d06c8f'/>
<id>urn:sha1:b938790e70540bf4f2e653dcd74b232494d06c8f</id>
<content type='text'>
The following memory leak can be observed when the controller supports
codecs which are stored in local_codecs list but the elements are never
freed:

unreferenced object 0xffff88800221d840 (size 32):
  comm "kworker/u3:0", pid 36, jiffies 4294898739 (age 127.060s)
  hex dump (first 32 bytes):
    f8 d3 02 03 80 88 ff ff 80 d8 21 02 80 88 ff ff  ..........!.....
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace:
    [&lt;ffffffffb324f557&gt;] __kmalloc+0x47/0x120
    [&lt;ffffffffb39ef37d&gt;] hci_codec_list_add.isra.0+0x2d/0x160
    [&lt;ffffffffb39ef643&gt;] hci_read_codec_capabilities+0x183/0x270
    [&lt;ffffffffb39ef9ab&gt;] hci_read_supported_codecs+0x1bb/0x2d0
    [&lt;ffffffffb39f162e&gt;] hci_read_local_codecs_sync+0x3e/0x60
    [&lt;ffffffffb39ff1b3&gt;] hci_dev_open_sync+0x943/0x11e0
    [&lt;ffffffffb396d55d&gt;] hci_power_on+0x10d/0x3f0
    [&lt;ffffffffb30c99b4&gt;] process_one_work+0x404/0x800
    [&lt;ffffffffb30ca134&gt;] worker_thread+0x374/0x670
    [&lt;ffffffffb30d9108&gt;] kthread+0x188/0x1c0
    [&lt;ffffffffb304db6b&gt;] ret_from_fork+0x2b/0x50
    [&lt;ffffffffb300206a&gt;] ret_from_fork_asm+0x1a/0x30

Cc: stable@vger.kernel.org
Fixes: 8961987f3f5f ("Bluetooth: Enumerate local supported codec and cache details")
Signed-off-by: Luiz Augusto von Dentz &lt;luiz.von.dentz@intel.com&gt;
</content>
</entry>
<entry>
<title>Bluetooth: hci_core: Fix build warnings</title>
<updated>2023-09-20T18:02:41+00:00</updated>
<author>
<name>Luiz Augusto von Dentz</name>
<email>luiz.von.dentz@intel.com</email>
</author>
<published>2023-09-15T21:42:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=dcda165706b9fbfd685898d46a6749d7d397e0c0'/>
<id>urn:sha1:dcda165706b9fbfd685898d46a6749d7d397e0c0</id>
<content type='text'>
This fixes the following warnings:

net/bluetooth/hci_core.c: In function ‘hci_register_dev’:
net/bluetooth/hci_core.c:2620:54: warning: ‘%d’ directive output may
be truncated writing between 1 and 10 bytes into a region of size 5
[-Wformat-truncation=]
 2620 |         snprintf(hdev-&gt;name, sizeof(hdev-&gt;name), "hci%d", id);
      |                                                      ^~
net/bluetooth/hci_core.c:2620:50: note: directive argument in the range
[0, 2147483647]
 2620 |         snprintf(hdev-&gt;name, sizeof(hdev-&gt;name), "hci%d", id);
      |                                                  ^~~~~~~
net/bluetooth/hci_core.c:2620:9: note: ‘snprintf’ output between 5 and
14 bytes into a destination of size 8
 2620 |         snprintf(hdev-&gt;name, sizeof(hdev-&gt;name), "hci%d", id);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Luiz Augusto von Dentz &lt;luiz.von.dentz@intel.com&gt;
</content>
</entry>
<entry>
<title>Bluetooth: Fix hci_link_tx_to RCU lock usage</title>
<updated>2023-09-20T18:01:42+00:00</updated>
<author>
<name>Ying Hsu</name>
<email>yinghsu@chromium.org</email>
</author>
<published>2023-09-04T14:11:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=c7eaf80bfb0c8cef852cce9501b95dd5a6bddcb9'/>
<id>urn:sha1:c7eaf80bfb0c8cef852cce9501b95dd5a6bddcb9</id>
<content type='text'>
Syzbot found a bug "BUG: sleeping function called from invalid context
at kernel/locking/mutex.c:580". It is because hci_link_tx_to holds an
RCU read lock and calls hci_disconnect which would hold a mutex lock
since the commit a13f316e90fd ("Bluetooth: hci_conn: Consolidate code
for aborting connections"). Here's an example call trace:

   __dump_stack lib/dump_stack.c:88 [inline]
   dump_stack_lvl+0xfc/0x174 lib/dump_stack.c:106
   ___might_sleep+0x4a9/0x4d3 kernel/sched/core.c:9663
   __mutex_lock_common kernel/locking/mutex.c:576 [inline]
   __mutex_lock+0xc7/0x6e7 kernel/locking/mutex.c:732
   hci_cmd_sync_queue+0x3a/0x287 net/bluetooth/hci_sync.c:388
   hci_abort_conn+0x2cd/0x2e4 net/bluetooth/hci_conn.c:1812
   hci_disconnect+0x207/0x237 net/bluetooth/hci_conn.c:244
   hci_link_tx_to net/bluetooth/hci_core.c:3254 [inline]
   __check_timeout net/bluetooth/hci_core.c:3419 [inline]
   __check_timeout+0x310/0x361 net/bluetooth/hci_core.c:3399
   hci_sched_le net/bluetooth/hci_core.c:3602 [inline]
   hci_tx_work+0xe8f/0x12d0 net/bluetooth/hci_core.c:3652
   process_one_work+0x75c/0xba1 kernel/workqueue.c:2310
   worker_thread+0x5b2/0x73a kernel/workqueue.c:2457
   kthread+0x2f7/0x30b kernel/kthread.c:319
   ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298

This patch releases RCU read lock before calling hci_disconnect and
reacquires it afterward to fix the bug.

Fixes: a13f316e90fd ("Bluetooth: hci_conn: Consolidate code for aborting connections")
Signed-off-by: Ying Hsu &lt;yinghsu@chromium.org&gt;
Signed-off-by: Luiz Augusto von Dentz &lt;luiz.von.dentz@intel.com&gt;
</content>
</entry>
<entry>
<title>Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_add_adv_monitor()</title>
<updated>2023-08-11T18:56:35+00:00</updated>
<author>
<name>Manish Mandlik</name>
<email>mmandlik@google.com</email>
</author>
<published>2023-08-04T18:14:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a2bcd2b63271a93a695fabbfbf459c603d956d48'/>
<id>urn:sha1:a2bcd2b63271a93a695fabbfbf459c603d956d48</id>
<content type='text'>
KSAN reports use-after-free in hci_add_adv_monitor().

While adding an adv monitor,
    hci_add_adv_monitor() calls -&gt;
    msft_add_monitor_pattern() calls -&gt;
    msft_add_monitor_sync() calls -&gt;
    msft_le_monitor_advertisement_cb() calls in an error case -&gt;
    hci_free_adv_monitor() which frees the *moniter.

This is referenced by bt_dev_dbg() in hci_add_adv_monitor().

Fix the bt_dev_dbg() by using handle instead of monitor-&gt;handle.

Fixes: b747a83690c8 ("Bluetooth: hci_sync: Refactor add Adv Monitor")
Signed-off-by: Manish Mandlik &lt;mmandlik@google.com&gt;
Signed-off-by: Luiz Augusto von Dentz &lt;luiz.von.dentz@intel.com&gt;
</content>
</entry>
<entry>
<title>Bluetooth: Fix potential use-after-free when clear keys</title>
<updated>2023-08-11T18:56:16+00:00</updated>
<author>
<name>Min Li</name>
<email>lm0963hack@gmail.com</email>
</author>
<published>2023-08-07T11:07:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=3673952cf0c6cf81b06c66a0b788abeeb02ff3ae'/>
<id>urn:sha1:3673952cf0c6cf81b06c66a0b788abeeb02ff3ae</id>
<content type='text'>
Similar to commit c5d2b6fa26b5 ("Bluetooth: Fix use-after-free in
hci_remove_ltk/hci_remove_irk"). We can not access k after kfree_rcu()
call.

Fixes: d7d41682efc2 ("Bluetooth: Fix Suspicious RCU usage warnings")
Signed-off-by: Min Li &lt;lm0963hack@gmail.com&gt;
Signed-off-by: Luiz Augusto von Dentz &lt;luiz.von.dentz@intel.com&gt;
</content>
</entry>
<entry>
<title>Bluetooth: af_bluetooth: Make BT_PKT_STATUS generic</title>
<updated>2023-08-11T18:49:16+00:00</updated>
<author>
<name>Luiz Augusto von Dentz</name>
<email>luiz.von.dentz@intel.com</email>
</author>
<published>2023-07-13T20:41:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=3f19ffb2f924db5b0925c77818d18ac1f6f08a44'/>
<id>urn:sha1:3f19ffb2f924db5b0925c77818d18ac1f6f08a44</id>
<content type='text'>
This makes the handling of BT_PKT_STATUS more generic so it can be
reused by sockets other than SCO like BT_DEFER_SETUP, etc.

Signed-off-by: Luiz Augusto von Dentz &lt;luiz.von.dentz@intel.com&gt;
</content>
</entry>
<entry>
<title>Bluetooth: Fix hci_suspend_sync crash</title>
<updated>2023-08-11T18:48:20+00:00</updated>
<author>
<name>Ying Hsu</name>
<email>yinghsu@chromium.org</email>
</author>
<published>2023-07-05T21:06:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=573ebae162111063eedc6c838a659ba628f66a0f'/>
<id>urn:sha1:573ebae162111063eedc6c838a659ba628f66a0f</id>
<content type='text'>
If hci_unregister_dev() frees the hci_dev object but hci_suspend_notifier
may still be accessing it, it can cause the program to crash.
Here's the call trace:
  &lt;4&gt;[102152.653246] Call Trace:
  &lt;4&gt;[102152.653254]  hci_suspend_sync+0x109/0x301 [bluetooth]
  &lt;4&gt;[102152.653259]  hci_suspend_dev+0x78/0xcd [bluetooth]
  &lt;4&gt;[102152.653263]  hci_suspend_notifier+0x42/0x7a [bluetooth]
  &lt;4&gt;[102152.653268]  notifier_call_chain+0x43/0x6b
  &lt;4&gt;[102152.653271]  __blocking_notifier_call_chain+0x48/0x69
  &lt;4&gt;[102152.653273]  __pm_notifier_call_chain+0x22/0x39
  &lt;4&gt;[102152.653276]  pm_suspend+0x287/0x57c
  &lt;4&gt;[102152.653278]  state_store+0xae/0xe5
  &lt;4&gt;[102152.653281]  kernfs_fop_write+0x109/0x173
  &lt;4&gt;[102152.653284]  __vfs_write+0x16f/0x1a2
  &lt;4&gt;[102152.653287]  ? selinux_file_permission+0xca/0x16f
  &lt;4&gt;[102152.653289]  ? security_file_permission+0x36/0x109
  &lt;4&gt;[102152.653291]  vfs_write+0x114/0x21d
  &lt;4&gt;[102152.653293]  __x64_sys_write+0x7b/0xdb
  &lt;4&gt;[102152.653296]  do_syscall_64+0x59/0x194
  &lt;4&gt;[102152.653299]  entry_SYSCALL_64_after_hwframe+0x5c/0xc1

This patch holds the reference count of the hci_dev object while
processing it in hci_suspend_notifier to avoid potential crash
caused by the race condition.

Signed-off-by: Ying Hsu &lt;yinghsu@chromium.org&gt;
Signed-off-by: Luiz Augusto von Dentz &lt;luiz.von.dentz@intel.com&gt;
</content>
</entry>
<entry>
<title>Bluetooth: hci_sync: Don't double print name in add/remove adv_monitor</title>
<updated>2023-08-11T18:45:07+00:00</updated>
<author>
<name>Douglas Anderson</name>
<email>dianders@chromium.org</email>
</author>
<published>2023-06-30T22:33:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=6f55eea116ba3646fb5fbb31de703f8cf79d8214'/>
<id>urn:sha1:6f55eea116ba3646fb5fbb31de703f8cf79d8214</id>
<content type='text'>
The hci_add_adv_monitor() hci_remove_adv_monitor() functions call
bt_dev_dbg() to print some debug statements. The bt_dev_dbg() macro
automatically adds in the device's name. That means that we shouldn't
include the name in the bt_dev_dbg() calls.

Suggested-by: Luiz Augusto von Dentz &lt;luiz.dentz@gmail.com&gt;
Signed-off-by: Douglas Anderson &lt;dianders@chromium.org&gt;
Signed-off-by: Luiz Augusto von Dentz &lt;luiz.von.dentz@intel.com&gt;
</content>
</entry>
<entry>
<title>Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_remove_adv_monitor()</title>
<updated>2023-07-20T18:25:50+00:00</updated>
<author>
<name>Douglas Anderson</name>
<email>dianders@chromium.org</email>
</author>
<published>2023-06-30T22:33:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=de6dfcefd107667ce2dbedf4d9337f5ed557a4a1'/>
<id>urn:sha1:de6dfcefd107667ce2dbedf4d9337f5ed557a4a1</id>
<content type='text'>
KASAN reports that there's a use-after-free in
hci_remove_adv_monitor(). Trawling through the disassembly, you can
see that the complaint is from the access in bt_dev_dbg() under the
HCI_ADV_MONITOR_EXT_MSFT case. The problem case happens because
msft_remove_monitor() can end up freeing the monitor
structure. Specifically:
  hci_remove_adv_monitor() -&gt;
  msft_remove_monitor() -&gt;
  msft_remove_monitor_sync() -&gt;
  msft_le_cancel_monitor_advertisement_cb() -&gt;
  hci_free_adv_monitor()

Let's fix the problem by just stashing the relevant data when it's
still valid.

Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor")
Signed-off-by: Douglas Anderson &lt;dianders@chromium.org&gt;
Signed-off-by: Luiz Augusto von Dentz &lt;luiz.von.dentz@intel.com&gt;
</content>
</entry>
<entry>
<title>Bluetooth: use RCU for hci_conn_params and iterate safely in hci_sync</title>
<updated>2023-07-20T18:25:24+00:00</updated>
<author>
<name>Pauli Virtanen</name>
<email>pav@iki.fi</email>
</author>
<published>2023-06-18T22:04:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=195ef75e19287b4bc413da3e3e3722b030ac881e'/>
<id>urn:sha1:195ef75e19287b4bc413da3e3e3722b030ac881e</id>
<content type='text'>
hci_update_accept_list_sync iterates over hdev-&gt;pend_le_conns and
hdev-&gt;pend_le_reports, and waits for controller events in the loop body,
without holding hdev lock.

Meanwhile, these lists and the items may be modified e.g. by
le_scan_cleanup. This can invalidate the list cursor or any other item
in the list, resulting to invalid behavior (eg use-after-free).

Use RCU for the hci_conn_params action lists. Since the loop bodies in
hci_sync block and we cannot use RCU or hdev-&gt;lock for the whole loop,
copy list items first and then iterate on the copy. Only the flags field
is written from elsewhere, so READ_ONCE/WRITE_ONCE should guarantee we
read valid values.

Free params everywhere with hci_conn_params_free so the cleanup is
guaranteed to be done properly.

This fixes the following, which can be triggered e.g. by BlueZ new
mgmt-tester case "Add + Remove Device Nowait - Success", or by changing
hci_le_set_cig_params to always return false, and running iso-tester:

==================================================================
BUG: KASAN: slab-use-after-free in hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
Read of size 8 at addr ffff888001265018 by task kworker/u3:0/32

Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
Workqueue: hci0 hci_cmd_sync_work
Call Trace:
&lt;TASK&gt;
dump_stack_lvl (./arch/x86/include/asm/irqflags.h:134 lib/dump_stack.c:107)
print_report (mm/kasan/report.c:320 mm/kasan/report.c:430)
? __virt_addr_valid (./include/linux/mmzone.h:1915 ./include/linux/mmzone.h:2011 arch/x86/mm/physaddr.c:65)
? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
kasan_report (mm/kasan/report.c:538)
? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
? __pfx_hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2780)
? mutex_lock (kernel/locking/mutex.c:282)
? __pfx_mutex_lock (kernel/locking/mutex.c:282)
? __pfx_mutex_unlock (kernel/locking/mutex.c:538)
? __pfx_update_passive_scan_sync (net/bluetooth/hci_sync.c:2861)
hci_cmd_sync_work (net/bluetooth/hci_sync.c:306)
process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
? __pfx_worker_thread (kernel/workqueue.c:2480)
kthread (kernel/kthread.c:376)
? __pfx_kthread (kernel/kthread.c:331)
ret_from_fork (arch/x86/entry/entry_64.S:314)
&lt;/TASK&gt;

Allocated by task 31:
kasan_save_stack (mm/kasan/common.c:46)
kasan_set_track (mm/kasan/common.c:52)
__kasan_kmalloc (mm/kasan/common.c:374 mm/kasan/common.c:383)
hci_conn_params_add (./include/linux/slab.h:580 ./include/linux/slab.h:720 net/bluetooth/hci_core.c:2277)
hci_connect_le_scan (net/bluetooth/hci_conn.c:1419 net/bluetooth/hci_conn.c:1589)
hci_connect_cis (net/bluetooth/hci_conn.c:2266)
iso_connect_cis (net/bluetooth/iso.c:390)
iso_sock_connect (net/bluetooth/iso.c:899)
__sys_connect (net/socket.c:2003 net/socket.c:2020)
__x64_sys_connect (net/socket.c:2027)
do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120)

Freed by task 15:
kasan_save_stack (mm/kasan/common.c:46)
kasan_set_track (mm/kasan/common.c:52)
kasan_save_free_info (mm/kasan/generic.c:523)
__kasan_slab_free (mm/kasan/common.c:238 mm/kasan/common.c:200 mm/kasan/common.c:244)
__kmem_cache_free (mm/slub.c:1807 mm/slub.c:3787 mm/slub.c:3800)
hci_conn_params_del (net/bluetooth/hci_core.c:2323)
le_scan_cleanup (net/bluetooth/hci_conn.c:202)
process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
kthread (kernel/kthread.c:376)
ret_from_fork (arch/x86/entry/entry_64.S:314)
==================================================================

Fixes: e8907f76544f ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3")
Signed-off-by: Pauli Virtanen &lt;pav@iki.fi&gt;
Signed-off-by: Luiz Augusto von Dentz &lt;luiz.von.dentz@intel.com&gt;
</content>
</entry>
</feed>
