1. 08 Mar, 2024 2 commits
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Fix UAF in hci_acl_create_conn_sync · 3d1c16e9
      Luiz Augusto von Dentz authored
      This fixes the following error caused by hci_conn being freed while
      hcy_acl_create_conn_sync is pending:
      
      ==================================================================
      BUG: KASAN: slab-use-after-free in hci_acl_create_conn_sync+0xa7/0x2e0
      Write of size 2 at addr ffff888002ae0036 by task kworker/u3:0/848
      
      CPU: 0 PID: 848 Comm: kworker/u3:0 Not tainted 6.8.0-rc6-g2ab3e8d6
      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:
       <TASK>
       dump_stack_lvl+0x21/0x70
       print_report+0xce/0x620
       ? preempt_count_sub+0x13/0xc0
       ? __virt_addr_valid+0x15f/0x310
       ? hci_acl_create_conn_sync+0xa7/0x2e0
       kasan_report+0xdf/0x110
       ? hci_acl_create_conn_sync+0xa7/0x2e0
       hci_acl_create_conn_sync+0xa7/0x2e0
       ? __pfx_hci_acl_create_conn_sync+0x10/0x10
       ? __pfx_lock_release+0x10/0x10
       ? __pfx_hci_acl_create_conn_sync+0x10/0x10
       hci_cmd_sync_work+0x138/0x1c0
       process_one_work+0x405/0x800
       ? __pfx_lock_acquire+0x10/0x10
       ? __pfx_process_one_work+0x10/0x10
       worker_thread+0x37b/0x670
       ? __pfx_worker_thread+0x10/0x10
       kthread+0x19b/0x1e0
       ? kthread+0xfe/0x1e0
       ? __pfx_kthread+0x10/0x10
       ret_from_fork+0x2f/0x50
       ? __pfx_kthread+0x10/0x10
       ret_from_fork_asm+0x1a/0x30
       </TASK>
      
      Allocated by task 847:
       kasan_save_stack+0x33/0x60
       kasan_save_track+0x14/0x30
       __kasan_kmalloc+0x8f/0xa0
       hci_conn_add+0xc6/0x970
       hci_connect_acl+0x309/0x410
       pair_device+0x4fb/0x710
       hci_sock_sendmsg+0x933/0xef0
       sock_write_iter+0x2c3/0x2d0
       do_iter_readv_writev+0x21a/0x2e0
       vfs_writev+0x21c/0x7b0
       do_writev+0x14a/0x180
       do_syscall_64+0x77/0x150
       entry_SYSCALL_64_after_hwframe+0x6c/0x74
      
      Freed by task 847:
       kasan_save_stack+0x33/0x60
       kasan_save_track+0x14/0x30
       kasan_save_free_info+0x3b/0x60
       __kasan_slab_free+0xfa/0x150
       kfree+0xcb/0x250
       device_release+0x58/0xf0
       kobject_put+0xbb/0x160
       hci_conn_del+0x281/0x570
       hci_conn_hash_flush+0xfc/0x130
       hci_dev_close_sync+0x336/0x960
       hci_dev_close+0x10e/0x140
       hci_sock_ioctl+0x14a/0x5c0
       sock_ioctl+0x58a/0x5d0
       __x64_sys_ioctl+0x480/0xf60
       do_syscall_64+0x77/0x150
       entry_SYSCALL_64_after_hwframe+0x6c/0x74
      
      Fixes: 45340097 ("Bluetooth: hci_conn: Only do ACL connections sequentially")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      3d1c16e9
    • Frédéric Danis's avatar
      Bluetooth: Fix eir name length · 2ab3e8d6
      Frédéric Danis authored
      According to Section 1.2 of Core Specification Supplement Part A the
      complete or short name strings are defined as utf8s, which should not
      include the trailing NULL for variable length array as defined in Core
      Specification Vol1 Part E Section 2.9.3.
      
      Removing the trailing NULL allows PTS to retrieve the random address based
      on device name, e.g. for SM/PER/KDU/BV-02-C, SM/PER/KDU/BV-08-C or
      GAP/BROB/BCST/BV-03-C.
      
      Fixes: f61851f6 ("Bluetooth: Fix append max 11 bytes of name to scan rsp data")
      Signed-off-by: default avatarFrédéric Danis <frederic.danis@collabora.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      2ab3e8d6
  2. 07 Mar, 2024 1 commit
  3. 06 Mar, 2024 37 commits
    • Vinicius Peixoto's avatar
      Bluetooth: Add new quirk for broken read key length on ATS2851 · 48201a3b
      Vinicius Peixoto authored
      The ATS2851 controller erroneously reports support for the "Read
      Encryption Key Length" HCI command. This makes it unable to connect
      to any devices, since this command is issued by the kernel during the
      connection process in response to an "Encryption Change" HCI event.
      
      Add a new quirk (HCI_QUIRK_BROKEN_ENC_KEY_SIZE) to hint that the command
      is unsupported, preventing it from interrupting the connection process.
      
      This is the error log from btmon before this patch:
      
      > HCI Event: Encryption Change (0x08) plen 4
              Status: Success (0x00)
              Handle: 2048 Address: ...
              Encryption: Enabled with E0 (0x01)
      < HCI Command: Read Encryption Key Size (0x05|0x0008) plen 2
              Handle: 2048 Address: ...
      > HCI Event: Command Status (0x0f) plen 4
            Read Encryption Key Size (0x05|0x0008) ncmd 1
              Status: Unknown HCI Command (0x01)
      Signed-off-by: default avatarVinicius Peixoto <nukelet64@gmail.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      48201a3b
    • Roman Smirnov's avatar
      Bluetooth: mgmt: remove NULL check in add_ext_adv_params_complete() · a310d74d
      Roman Smirnov authored
      Remove the cmd pointer NULL check in add_ext_adv_params_complete()
      because it occurs earlier in add_ext_adv_params(). This check is
      also unnecessary because the pointer is dereferenced just before it.
      
      Found by Linux Verification Center (linuxtesting.org) with Svace.
      Signed-off-by: default avatarRoman Smirnov <r.smirnov@omp.ru>
      Reviewed-by: default avatarSergey Shtylyov <s.shtylyov@omp.ru>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      a310d74d
    • Roman Smirnov's avatar
      Bluetooth: mgmt: remove NULL check in mgmt_set_connectable_complete() · 3237da12
      Roman Smirnov authored
      Remove the cmd pointer NULL check in mgmt_set_connectable_complete()
      because it occurs earlier in set_connectable(). This check is also
      unnecessary because the pointer is dereferenced just before it.
      
      Found by Linux Verification Center (linuxtesting.org) with Svace.
      Signed-off-by: default avatarRoman Smirnov <r.smirnov@omp.ru>
      Reviewed-by: default avatarSergey Shtylyov <s.shtylyov@omp.ru>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      3237da12
    • Peter Tsao's avatar
      Bluetooth: btusb: Add support Mediatek MT7920 · 1cb63d80
      Peter Tsao authored
      This patch is added support Mediatek MT7920
      The firmware location of MT7920 will set to
      /lib/firmware/mediatek/
      
      The information in /sys/kernel/debug/usb/devices about MT7920U
      Bluetooth device is listed as the below
      
      T:  Bus=01 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 12 Spd=480  MxCh= 0
      D:  Ver= 2.10 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs=  1
      P:  Vendor=0e8d ProdID=7920 Rev= 1.00
      S:  Manufacturer=MediaTek Inc.
      S:  Product=Wireless_Device
      S:  SerialNumber=000000000
      C:* #Ifs= 3 Cfg#= 1 Atr=e0 MxPwr=100mA
      A:  FirstIf#= 0 IfCount= 3 Cls=e0(wlcon) Sub=01 Prot=01
      I:* If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
      E:  Ad=81(I) Atr=03(Int.) MxPS=  16 Ivl=125us
      E:  Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
      E:  Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
      I:* If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
      E:  Ad=83(I) Atr=01(Isoc) MxPS=   0 Ivl=1ms
      E:  Ad=03(O) Atr=01(Isoc) MxPS=   0 Ivl=1ms
      I:  If#= 1 Alt= 1 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
      E:  Ad=83(I) Atr=01(Isoc) MxPS=   9 Ivl=1ms
      E:  Ad=03(O) Atr=01(Isoc) MxPS=   9 Ivl=1ms
      I:  If#= 1 Alt= 2 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
      E:  Ad=83(I) Atr=01(Isoc) MxPS=  17 Ivl=1ms
      E:  Ad=03(O) Atr=01(Isoc) MxPS=  17 Ivl=1ms
      I:  If#= 1 Alt= 3 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
      E:  Ad=83(I) Atr=01(Isoc) MxPS=  25 Ivl=1ms
      E:  Ad=03(O) Atr=01(Isoc) MxPS=  25 Ivl=1ms
      I:  If#= 1 Alt= 4 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
      E:  Ad=83(I) Atr=01(Isoc) MxPS=  33 Ivl=1ms
      E:  Ad=03(O) Atr=01(Isoc) MxPS=  33 Ivl=1ms
      I:  If#= 1 Alt= 5 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
      E:  Ad=83(I) Atr=01(Isoc) MxPS=  49 Ivl=1ms
      E:  Ad=03(O) Atr=01(Isoc) MxPS=  49 Ivl=1ms
      I:  If#= 1 Alt= 6 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
      E:  Ad=83(I) Atr=01(Isoc) MxPS=  63 Ivl=1ms
      E:  Ad=03(O) Atr=01(Isoc) MxPS=  63 Ivl=1ms
      I:* If#= 2 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=(none)
      E:  Ad=8a(I) Atr=03(Int.) MxPS=  64 Ivl=125us
      E:  Ad=0a(O) Atr=03(Int.) MxPS=  64 Ivl=125us
      I:  If#= 2 Alt= 1 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=(none)
      E:  Ad=8a(I) Atr=03(Int.) MxPS= 512 Ivl=125us
      E:  Ad=0a(O) Atr=03(Int.) MxPS= 512 Ivl=125us
      Signed-off-by: default avatarPeter Tsao <peter.tsao@mediatek.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      1cb63d80
    • Takashi Iwai's avatar
      Bluetooth: btmtk: Add MODULE_FIRMWARE() for MT7922 · 3e465a07
      Takashi Iwai authored
      Since dracut refers to the module info for defining the required
      firmware files and btmtk driver doesn't provide the firmware info for
      MT7922, the generate initrd misses the firmware, resulting in the
      broken Bluetooth.
      
      This patch simply adds the MODULE_FIRMWARE() for the missing entry
      for covering that.
      
      Link: https://bugzilla.suse.com/show_bug.cgi?id=1214133Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Reviewed-by: default avatarPaul Menzel <pmenzel@molgen.mpg.de>
      Reviewed-by: default avatarMatthias Brugger <matthias.bgg@gmail.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      3e465a07
    • Marcel Ziswiler's avatar
      Bluetooth: btnxpuart: Fix btnxpuart_close · 664130c0
      Marcel Ziswiler authored
      Fix scheduling while atomic BUG in btnxpuart_close(), properly
      purge the transmit queue and free the receive skb.
      
      [   10.973809] BUG: scheduling while atomic: kworker/u9:0/80/0x00000002
      ...
      [   10.980740] CPU: 3 PID: 80 Comm: kworker/u9:0 Not tainted 6.8.0-rc7-0.0.0-devel-00005-g61fdfceacf09 #1
      [   10.980751] Hardware name: Toradex Verdin AM62 WB on Dahlia Board (DT)
      [   10.980760] Workqueue: hci0 hci_power_off [bluetooth]
      [   10.981169] Call trace:
      ...
      [   10.981363]  uart_update_mctrl+0x58/0x78
      [   10.981373]  uart_dtr_rts+0x104/0x114
      [   10.981381]  tty_port_shutdown+0xd4/0xdc
      [   10.981396]  tty_port_close+0x40/0xbc
      [   10.981407]  uart_close+0x34/0x9c
      [   10.981414]  ttyport_close+0x50/0x94
      [   10.981430]  serdev_device_close+0x40/0x50
      [   10.981442]  btnxpuart_close+0x24/0x98 [btnxpuart]
      [   10.981469]  hci_dev_close_sync+0x2d8/0x718 [bluetooth]
      [   10.981728]  hci_dev_do_close+0x2c/0x70 [bluetooth]
      [   10.981862]  hci_power_off+0x20/0x64 [bluetooth]
      
      Fixes: 689ca16e ("Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMarcel Ziswiler <marcel.ziswiler@toradex.com>
      Reviewed-by: default avatarNeeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>
      Signed-off-by: default avatarFrancesco Dolcini <francesco.dolcini@toradex.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      664130c0
    • Dan Carpenter's avatar
      Bluetooth: ISO: Clean up returns values in iso_connect_ind() · 18d88f0f
      Dan Carpenter authored
      This function either returns 0 or HCI_LM_ACCEPT.  Make it clearer which
      returns are which and delete the "lm" variable because it is no longer
      required.
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      18d88f0f
    • Pauli Virtanen's avatar
      Bluetooth: fix use-after-free in accessing skb after sending it · 947ec0d0
      Pauli Virtanen authored
      hci_send_cmd_sync first sends skb and then tries to clone it.  However,
      the driver may have already freed the skb at that point.
      
      Fix by cloning the sent_cmd cloned just above, instead of the original.
      
      Log:
      ================================================================
      BUG: KASAN: slab-use-after-free in __copy_skb_header+0x1a/0x240
      ...
      Call Trace: ..
       __skb_clone+0x59/0x2c0
       hci_cmd_work+0x3b3/0x3d0 [bluetooth]
       process_one_work+0x459/0x900
      ...
      Allocated by task 129: ...
       __alloc_skb+0x1ae/0x220
       __hci_cmd_sync_sk+0x44c/0x7a0 [bluetooth]
       __hci_cmd_sync_status+0x24/0xb0 [bluetooth]
       set_cig_params_sync+0x778/0x7d0 [bluetooth]
      ...
      Freed by task 0: ...
       kmem_cache_free+0x157/0x3c0
       __usb_hcd_giveback_urb+0x11e/0x1e0
       usb_giveback_urb_bh+0x1ad/0x2a0
       tasklet_action_common.isra.0+0x259/0x4a0
       __do_softirq+0x15b/0x5a7
      ================================================================
      
      Fixes: 2615fd9a ("Bluetooth: hci_sync: Fix overwriting request callback")
      Signed-off-by: default avatarPauli Virtanen <pav@iki.fi>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      947ec0d0
    • Luiz Augusto von Dentz's avatar
      Bluetooth: af_bluetooth: Fix deadlock · f7b94bdc
      Luiz Augusto von Dentz authored
      Attemting to do sock_lock on .recvmsg may cause a deadlock as shown
      bellow, so instead of using sock_sock this uses sk_receive_queue.lock
      on bt_sock_ioctl to avoid the UAF:
      
      INFO: task kworker/u9:1:121 blocked for more than 30 seconds.
            Not tainted 6.7.6-lemon #183
      Workqueue: hci0 hci_rx_work
      Call Trace:
       <TASK>
       __schedule+0x37d/0xa00
       schedule+0x32/0xe0
       __lock_sock+0x68/0xa0
       ? __pfx_autoremove_wake_function+0x10/0x10
       lock_sock_nested+0x43/0x50
       l2cap_sock_recv_cb+0x21/0xa0
       l2cap_recv_frame+0x55b/0x30a0
       ? psi_task_switch+0xeb/0x270
       ? finish_task_switch.isra.0+0x93/0x2a0
       hci_rx_work+0x33a/0x3f0
       process_one_work+0x13a/0x2f0
       worker_thread+0x2f0/0x410
       ? __pfx_worker_thread+0x10/0x10
       kthread+0xe0/0x110
       ? __pfx_kthread+0x10/0x10
       ret_from_fork+0x2c/0x50
       ? __pfx_kthread+0x10/0x10
       ret_from_fork_asm+0x1b/0x30
       </TASK>
      
      Fixes: 2e07e834 ("Bluetooth: af_bluetooth: Fix Use-After-Free in bt_sock_recvmsg")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      f7b94bdc
    • Luiz Augusto von Dentz's avatar
      Bluetooth: bnep: Fix out-of-bound access · 0f0639b4
      Luiz Augusto von Dentz authored
      This fixes attempting to access past ethhdr.h_source, although it seems
      intentional to copy also the contents of h_proto this triggers
      out-of-bound access problems with the likes of static analyzer, so this
      instead just copy ETH_ALEN and then proceed to use put_unaligned to copy
      h_proto separetely.
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      0f0639b4
    • Luiz Augusto von Dentz's avatar
      Bluetooth: btusb: Fix memory leak · 79f4127a
      Luiz Augusto von Dentz authored
      This checks if CONFIG_DEV_COREDUMP is enabled before attempting to clone
      the skb and also make sure btmtk_process_coredump frees the skb passed
      following the same logic.
      
      Fixes: 0b701513 ("Bluetooth: btusb: mediatek: add MediaTek devcoredump support")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      79f4127a
    • Luiz Augusto von Dentz's avatar
      Bluetooth: msft: Fix memory leak · a6e06258
      Luiz Augusto von Dentz authored
      Fix leaking buffer allocated to send MSFT_OP_LE_MONITOR_ADVERTISEMENT.
      
      Fixes: 9e14606d ("Bluetooth: msft: Extended monitor tracking by address filter")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      a6e06258
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_core: Fix possible buffer overflow · 81137162
      Luiz Augusto von Dentz authored
      struct hci_dev_info has a fixed size name[8] field so in the event that
      hdev->name is bigger than that strcpy would attempt to write past its
      size, so this fixes this problem by switching to use strscpy.
      
      Fixes: dcda1657 ("Bluetooth: hci_core: Fix build warnings")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      81137162
    • Andrey Skvortsov's avatar
      Bluetooth: btrtl: fix out of bounds memory access · de4e88ec
      Andrey Skvortsov authored
      The problem is detected by KASAN.
      btrtl driver uses private hci data to store 'struct btrealtek_data'.
      If btrtl driver is used with btusb, then memory for private hci data
      is allocated in btusb. But no private data is allocated after hci_dev,
      when btrtl is used with hci_h5.
      
      This commit adds memory allocation for hci_h5 case.
      
       ==================================================================
       BUG: KASAN: slab-out-of-bounds in btrtl_initialize+0x6cc/0x958 [btrtl]
       Write of size 8 at addr ffff00000f5a5748 by task kworker/u9:0/76
      
       Hardware name: Pine64 PinePhone (1.2) (DT)
       Workqueue: hci0 hci_power_on [bluetooth]
       Call trace:
        dump_backtrace+0x9c/0x128
        show_stack+0x20/0x38
        dump_stack_lvl+0x48/0x60
        print_report+0xf8/0x5d8
        kasan_report+0x90/0xd0
        __asan_store8+0x9c/0xc0
        	 [btrtl]
        h5_btrtl_setup+0xd0/0x2f8 [hci_uart]
        h5_setup+0x50/0x80 [hci_uart]
        hci_uart_setup+0xd4/0x260 [hci_uart]
        hci_dev_open_sync+0x1cc/0xf68 [bluetooth]
        hci_dev_do_open+0x34/0x90 [bluetooth]
        hci_power_on+0xc4/0x3c8 [bluetooth]
        process_one_work+0x328/0x6f0
        worker_thread+0x410/0x778
        kthread+0x168/0x178
        ret_from_fork+0x10/0x20
      
       Allocated by task 53:
        kasan_save_stack+0x3c/0x68
        kasan_save_track+0x20/0x40
        kasan_save_alloc_info+0x68/0x78
        __kasan_kmalloc+0xd4/0xd8
        __kmalloc+0x1b4/0x3b0
        hci_alloc_dev_priv+0x28/0xa58 [bluetooth]
        hci_uart_register_device+0x118/0x4f8 [hci_uart]
        h5_serdev_probe+0xf4/0x178 [hci_uart]
        serdev_drv_probe+0x54/0xa0
        really_probe+0x254/0x588
        __driver_probe_device+0xc4/0x210
        driver_probe_device+0x64/0x160
        __driver_attach_async_helper+0x88/0x158
        async_run_entry_fn+0xd0/0x388
        process_one_work+0x328/0x6f0
        worker_thread+0x410/0x778
        kthread+0x168/0x178
        ret_from_fork+0x10/0x20
      
       Last potentially related work creation:
        kasan_save_stack+0x3c/0x68
        __kasan_record_aux_stack+0xb0/0x150
        kasan_record_aux_stack_noalloc+0x14/0x20
        __queue_work+0x33c/0x960
        queue_work_on+0x98/0xc0
        hci_recv_frame+0xc8/0x1e8 [bluetooth]
        h5_complete_rx_pkt+0x2c8/0x800 [hci_uart]
        h5_rx_payload+0x98/0xb8 [hci_uart]
        h5_recv+0x158/0x3d8 [hci_uart]
        hci_uart_receive_buf+0xa0/0xe8 [hci_uart]
        ttyport_receive_buf+0xac/0x178
        flush_to_ldisc+0x130/0x2c8
        process_one_work+0x328/0x6f0
        worker_thread+0x410/0x778
        kthread+0x168/0x178
        ret_from_fork+0x10/0x20
      
       Second to last potentially related work creation:
        kasan_save_stack+0x3c/0x68
        __kasan_record_aux_stack+0xb0/0x150
        kasan_record_aux_stack_noalloc+0x14/0x20
        __queue_work+0x788/0x960
        queue_work_on+0x98/0xc0
        __hci_cmd_sync_sk+0x23c/0x7a0 [bluetooth]
        __hci_cmd_sync+0x24/0x38 [bluetooth]
        btrtl_initialize+0x760/0x958 [btrtl]
        h5_btrtl_setup+0xd0/0x2f8 [hci_uart]
        h5_setup+0x50/0x80 [hci_uart]
        hci_uart_setup+0xd4/0x260 [hci_uart]
        hci_dev_open_sync+0x1cc/0xf68 [bluetooth]
        hci_dev_do_open+0x34/0x90 [bluetooth]
        hci_power_on+0xc4/0x3c8 [bluetooth]
        process_one_work+0x328/0x6f0
        worker_thread+0x410/0x778
        kthread+0x168/0x178
        ret_from_fork+0x10/0x20
       ==================================================================
      
      Fixes: 5b355944 ("Bluetooth: btrtl: Add btrealtek data struct")
      Fixes: 044014ce ("Bluetooth: btrtl: Add Realtek devcoredump support")
      Signed-off-by: default avatarAndrey Skvortsov <andrej.skvortzov@gmail.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      de4e88ec
    • Andrey Skvortsov's avatar
      Bluetooth: hci_h5: Add ability to allocate memory for private data · 7a6d793e
      Andrey Skvortsov authored
      In some cases uart-base drivers may need to use priv data. For
      example, to store information needed for devcoredump.
      
      Fixes: 044014ce ("Bluetooth: btrtl: Add Realtek devcoredump support")
      Signed-off-by: default avatarAndrey Skvortsov <andrej.skvortzov@gmail.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      7a6d793e
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Fix overwriting request callback · 2615fd9a
      Luiz Augusto von Dentz authored
      In a few cases the stack may generate commands as responses to events
      which would happen to overwrite the sent_cmd, so this attempts to store
      the request in req_skb so even if sent_cmd is replaced with a new
      command the pending request will remain in stored in req_skb.
      
      Fixes: 6a98e383 ("Bluetooth: Add helper for serialized HCI command execution")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      2615fd9a
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Use QoS to determine which PHY to scan · 22cbf4f8
      Luiz Augusto von Dentz authored
      This used the hci_conn QoS to determine which PHY to scan when creating
      a PA Sync.
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      22cbf4f8
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Use address filtering when HCI_PA_SYNC is set · bba71ef1
      Luiz Augusto von Dentz authored
      If HCI_PA_SYNC flag is set it means there is a Periodic Advertising
      Synchronization pending, so this attempts to locate the address passed
      to HCI_OP_LE_PA_CREATE_SYNC and program it in the accept list so only
      reports with that address are processed.
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      bba71ef1
    • Iulia Tanasescu's avatar
      Bluetooth: ISO: Reassemble PA data for bcast sink · 168d9bf9
      Iulia Tanasescu authored
      This adds support to reassemble PA data for a Broadcast Sink
      listening socket. This is needed in case the BASE is received
      fragmented in multiple PA reports.
      
      PA data is first reassembled inside the hcon, before the BASE
      is extracted and stored inside the socket. The length of the
      le_per_adv_data hcon array has been raised to 1650, to accommodate
      the maximum PA data length that can come fragmented, according to
      spec.
      Signed-off-by: default avatarIulia Tanasescu <iulia.tanasescu@nxp.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      168d9bf9
    • Iulia Tanasescu's avatar
      Bluetooth: ISO: Add hcon for listening bis sk · 02171da6
      Iulia Tanasescu authored
      This creates a hcon instance at bis listen, before the PA sync
      procedure is started.
      Signed-off-by: default avatarIulia Tanasescu <iulia.tanasescu@nxp.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      02171da6
    • Luiz Augusto von Dentz's avatar
      Bluetooth: btintel: Fixe build regression · 6e62ebfb
      Luiz Augusto von Dentz authored
      This fixes the following build regression:
      
      drivers-bluetooth-btintel.c-btintel_read_version()-warn:
      passing-zero-to-PTR_ERR
      
      Fixes: b79e0409 ("Bluetooth: btintel: Fix null ptr deref in btintel_read_version")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      6e62ebfb
    • Bartosz Golaszewski's avatar
      Bluetooth: hci_qca: don't use IS_ERR_OR_NULL() with gpiod_get_optional() · 56d074d2
      Bartosz Golaszewski authored
      The optional variants for the gpiod_get() family of functions return NULL
      if the GPIO in question is not associated with this device. They return
      ERR_PTR() on any other error. NULL descriptors are graciously handled by
      GPIOLIB and can be safely passed to any of the GPIO consumer interfaces
      as they will return 0 and act as if the function succeeded. If one is
      using the optional variant, then there's no point in checking for NULL.
      
      Fixes: 68456671 ("Bluetooth: hci_qca: Fix NULL vs IS_ERR_OR_NULL check in qca_serdev_probe")
      Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      56d074d2
    • Kiran K's avatar
      Bluetooth: btintel: Print Firmware Sequencer information · a7ba218a
      Kiran K authored
      Firmware sequencer (FSEQ) is a common code shared across Bluetooth
      and Wifi. Printing FSEQ will help to debug if there is any mismatch
      between Bluetooth and Wifi FSEQ.
      Signed-off-by: default avatarKiran K <kiran.k@intel.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      a7ba218a
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Fix UAF on create_le_conn_complete · f7cbce60
      Luiz Augusto von Dentz authored
      While waiting for hci_dev_lock the hci_conn object may be cleanup
      causing the following trace:
      
      BUG: KASAN: slab-use-after-free in hci_connect_le_scan_cleanup+0x29/0x350
      Read of size 8 at addr ffff888001a50a30 by task kworker/u3:1/111
      
      CPU: 0 PID: 111 Comm: kworker/u3:1 Not tainted
      6.8.0-rc2-00701-g8179b15ab3fd-dirty #6418
      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:
       <TASK>
       dump_stack_lvl+0x21/0x70
       print_report+0xce/0x620
       ? preempt_count_sub+0x13/0xc0
       ? __virt_addr_valid+0x15f/0x310
       ? hci_connect_le_scan_cleanup+0x29/0x350
       kasan_report+0xdf/0x110
       ? hci_connect_le_scan_cleanup+0x29/0x350
       hci_connect_le_scan_cleanup+0x29/0x350
       create_le_conn_complete+0x25c/0x2c0
      
      Fixes: 881559af ("Bluetooth: hci_sync: Attempt to dequeue connection attempt")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      f7cbce60
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Fix UAF on hci_abort_conn_sync · 7453847f
      Luiz Augusto von Dentz authored
      Fixes the following trace where hci_acl_create_conn_sync attempts to
      call hci_abort_conn_sync after timeout:
      
      BUG: KASAN: slab-use-after-free in hci_abort_conn_sync
      (net/bluetooth/hci_sync.c:5439)
      Read of size 2 at addr ffff88800322c032 by task kworker/u3:2/36
      
      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:
      <TASK>
      dump_stack_lvl (./arch/x86/include/asm/irqflags.h:26
      ./arch/x86/include/asm/irqflags.h:67 ./arch/x86/include/asm/irqflags.h:127
      lib/dump_stack.c:107)
      print_report (mm/kasan/report.c:378 mm/kasan/report.c:488)
      ? preempt_count_sub (kernel/sched/core.c:5889)
      ? __virt_addr_valid (./arch/x86/include/asm/preempt.h:103 (discriminator 1)
      ./include/linux/rcupdate.h:865 (discriminator 1)
      ./include/linux/mmzone.h:2026 (discriminator 1)
      arch/x86/mm/physaddr.c:65 (discriminator 1))
      ? hci_abort_conn_sync (net/bluetooth/hci_sync.c:5439)
      kasan_report (mm/kasan/report.c:603)
      ? hci_abort_conn_sync (net/bluetooth/hci_sync.c:5439)
      hci_abort_conn_sync (net/bluetooth/hci_sync.c:5439)
      ? __pfx_hci_abort_conn_sync (net/bluetooth/hci_sync.c:5433)
      hci_acl_create_conn_sync (net/bluetooth/hci_sync.c:6681)
      
      Fixes: 45340097 ("Bluetooth: hci_conn: Only do ACL connections sequentially")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      7453847f
    • Ricardo B. Marliere's avatar
      Bluetooth: constify the struct device_type usage · 412b894a
      Ricardo B. Marliere authored
      Since commit aed65af1 ("drivers: make device_type const"), the driver
      core can properly handle constant struct device_type. Move the bt_type and
      bnep_type variables to be constant structures as well, placing it into
      read-only memory which can not be modified at runtime.
      
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarRicardo B. Marliere <ricardo@marliere.net>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      412b894a
    • Christophe JAILLET's avatar
      Bluetooth: btbcm: Use devm_kstrdup() · f9183eaa
      Christophe JAILLET authored
      Use devm_kstrdup() instead of hand-writing it.
      It is less verbose.
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      f9183eaa
    • Christophe JAILLET's avatar
      Bluetooth: btbcm: Use strreplace() · e49f18b9
      Christophe JAILLET authored
      Use strreplace() instead of hand-writing it.
      It is less verbose.
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      e49f18b9
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Attempt to dequeue connection attempt · 881559af
      Luiz Augusto von Dentz authored
      If connection is still queued/pending in the cmd_sync queue it means no
      command has been generated and it should be safe to just dequeue the
      callback when it is being aborted.
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      881559af
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Add helper functions to manipulate cmd_sync queue · 505ea2b2
      Luiz Augusto von Dentz authored
      This adds functions to queue, dequeue and lookup into the cmd_sync
      list.
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      505ea2b2
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_conn: Fix UAF Write in __hci_acl_create_connection_sync · 5f641f03
      Luiz Augusto von Dentz authored
      This fixes the UAF on __hci_acl_create_connection_sync caused by
      connection abortion, it uses the same logic as to LE_LINK which uses
      hci_cmd_sync_cancel to prevent the callback to run if the connection is
      abort prematurely.
      
      Reported-by: syzbot+3f0a39be7a2035700868@syzkaller.appspotmail.com
      Fixes: 45340097 ("Bluetooth: hci_conn: Only do ACL connections sequentially")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      5f641f03
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_conn: Always use sk_timeo as conn_timeout · bf98feea
      Luiz Augusto von Dentz authored
      This aligns the use socket sk_timeo as conn_timeout when initiating a
      connection and then use it when scheduling the resulting HCI command,
      that way the command is actually aborted synchronously thus not
      blocking commands generated by hci_abort_conn_sync to inform the
      controller the connection is to be aborted.
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      bf98feea
    • Lukas Bulwahn's avatar
      Bluetooth: hci_event: Remove code to removed CONFIG_BT_HS · f4b0c2b4
      Lukas Bulwahn authored
      Commit cec9f3c5561d ("Bluetooth: Remove BT_HS") removes config BT_HS, but
      misses two "ifdef BT_HS" blocks in hci_event.c.
      
      Remove this dead code from this removed config option.
      Signed-off-by: default avatarLukas Bulwahn <lukas.bulwahn@gmail.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      f4b0c2b4
    • Jonas Dreßler's avatar
      Bluetooth: Remove pending ACL connection attempts · 4aa42119
      Jonas Dreßler authored
      With the last commit we moved to using the hci_sync queue for "Create
      Connection" requests, removing the need for retrying the paging after
      finished/failed "Create Connection" requests and after the end of
      inquiries.
      
      hci_conn_check_pending() was used to trigger this retry, we can remove it
      now.
      
      Note that we can also remove the special handling for COMMAND_DISALLOWED
      errors in the completion handler of "Create Connection", because "Create
      Connection" requests are now always serialized.
      
      This is somewhat reverting commit 4c67bc74 ("[Bluetooth] Support
      concurrent connect requests").
      
      With this, the BT_CONNECT2 state of ACL hci_conn objects should now be
      back to meaning only one thing: That we received a "Connection Request"
      from another device (see hci_conn_request_evt), but the response to that
      is going to be deferred.
      Signed-off-by: default avatarJonas Dreßler <verdre@v0yd.nl>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      4aa42119
    • Jonas Dreßler's avatar
      Bluetooth: hci_conn: Only do ACL connections sequentially · 45340097
      Jonas Dreßler authored
      Pretty much all bluetooth chipsets only support paging a single device at
      a time, and if they don't reject a secondary "Create Connection" request
      while another is still ongoing, they'll most likely serialize those
      requests in the firware.
      
      With commit 4c67bc74 ("[Bluetooth] Support concurrent connect
      requests") we started adding some serialization of our own in case the
      adapter returns "Command Disallowed" HCI error.
      
      This commit was using the BT_CONNECT2 state for the serialization, this
      state is also used for a few more things (most notably to indicate we're
      waiting for an inquiry to cancel) and therefore a bit unreliable. Also
      not all BT firwares would respond with "Command Disallowed" on too many
      connection requests, some will also respond with "Hardware Failure"
      (BCM4378), and others will error out later and send a "Connect Complete"
      event with error "Rejected Limited Resources" (Marvell 88W8897).
      
      We can clean things up a bit and also make the serialization more reliable
      by using our hci_sync machinery to always do "Create Connection" requests
      in a sequential manner.
      
      This is very similar to what we're already doing for establishing LE
      connections, and it works well there.
      
      Note that this causes a test failure in mgmt-tester (test "Pair Device
      - Power off 1") because the hci_abort_conn_sync() changes the error we
      return on timeout of the "Create Connection". We'll fix this on the
      mgmt-tester side by adjusting the expected error for the test.
      Signed-off-by: default avatarJonas Dreßler <verdre@v0yd.nl>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      45340097
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_event: Fix not indicating new connection for BIG Sync · eeda1bf9
      Luiz Augusto von Dentz authored
      BIG Sync (aka. Broadcast sink) requires to inform that the device is
      connected when a data path is active otherwise userspace could attempt
      to free resources allocated to the device object while scanning.
      
      Fixes: 1d11d70d ("Bluetooth: ISO: Pass BIG encryption info through QoS")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      eeda1bf9
    • Luiz Augusto von Dentz's avatar
      Bluetooth: Remove BT_HS · e7b02296
      Luiz Augusto von Dentz authored
      High Speed, Alternate MAC and PHY (AMP) extension, has been removed from
      Bluetooth Core specification on 5.3:
      
      https://www.bluetooth.com/blog/new-core-specification-v5-3-feature-enhancements/
      
      Fixes: 244bc377 ("Bluetooth: Add BT_HS config option")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      e7b02296