1. 03 11月, 2022 6 次提交
    • L
      Bluetooth: L2CAP: Fix attempting to access uninitialized memory · b1a2cd50
      Luiz Augusto von Dentz 提交于
      On l2cap_parse_conf_req the variable efs is only initialized if
      remote_efs has been set.
      
      CVE: CVE-2022-42895
      CC: stable@vger.kernel.org
      Reported-by: NTamás Koczka <poprdi@google.com>
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Reviewed-by: NTedd Ho-Jeong An <tedd.an@intel.com>
      b1a2cd50
    • L
      Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm · f937b758
      Luiz Augusto von Dentz 提交于
      l2cap_global_chan_by_psm shall not return fixed channels as they are not
      meant to be connected by (S)PSM.
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Reviewed-by: NTedd Ho-Jeong An <tedd.an@intel.com>
      f937b758
    • L
      Bluetooth: L2CAP: Fix accepting connection request for invalid SPSM · 711f8c3f
      Luiz Augusto von Dentz 提交于
      The Bluetooth spec states that the valid range for SPSM is from
      0x0001-0x00ff so it is invalid to accept values outside of this range:
      
        BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 3, Part A
        page 1059:
        Table 4.15: L2CAP_LE_CREDIT_BASED_CONNECTION_REQ SPSM ranges
      
      CVE: CVE-2022-42896
      CC: stable@vger.kernel.org
      Reported-by: NTamás Koczka <poprdi@google.com>
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Reviewed-by: NTedd Ho-Jeong An <tedd.an@intel.com>
      711f8c3f
    • H
      Bluetooth: L2CAP: Fix memory leak in vhci_write · 7c9524d9
      Hawkins Jiawei 提交于
      Syzkaller reports a memory leak as follows:
      ====================================
      BUG: memory leak
      unreferenced object 0xffff88810d81ac00 (size 240):
        [...]
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<ffffffff838733d9>] __alloc_skb+0x1f9/0x270 net/core/skbuff.c:418
          [<ffffffff833f742f>] alloc_skb include/linux/skbuff.h:1257 [inline]
          [<ffffffff833f742f>] bt_skb_alloc include/net/bluetooth/bluetooth.h:469 [inline]
          [<ffffffff833f742f>] vhci_get_user drivers/bluetooth/hci_vhci.c:391 [inline]
          [<ffffffff833f742f>] vhci_write+0x5f/0x230 drivers/bluetooth/hci_vhci.c:511
          [<ffffffff815e398d>] call_write_iter include/linux/fs.h:2192 [inline]
          [<ffffffff815e398d>] new_sync_write fs/read_write.c:491 [inline]
          [<ffffffff815e398d>] vfs_write+0x42d/0x540 fs/read_write.c:578
          [<ffffffff815e3cdd>] ksys_write+0x9d/0x160 fs/read_write.c:631
          [<ffffffff845e0645>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
          [<ffffffff845e0645>] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
          [<ffffffff84600087>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
      ====================================
      
      HCI core will uses hci_rx_work() to process frame, which is queued to
      the hdev->rx_q tail in hci_recv_frame() by HCI driver.
      
      Yet the problem is that, HCI core may not free the skb after handling
      ACL data packets. To be more specific, when start fragment does not
      contain the L2CAP length, HCI core just copies skb into conn->rx_skb and
      finishes frame process in l2cap_recv_acldata(), without freeing the skb,
      which triggers the above memory leak.
      
      This patch solves it by releasing the relative skb, after processing
      the above case in l2cap_recv_acldata().
      
      Fixes: 4d7ea8ee ("Bluetooth: L2CAP: Fix handling fragmented length")
      Link: https://lore.kernel.org/all/0000000000000d0b1905e6aaef64@google.com/
      Reported-and-tested-by: syzbot+8f819e36e01022991cfa@syzkaller.appspotmail.com
      Signed-off-by: NHawkins Jiawei <yin31149@gmail.com>
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      7c9524d9
    • Z
      Bluetooth: L2CAP: fix use-after-free in l2cap_conn_del() · 0d0e2d03
      Zhengchao Shao 提交于
      When l2cap_recv_frame() is invoked to receive data, and the cid is
      L2CAP_CID_A2MP, if the channel does not exist, it will create a channel.
      However, after a channel is created, the hold operation of the channel
      is not performed. In this case, the value of channel reference counting
      is 1. As a result, after hci_error_reset() is triggered, l2cap_conn_del()
      invokes the close hook function of A2MP to release the channel. Then
       l2cap_chan_unlock(chan) will trigger UAF issue.
      
      The process is as follows:
      Receive data:
      l2cap_data_channel()
          a2mp_channel_create()  --->channel ref is 2
          l2cap_chan_put()       --->channel ref is 1
      
      Triger event:
          hci_error_reset()
              hci_dev_do_close()
              ...
              l2cap_disconn_cfm()
                  l2cap_conn_del()
                      l2cap_chan_hold()    --->channel ref is 2
                      l2cap_chan_del()     --->channel ref is 1
                      a2mp_chan_close_cb() --->channel ref is 0, release channel
                      l2cap_chan_unlock()  --->UAF of channel
      
      The detailed Call Trace is as follows:
      BUG: KASAN: use-after-free in __mutex_unlock_slowpath+0xa6/0x5e0
      Read of size 8 at addr ffff8880160664b8 by task kworker/u11:1/7593
      Workqueue: hci0 hci_error_reset
      Call Trace:
       <TASK>
       dump_stack_lvl+0xcd/0x134
       print_report.cold+0x2ba/0x719
       kasan_report+0xb1/0x1e0
       kasan_check_range+0x140/0x190
       __mutex_unlock_slowpath+0xa6/0x5e0
       l2cap_conn_del+0x404/0x7b0
       l2cap_disconn_cfm+0x8c/0xc0
       hci_conn_hash_flush+0x11f/0x260
       hci_dev_close_sync+0x5f5/0x11f0
       hci_dev_do_close+0x2d/0x70
       hci_error_reset+0x9e/0x140
       process_one_work+0x98a/0x1620
       worker_thread+0x665/0x1080
       kthread+0x2e4/0x3a0
       ret_from_fork+0x1f/0x30
       </TASK>
      
      Allocated by task 7593:
       kasan_save_stack+0x1e/0x40
       __kasan_kmalloc+0xa9/0xd0
       l2cap_chan_create+0x40/0x930
       amp_mgr_create+0x96/0x990
       a2mp_channel_create+0x7d/0x150
       l2cap_recv_frame+0x51b8/0x9a70
       l2cap_recv_acldata+0xaa3/0xc00
       hci_rx_work+0x702/0x1220
       process_one_work+0x98a/0x1620
       worker_thread+0x665/0x1080
       kthread+0x2e4/0x3a0
       ret_from_fork+0x1f/0x30
      
      Freed by task 7593:
       kasan_save_stack+0x1e/0x40
       kasan_set_track+0x21/0x30
       kasan_set_free_info+0x20/0x30
       ____kasan_slab_free+0x167/0x1c0
       slab_free_freelist_hook+0x89/0x1c0
       kfree+0xe2/0x580
       l2cap_chan_put+0x22a/0x2d0
       l2cap_conn_del+0x3fc/0x7b0
       l2cap_disconn_cfm+0x8c/0xc0
       hci_conn_hash_flush+0x11f/0x260
       hci_dev_close_sync+0x5f5/0x11f0
       hci_dev_do_close+0x2d/0x70
       hci_error_reset+0x9e/0x140
       process_one_work+0x98a/0x1620
       worker_thread+0x665/0x1080
       kthread+0x2e4/0x3a0
       ret_from_fork+0x1f/0x30
      
      Last potentially related work creation:
       kasan_save_stack+0x1e/0x40
       __kasan_record_aux_stack+0xbe/0xd0
       call_rcu+0x99/0x740
       netlink_release+0xe6a/0x1cf0
       __sock_release+0xcd/0x280
       sock_close+0x18/0x20
       __fput+0x27c/0xa90
       task_work_run+0xdd/0x1a0
       exit_to_user_mode_prepare+0x23c/0x250
       syscall_exit_to_user_mode+0x19/0x50
       do_syscall_64+0x42/0x80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Second to last potentially related work creation:
       kasan_save_stack+0x1e/0x40
       __kasan_record_aux_stack+0xbe/0xd0
       call_rcu+0x99/0x740
       netlink_release+0xe6a/0x1cf0
       __sock_release+0xcd/0x280
       sock_close+0x18/0x20
       __fput+0x27c/0xa90
       task_work_run+0xdd/0x1a0
       exit_to_user_mode_prepare+0x23c/0x250
       syscall_exit_to_user_mode+0x19/0x50
       do_syscall_64+0x42/0x80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Fixes: d0be8347 ("Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put")
      Signed-off-by: NZhengchao Shao <shaozhengchao@huawei.com>
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      0d0e2d03
    • M
      Bluetooth: L2CAP: Fix use-after-free caused by l2cap_reassemble_sdu · 3aff8aac
      Maxim Mikityanskiy 提交于
      Fix the race condition between the following two flows that run in
      parallel:
      
      1. l2cap_reassemble_sdu -> chan->ops->recv (l2cap_sock_recv_cb) ->
         __sock_queue_rcv_skb.
      
      2. bt_sock_recvmsg -> skb_recv_datagram, skb_free_datagram.
      
      An SKB can be queued by the first flow and immediately dequeued and
      freed by the second flow, therefore the callers of l2cap_reassemble_sdu
      can't use the SKB after that function returns. However, some places
      continue accessing struct l2cap_ctrl that resides in the SKB's CB for a
      short time after l2cap_reassemble_sdu returns, leading to a
      use-after-free condition (the stack trace is below, line numbers for
      kernel 5.19.8).
      
      Fix it by keeping a local copy of struct l2cap_ctrl.
      
      BUG: KASAN: use-after-free in l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
      Read of size 1 at addr ffff88812025f2f0 by task kworker/u17:3/43169
      
      Workqueue: hci0 hci_rx_work [bluetooth]
      Call Trace:
       <TASK>
       dump_stack_lvl (lib/dump_stack.c:107 (discriminator 4))
       print_report.cold (mm/kasan/report.c:314 mm/kasan/report.c:429)
       ? l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
       kasan_report (mm/kasan/report.c:162 mm/kasan/report.c:493)
       ? l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
       l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
       l2cap_rx (net/bluetooth/l2cap_core.c:7236 net/bluetooth/l2cap_core.c:7271) bluetooth
       ret_from_fork (arch/x86/entry/entry_64.S:306)
       </TASK>
      
      Allocated by task 43169:
       kasan_save_stack (mm/kasan/common.c:39)
       __kasan_slab_alloc (mm/kasan/common.c:45 mm/kasan/common.c:436 mm/kasan/common.c:469)
       kmem_cache_alloc_node (mm/slab.h:750 mm/slub.c:3243 mm/slub.c:3293)
       __alloc_skb (net/core/skbuff.c:414)
       l2cap_recv_frag (./include/net/bluetooth/bluetooth.h:425 net/bluetooth/l2cap_core.c:8329) bluetooth
       l2cap_recv_acldata (net/bluetooth/l2cap_core.c:8442) bluetooth
       hci_rx_work (net/bluetooth/hci_core.c:3642 net/bluetooth/hci_core.c:3832) bluetooth
       process_one_work (kernel/workqueue.c:2289)
       worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2437)
       kthread (kernel/kthread.c:376)
       ret_from_fork (arch/x86/entry/entry_64.S:306)
      
      Freed by task 27920:
       kasan_save_stack (mm/kasan/common.c:39)
       kasan_set_track (mm/kasan/common.c:45)
       kasan_set_free_info (mm/kasan/generic.c:372)
       ____kasan_slab_free (mm/kasan/common.c:368 mm/kasan/common.c:328)
       slab_free_freelist_hook (mm/slub.c:1780)
       kmem_cache_free (mm/slub.c:3536 mm/slub.c:3553)
       skb_free_datagram (./include/net/sock.h:1578 ./include/net/sock.h:1639 net/core/datagram.c:323)
       bt_sock_recvmsg (net/bluetooth/af_bluetooth.c:295) bluetooth
       l2cap_sock_recvmsg (net/bluetooth/l2cap_sock.c:1212) bluetooth
       sock_read_iter (net/socket.c:1087)
       new_sync_read (./include/linux/fs.h:2052 fs/read_write.c:401)
       vfs_read (fs/read_write.c:482)
       ksys_read (fs/read_write.c:620)
       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)
      
      Link: https://lore.kernel.org/linux-bluetooth/CAKErNvoqga1WcmoR3-0875esY6TVWFQDandbVZncSiuGPBQXLA@mail.gmail.com/T/#u
      Fixes: d2a7ac5d ("Bluetooth: Add the ERTM receive state machine")
      Fixes: 4b51dae9 ("Bluetooth: Add streaming mode receive and incoming packet classifier")
      Signed-off-by: NMaxim Mikityanskiy <maxtram95@gmail.com>
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      3aff8aac
  2. 30 9月, 2022 1 次提交
  3. 20 9月, 2022 1 次提交
    • T
      Bluetooth: L2CAP: initialize delayed works at l2cap_chan_create() · 2d2cb306
      Tetsuo Handa 提交于
      syzbot is reporting cancel_delayed_work() without INIT_DELAYED_WORK() at
      l2cap_chan_del() [1], for CONF_NOT_COMPLETE flag (which meant to prevent
      l2cap_chan_del() from calling cancel_delayed_work()) is cleared by timer
      which fires before l2cap_chan_del() is called by closing file descriptor
      created by socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_L2CAP).
      
      l2cap_bredr_sig_cmd(L2CAP_CONF_REQ) and l2cap_bredr_sig_cmd(L2CAP_CONF_RSP)
      are calling l2cap_ertm_init(chan), and they call l2cap_chan_ready() (which
      clears CONF_NOT_COMPLETE flag) only when l2cap_ertm_init(chan) succeeded.
      
      l2cap_sock_init() does not call l2cap_ertm_init(chan), and it instead sets
      CONF_NOT_COMPLETE flag by calling l2cap_chan_set_defaults(). However, when
      connect() is requested, "command 0x0409 tx timeout" happens after 2 seconds
       from connect() request, and CONF_NOT_COMPLETE flag is cleared after 4
      seconds from connect() request, for l2cap_conn_start() from
      l2cap_info_timeout() callback scheduled by
      
        schedule_delayed_work(&conn->info_timer, L2CAP_INFO_TIMEOUT);
      
      in l2cap_connect() is calling l2cap_chan_ready().
      
      Fix this problem by initializing delayed works used by L2CAP_MODE_ERTM
      mode as soon as l2cap_chan_create() allocates a channel, like I did in
      commit be859723 ("Bluetooth: initialize skb_queue_head at
      l2cap_chan_create()").
      
      Link: https://syzkaller.appspot.com/bug?extid=83672956c7aa6af698b3 [1]
      Reported-by: Nsyzbot <syzbot+83672956c7aa6af698b3@syzkaller.appspotmail.com>
      Signed-off-by: NTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      2d2cb306
  4. 26 8月, 2022 2 次提交
    • L
      Bluetooth: L2CAP: Fix build errors in some archs · b840304f
      Luiz Augusto von Dentz 提交于
      This attempts to fix the follow errors:
      
      In function 'memcmp',
          inlined from 'bacmp' at ./include/net/bluetooth/bluetooth.h:347:9,
          inlined from 'l2cap_global_chan_by_psm' at
          net/bluetooth/l2cap_core.c:2003:15:
      ./include/linux/fortify-string.h:44:33: error: '__builtin_memcmp'
      specified bound 6 exceeds source size 0 [-Werror=stringop-overread]
         44 | #define __underlying_memcmp     __builtin_memcmp
            |                                 ^
      ./include/linux/fortify-string.h:420:16: note: in expansion of macro
      '__underlying_memcmp'
        420 |         return __underlying_memcmp(p, q, size);
            |                ^~~~~~~~~~~~~~~~~~~
      In function 'memcmp',
          inlined from 'bacmp' at ./include/net/bluetooth/bluetooth.h:347:9,
          inlined from 'l2cap_global_chan_by_psm' at
          net/bluetooth/l2cap_core.c:2004:15:
      ./include/linux/fortify-string.h:44:33: error: '__builtin_memcmp'
      specified bound 6 exceeds source size 0 [-Werror=stringop-overread]
         44 | #define __underlying_memcmp     __builtin_memcmp
            |                                 ^
      ./include/linux/fortify-string.h:420:16: note: in expansion of macro
      '__underlying_memcmp'
        420 |         return __underlying_memcmp(p, q, size);
            |                ^~~~~~~~~~~~~~~~~~~
      
      Fixes: 332f1795 ("Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression")
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      b840304f
    • L
      Bluetooth: L2CAP: Fix build errors in some archs · fc5ae5b4
      Luiz Augusto von Dentz 提交于
      This attempts to fix the follow errors:
      
      In function 'memcmp',
          inlined from 'bacmp' at ./include/net/bluetooth/bluetooth.h:347:9,
          inlined from 'l2cap_global_chan_by_psm' at
          net/bluetooth/l2cap_core.c:2003:15:
      ./include/linux/fortify-string.h:44:33: error: '__builtin_memcmp'
      specified bound 6 exceeds source size 0 [-Werror=stringop-overread]
         44 | #define __underlying_memcmp     __builtin_memcmp
            |                                 ^
      ./include/linux/fortify-string.h:420:16: note: in expansion of macro
      '__underlying_memcmp'
        420 |         return __underlying_memcmp(p, q, size);
            |                ^~~~~~~~~~~~~~~~~~~
      In function 'memcmp',
          inlined from 'bacmp' at ./include/net/bluetooth/bluetooth.h:347:9,
          inlined from 'l2cap_global_chan_by_psm' at
          net/bluetooth/l2cap_core.c:2004:15:
      ./include/linux/fortify-string.h:44:33: error: '__builtin_memcmp'
      specified bound 6 exceeds source size 0 [-Werror=stringop-overread]
         44 | #define __underlying_memcmp     __builtin_memcmp
            |                                 ^
      ./include/linux/fortify-string.h:420:16: note: in expansion of macro
      '__underlying_memcmp'
        420 |         return __underlying_memcmp(p, q, size);
            |                ^~~~~~~~~~~~~~~~~~~
      
      Fixes: 332f1795 ("Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression")
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      fc5ae5b4
  5. 09 8月, 2022 1 次提交
  6. 27 7月, 2022 1 次提交
    • L
      Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put · d0be8347
      Luiz Augusto von Dentz 提交于
      This fixes the following trace which is caused by hci_rx_work starting up
      *after* the final channel reference has been put() during sock_close() but
      *before* the references to the channel have been destroyed, so instead
      the code now rely on kref_get_unless_zero/l2cap_chan_hold_unless_zero to
      prevent referencing a channel that is about to be destroyed.
      
        refcount_t: increment on 0; use-after-free.
        BUG: KASAN: use-after-free in refcount_dec_and_test+0x20/0xd0
        Read of size 4 at addr ffffffc114f5bf18 by task kworker/u17:14/705
      
        CPU: 4 PID: 705 Comm: kworker/u17:14 Tainted: G S      W
        4.14.234-00003-g1fb6d0bd49a4-dirty #28
        Hardware name: Qualcomm Technologies, Inc. SM8150 V2 PM8150
        Google Inc. MSM sm8150 Flame DVT (DT)
        Workqueue: hci0 hci_rx_work
        Call trace:
         dump_backtrace+0x0/0x378
         show_stack+0x20/0x2c
         dump_stack+0x124/0x148
         print_address_description+0x80/0x2e8
         __kasan_report+0x168/0x188
         kasan_report+0x10/0x18
         __asan_load4+0x84/0x8c
         refcount_dec_and_test+0x20/0xd0
         l2cap_chan_put+0x48/0x12c
         l2cap_recv_frame+0x4770/0x6550
         l2cap_recv_acldata+0x44c/0x7a4
         hci_acldata_packet+0x100/0x188
         hci_rx_work+0x178/0x23c
         process_one_work+0x35c/0x95c
         worker_thread+0x4cc/0x960
         kthread+0x1a8/0x1c4
         ret_from_fork+0x10/0x18
      
      Cc: stable@kernel.org
      Reported-by: NLee Jones <lee.jones@linaro.org>
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Tested-by: NLee Jones <lee.jones@linaro.org>
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      d0be8347
  7. 22 7月, 2022 1 次提交
  8. 19 3月, 2022 1 次提交
  9. 04 3月, 2022 1 次提交
  10. 23 12月, 2021 1 次提交
  11. 31 8月, 2021 1 次提交
  12. 26 6月, 2021 5 次提交
  13. 06 4月, 2021 1 次提交
  14. 02 4月, 2021 2 次提交
  15. 25 3月, 2021 1 次提交
  16. 23 3月, 2021 1 次提交
  17. 22 3月, 2021 1 次提交
    • A
      Bluetooth: Set CONF_NOT_COMPLETE as l2cap_chan default · 3a9d54b1
      Archie Pusaka 提交于
      Currently l2cap_chan_set_defaults() reset chan->conf_state to zero.
      However, there is a flag CONF_NOT_COMPLETE which is set when
      creating the l2cap_chan. It is suggested that the flag should be
      cleared when l2cap_chan is ready, but when l2cap_chan_set_defaults()
      is called, l2cap_chan is not yet ready. Therefore, we must set this
      flag as the default.
      
      Example crash call trace:
      __dump_stack lib/dump_stack.c:15 [inline]
      dump_stack+0xc4/0x118 lib/dump_stack.c:56
      panic+0x1c6/0x38b kernel/panic.c:117
      __warn+0x170/0x1b9 kernel/panic.c:471
      warn_slowpath_fmt+0xc7/0xf8 kernel/panic.c:494
      debug_print_object+0x175/0x193 lib/debugobjects.c:260
      debug_object_assert_init+0x171/0x1bf lib/debugobjects.c:614
      debug_timer_assert_init kernel/time/timer.c:629 [inline]
      debug_assert_init kernel/time/timer.c:677 [inline]
      del_timer+0x7c/0x179 kernel/time/timer.c:1034
      try_to_grab_pending+0x81/0x2e5 kernel/workqueue.c:1230
      cancel_delayed_work+0x7c/0x1c4 kernel/workqueue.c:2929
      l2cap_clear_timer+0x1e/0x41 include/net/bluetooth/l2cap.h:834
      l2cap_chan_del+0x2d8/0x37e net/bluetooth/l2cap_core.c:640
      l2cap_chan_close+0x532/0x5d8 net/bluetooth/l2cap_core.c:756
      l2cap_sock_shutdown+0x806/0x969 net/bluetooth/l2cap_sock.c:1174
      l2cap_sock_release+0x64/0x14d net/bluetooth/l2cap_sock.c:1217
      __sock_release+0xda/0x217 net/socket.c:580
      sock_close+0x1b/0x1f net/socket.c:1039
      __fput+0x322/0x55c fs/file_table.c:208
      ____fput+0x17/0x19 fs/file_table.c:244
      task_work_run+0x19b/0x1d3 kernel/task_work.c:115
      exit_task_work include/linux/task_work.h:21 [inline]
      do_exit+0xe4c/0x204a kernel/exit.c:766
      do_group_exit+0x291/0x291 kernel/exit.c:891
      get_signal+0x749/0x1093 kernel/signal.c:2396
      do_signal+0xa5/0xcdb arch/x86/kernel/signal.c:737
      exit_to_usermode_loop arch/x86/entry/common.c:243 [inline]
      prepare_exit_to_usermode+0xed/0x235 arch/x86/entry/common.c:277
      syscall_return_slowpath+0x3a7/0x3b3 arch/x86/entry/common.c:348
      int_ret_from_sys_call+0x25/0xa3
      Signed-off-by: NArchie Pusaka <apusaka@chromium.org>
      Reported-by: syzbot+338f014a98367a08a114@syzkaller.appspotmail.com
      Reviewed-by: NAlain Michaud <alainm@chromium.org>
      Reviewed-by: NAbhishek Pandit-Subedi <abhishekpandit@chromium.org>
      Reviewed-by: NGuenter Roeck <groeck@chromium.org>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      3a9d54b1
  18. 16 3月, 2021 1 次提交
  19. 26 1月, 2021 2 次提交
    • B
      Bluetooth: L2CAP: Try harder to accept device not knowing options · 98d2c3e1
      Bastien Nocera 提交于
      The current implementation of L2CAP options negotiation will continue
      the negotiation when a device responds with L2CAP_CONF_UNACCEPT ("unaccepted
      options"), but not when the device replies with L2CAP_CONF_UNKNOWN ("unknown
      options").
      
      Trying to continue the negotiation without ERTM support will allow
      Bluetooth-capable XBox One controllers (notably models 1708 and 1797)
      to connect.
      
      btmon before patch:
      > ACL Data RX: Handle 256 flags 0x02 dlen 16                            #64 [hci0] 59.182702
            L2CAP: Connection Response (0x03) ident 2 len 8
              Destination CID: 64
              Source CID: 64
              Result: Connection successful (0x0000)
              Status: No further information available (0x0000)
      < ACL Data TX: Handle 256 flags 0x00 dlen 23                            #65 [hci0] 59.182744
            L2CAP: Configure Request (0x04) ident 3 len 15
              Destination CID: 64
              Flags: 0x0000
              Option: Retransmission and Flow Control (0x04) [mandatory]
                Mode: Basic (0x00)
                TX window size: 0
                Max transmit: 0
                Retransmission timeout: 0
                Monitor timeout: 0
                Maximum PDU size: 0
      > ACL Data RX: Handle 256 flags 0x02 dlen 16                            #66 [hci0] 59.183948
            L2CAP: Configure Request (0x04) ident 1 len 8
              Destination CID: 64
              Flags: 0x0000
              Option: Maximum Transmission Unit (0x01) [mandatory]
                MTU: 1480
      < ACL Data TX: Handle 256 flags 0x00 dlen 18                            #67 [hci0] 59.183994
            L2CAP: Configure Response (0x05) ident 1 len 10
              Source CID: 64
              Flags: 0x0000
              Result: Success (0x0000)
              Option: Maximum Transmission Unit (0x01) [mandatory]
                MTU: 1480
      > ACL Data RX: Handle 256 flags 0x02 dlen 15                            #69 [hci0] 59.187676
            L2CAP: Configure Response (0x05) ident 3 len 7
              Source CID: 64
              Flags: 0x0000
              Result: Failure - unknown options (0x0003)
              04                                               .
      < ACL Data TX: Handle 256 flags 0x00 dlen 12                            #70 [hci0] 59.187722
            L2CAP: Disconnection Request (0x06) ident 4 len 4
              Destination CID: 64
              Source CID: 64
      > ACL Data RX: Handle 256 flags 0x02 dlen 12                            #73 [hci0] 59.192714
            L2CAP: Disconnection Response (0x07) ident 4 len 4
              Destination CID: 64
              Source CID: 64
      
      btmon after patch:
      > ACL Data RX: Handle 256 flags 0x02 dlen 16                          #248 [hci0] 103.502970
            L2CAP: Connection Response (0x03) ident 5 len 8
              Destination CID: 65
              Source CID: 65
              Result: Connection pending (0x0001)
              Status: No further information available (0x0000)
      > ACL Data RX: Handle 256 flags 0x02 dlen 16                          #249 [hci0] 103.504184
            L2CAP: Connection Response (0x03) ident 5 len 8
              Destination CID: 65
              Source CID: 65
              Result: Connection successful (0x0000)
              Status: No further information available (0x0000)
      < ACL Data TX: Handle 256 flags 0x00 dlen 23                          #250 [hci0] 103.504398
            L2CAP: Configure Request (0x04) ident 6 len 15
              Destination CID: 65
              Flags: 0x0000
              Option: Retransmission and Flow Control (0x04) [mandatory]
                Mode: Basic (0x00)
                TX window size: 0
                Max transmit: 0
                Retransmission timeout: 0
                Monitor timeout: 0
                Maximum PDU size: 0
      > ACL Data RX: Handle 256 flags 0x02 dlen 16                          #251 [hci0] 103.505472
            L2CAP: Configure Request (0x04) ident 3 len 8
              Destination CID: 65
              Flags: 0x0000
              Option: Maximum Transmission Unit (0x01) [mandatory]
                MTU: 1480
      < ACL Data TX: Handle 256 flags 0x00 dlen 18                          #252 [hci0] 103.505689
            L2CAP: Configure Response (0x05) ident 3 len 10
              Source CID: 65
              Flags: 0x0000
              Result: Success (0x0000)
              Option: Maximum Transmission Unit (0x01) [mandatory]
                MTU: 1480
      > ACL Data RX: Handle 256 flags 0x02 dlen 15                          #254 [hci0] 103.509165
            L2CAP: Configure Response (0x05) ident 6 len 7
              Source CID: 65
              Flags: 0x0000
              Result: Failure - unknown options (0x0003)
              04                                               .
      < ACL Data TX: Handle 256 flags 0x00 dlen 12                          #255 [hci0] 103.509426
            L2CAP: Configure Request (0x04) ident 7 len 4
              Destination CID: 65
              Flags: 0x0000
      < ACL Data TX: Handle 256 flags 0x00 dlen 12                          #257 [hci0] 103.511870
            L2CAP: Connection Request (0x02) ident 8 len 4
              PSM: 1 (0x0001)
              Source CID: 66
      > ACL Data RX: Handle 256 flags 0x02 dlen 14                          #259 [hci0] 103.514121
            L2CAP: Configure Response (0x05) ident 7 len 6
              Source CID: 65
              Flags: 0x0000
              Result: Success (0x0000)
      Signed-off-by: NFlorian Dollinger <dollinger.florian@gmx.de>
      Co-developed-by: NFlorian Dollinger <dollinger.florian@gmx.de>
      Reviewed-by: NLuiz Augusto Von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      98d2c3e1
    • L
      Bluetooth: L2CAP: Fix handling fragmented length · 4d7ea8ee
      Luiz Augusto von Dentz 提交于
      Bluetooth Core Specification v5.2, Vol. 3, Part A, section 1.4, table
      1.1:
      
       'Start Fragments always either begin with the first octet of the Basic
        L2CAP header of a PDU or they have a length of zero (see [Vol 2] Part
        B, Section 6.6.2).'
      
      Apparently this was changed by the following errata:
      
      https://www.bluetooth.org/tse/errata_view.cfm?errata_id=10216Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      4d7ea8ee
  20. 07 12月, 2020 1 次提交
    • J
      Bluetooth: Fix for Bluetooth SIG test L2CAP/COS/CFD/BV-14-C · 5b8ec15d
      Jimmy Wahlberg 提交于
      This test case is meant to verify that multiple
      unknown options is included in the response.
      
      BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 3, Part A
      page 1057
      
      'On an unknown option failure (Result=0x0003),
      the option(s) that contain anoption type field that is not
      understood by the recipient of the L2CAP_CONFIGURATION_REQ
      packet shall be included in the L2CAP_CONFIGURATION_RSP
      packet unless they are hints.'
      
      Before this patch:
      
      > ACL Data RX: Handle 11 flags 0x02 dlen 24
            L2CAP: Configure Request (0x04) ident 18 len 16
              Destination CID: 64
              Flags: 0x0000
              Option: Unknown (0x10) [mandatory]
              10 00 11 02 11 00 12 02 12 00
      < ACL Data TX: Handle 11 flags 0x00 dlen 17
            L2CAP: Configure Response (0x05) ident 18 len 9
              Source CID: 64
              Flags: 0x0000
              Result: Failure - unknown options (0x0003)
              Option: Unknown (0x10) [mandatory]
              12
      
      After this patch:
      
      > ACL Data RX: Handle 11 flags 0x02 dlen 24
            L2CAP: Configure Request (0x04) ident 5 len 16
              Destination CID: 64
              Flags: 0x0000
              Option: Unknown (0x10) [mandatory]
              10 00 11 02 11 00 12 02 12 00
      < ACL Data TX: Handle 11 flags 0x00 dlen 23
            L2CAP: Configure Response (0x05) ident 5 len 15
              Source CID: 64
              Flags: 0x0000
              Result: Failure - unknown options (0x0003)
              Option: Unknown (0x10) [mandatory]
              10 11 01 11 12 01 12
      Signed-off-by: NJimmy Wahlberg <jimmywa@spotify.com>
      Reviewed-by: NLuiz Augusto Von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      Signed-off-by: NJohan Hedberg <johan.hedberg@intel.com>
      5b8ec15d
  21. 11 11月, 2020 1 次提交
  22. 26 9月, 2020 1 次提交
  23. 11 7月, 2020 1 次提交
  24. 18 6月, 2020 1 次提交
  25. 11 5月, 2020 1 次提交
  26. 26 3月, 2020 1 次提交
  27. 15 3月, 2020 1 次提交
  28. 12 3月, 2020 1 次提交
    • H
      Bluetooth: L2CAP: handle l2cap config request during open state · 96298f64
      Howard Chung 提交于
      According to Core Spec Version 5.2 | Vol 3, Part A 6.1.5,
      the incoming L2CAP_ConfigReq should be handled during
      OPEN state.
      
      The section below shows the btmon trace when running
      L2CAP/COS/CFD/BV-12-C before and after this change.
      
      === Before ===
      ...
      > ACL Data RX: Handle 256 flags 0x02 dlen 12                #22
            L2CAP: Connection Request (0x02) ident 2 len 4
              PSM: 1 (0x0001)
              Source CID: 65
      < ACL Data TX: Handle 256 flags 0x00 dlen 16                #23
            L2CAP: Connection Response (0x03) ident 2 len 8
              Destination CID: 64
              Source CID: 65
              Result: Connection successful (0x0000)
              Status: No further information available (0x0000)
      < ACL Data TX: Handle 256 flags 0x00 dlen 12                #24
            L2CAP: Configure Request (0x04) ident 2 len 4
              Destination CID: 65
              Flags: 0x0000
      > HCI Event: Number of Completed Packets (0x13) plen 5      #25
              Num handles: 1
              Handle: 256
              Count: 1
      > HCI Event: Number of Completed Packets (0x13) plen 5      #26
              Num handles: 1
              Handle: 256
              Count: 1
      > ACL Data RX: Handle 256 flags 0x02 dlen 16                #27
            L2CAP: Configure Request (0x04) ident 3 len 8
              Destination CID: 64
              Flags: 0x0000
              Option: Unknown (0x10) [hint]
              01 00                                            ..
      < ACL Data TX: Handle 256 flags 0x00 dlen 18                #28
            L2CAP: Configure Response (0x05) ident 3 len 10
              Source CID: 65
              Flags: 0x0000
              Result: Success (0x0000)
              Option: Maximum Transmission Unit (0x01) [mandatory]
                MTU: 672
      > HCI Event: Number of Completed Packets (0x13) plen 5      #29
              Num handles: 1
              Handle: 256
              Count: 1
      > ACL Data RX: Handle 256 flags 0x02 dlen 14                #30
            L2CAP: Configure Response (0x05) ident 2 len 6
              Source CID: 64
              Flags: 0x0000
              Result: Success (0x0000)
      > ACL Data RX: Handle 256 flags 0x02 dlen 20                #31
            L2CAP: Configure Request (0x04) ident 3 len 12
              Destination CID: 64
              Flags: 0x0000
              Option: Unknown (0x10) [hint]
              01 00 91 02 11 11                                ......
      < ACL Data TX: Handle 256 flags 0x00 dlen 14                #32
            L2CAP: Command Reject (0x01) ident 3 len 6
              Reason: Invalid CID in request (0x0002)
              Destination CID: 64
              Source CID: 65
      > HCI Event: Number of Completed Packets (0x13) plen 5      #33
              Num handles: 1
              Handle: 256
              Count: 1
      ...
      === After ===
      ...
      > ACL Data RX: Handle 256 flags 0x02 dlen 12               #22
            L2CAP: Connection Request (0x02) ident 2 len 4
              PSM: 1 (0x0001)
              Source CID: 65
      < ACL Data TX: Handle 256 flags 0x00 dlen 16               #23
            L2CAP: Connection Response (0x03) ident 2 len 8
              Destination CID: 64
              Source CID: 65
              Result: Connection successful (0x0000)
              Status: No further information available (0x0000)
      < ACL Data TX: Handle 256 flags 0x00 dlen 12               #24
            L2CAP: Configure Request (0x04) ident 2 len 4
              Destination CID: 65
              Flags: 0x0000
      > HCI Event: Number of Completed Packets (0x13) plen 5     #25
              Num handles: 1
              Handle: 256
              Count: 1
      > HCI Event: Number of Completed Packets (0x13) plen 5     #26
              Num handles: 1
              Handle: 256
              Count: 1
      > ACL Data RX: Handle 256 flags 0x02 dlen 16               #27
            L2CAP: Configure Request (0x04) ident 3 len 8
              Destination CID: 64
              Flags: 0x0000
              Option: Unknown (0x10) [hint]
              01 00                                            ..
      < ACL Data TX: Handle 256 flags 0x00 dlen 18               #28
            L2CAP: Configure Response (0x05) ident 3 len 10
              Source CID: 65
              Flags: 0x0000
              Result: Success (0x0000)
              Option: Maximum Transmission Unit (0x01) [mandatory]
                MTU: 672
      > HCI Event: Number of Completed Packets (0x13) plen 5     #29
              Num handles: 1
              Handle: 256
              Count: 1
      > ACL Data RX: Handle 256 flags 0x02 dlen 14               #30
            L2CAP: Configure Response (0x05) ident 2 len 6
              Source CID: 64
              Flags: 0x0000
              Result: Success (0x0000)
      > ACL Data RX: Handle 256 flags 0x02 dlen 20               #31
            L2CAP: Configure Request (0x04) ident 3 len 12
              Destination CID: 64
              Flags: 0x0000
              Option: Unknown (0x10) [hint]
              01 00 91 02 11 11                                .....
      < ACL Data TX: Handle 256 flags 0x00 dlen 18               #32
            L2CAP: Configure Response (0x05) ident 3 len 10
              Source CID: 65
              Flags: 0x0000
              Result: Success (0x0000)
              Option: Maximum Transmission Unit (0x01) [mandatory]
                MTU: 672
      < ACL Data TX: Handle 256 flags 0x00 dlen 12               #33
            L2CAP: Configure Request (0x04) ident 3 len 4
              Destination CID: 65
              Flags: 0x0000
      > HCI Event: Number of Completed Packets (0x13) plen 5     #34
              Num handles: 1
              Handle: 256
              Count: 1
      > HCI Event: Number of Completed Packets (0x13) plen 5     #35
              Num handles: 1
              Handle: 256
              Count: 1
      ...
      Signed-off-by: NHoward Chung <howardchung@google.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      96298f64