An error occurred fetching the project authors.
  1. 19 May, 2023 4 commits
    • Ruihan Li's avatar
      Bluetooth: Unlink CISes when LE disconnects in hci_conn_del · a2904d28
      Ruihan Li authored
      Currently, hci_conn_del calls hci_conn_unlink for BR/EDR, (e)SCO, and
      CIS connections, i.e., everything except LE connections. However, if
      (e)SCO connections are unlinked when BR/EDR disconnects, CIS connections
      should also be unlinked when LE disconnects.
      
      In terms of disconnection behavior, CIS and (e)SCO connections are not
      too different. One peculiarity of CIS is that when CIS connections are
      disconnected, the CIS handle isn't deleted, as per [BLUETOOTH CORE
      SPECIFICATION Version 5.4 | Vol 4, Part E] 7.1.6 Disconnect command:
      
              All SCO, eSCO, and CIS connections on a physical link should be
              disconnected before the ACL connection on the same physical
              connection is disconnected. If it does not, they will be
              implicitly disconnected as part of the ACL disconnection.
              ...
              Note: As specified in Section 7.7.5, on the Central, the handle
              for a CIS remains valid even after disconnection and, therefore,
              the Host can recreate a disconnected CIS at a later point in
              time using the same connection handle.
      
      Since hci_conn_link invokes both hci_conn_get and hci_conn_hold,
      hci_conn_unlink should perform both hci_conn_put and hci_conn_drop as
      well. However, currently it performs only hci_conn_put.
      
      This patch makes hci_conn_unlink call hci_conn_drop as well, which
      simplifies the logic in hci_conn_del a bit and may benefit future users
      of hci_conn_unlink. But it is noted that this change additionally
      implies that hci_conn_unlink can queue disc_work on conn itself, with
      the following call stack:
      
              hci_conn_unlink(conn)  [conn->parent == NULL]
                      -> hci_conn_unlink(child)  [child->parent == conn]
                              -> hci_conn_drop(child->parent)
                                      -> queue_delayed_work(&conn->disc_work)
      
      Queued disc_work after hci_conn_del can be spurious, so during the
      process of hci_conn_del, it is necessary to make the call to
      cancel_delayed_work(&conn->disc_work) after invoking hci_conn_unlink.
      Signed-off-by: default avatarRuihan Li <lrh2000@pku.edu.cn>
      Co-developed-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      a2904d28
    • Ruihan Li's avatar
      Bluetooth: Fix UAF in hci_conn_hash_flush again · a2ac591c
      Ruihan Li authored
      Commit 06149746 ("Bluetooth: hci_conn: Add support for linking
      multiple hcon") reintroduced a previously fixed bug [1] ("KASAN:
      slab-use-after-free Read in hci_conn_hash_flush"). This bug was
      originally fixed by commit 5dc7d23e ("Bluetooth: hci_conn: Fix
      possible UAF").
      
      The hci_conn_unlink function was added to avoid invalidating the link
      traversal caused by successive hci_conn_del operations releasing extra
      connections. However, currently hci_conn_unlink itself also releases
      extra connections, resulted in the reintroduced bug.
      
      This patch follows a more robust solution for cleaning up all
      connections, by repeatedly removing the first connection until there are
      none left. This approach does not rely on the inner workings of
      hci_conn_del and ensures proper cleanup of all connections.
      
      Meanwhile, we need to make sure that hci_conn_del never fails. Indeed it
      doesn't, as it now always returns zero. To make this a bit clearer, this
      patch also changes its return type to void.
      
      Reported-by: syzbot+8bb72f86fc823817bc5d@syzkaller.appspotmail.com
      Closes: https://lore.kernel.org/linux-bluetooth/000000000000aa920505f60d25ad@google.com/
      Fixes: 06149746 ("Bluetooth: hci_conn: Add support for linking multiple hcon")
      Signed-off-by: default avatarRuihan Li <lrh2000@pku.edu.cn>
      Co-developed-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      a2ac591c
    • Ruihan Li's avatar
      Bluetooth: Refcnt drop must be placed last in hci_conn_unlink · 2910431a
      Ruihan Li authored
      If hci_conn_put(conn->parent) reduces conn->parent's reference count to
      zero, it can immediately deallocate conn->parent. At the same time,
      conn->link->list has its head in conn->parent, causing use-after-free
      problems in the latter list_del_rcu(&conn->link->list).
      
      This problem can be easily solved by reordering the two operations,
      i.e., first performing the list removal with list_del_rcu and then
      decreasing the refcnt with hci_conn_put.
      Reported-by: default avatarLuiz Augusto von Dentz <luiz.dentz@gmail.com>
      Closes: https://lore.kernel.org/linux-bluetooth/CABBYNZ+1kce8_RJrLNOXd_8=Mdpb=2bx4Nto-hFORk=qiOkoCg@mail.gmail.com/
      Fixes: 06149746 ("Bluetooth: hci_conn: Add support for linking multiple hcon")
      Signed-off-by: default avatarRuihan Li <lrh2000@pku.edu.cn>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      2910431a
    • Ruihan Li's avatar
      Bluetooth: Fix potential double free caused by hci_conn_unlink · ca1fd42e
      Ruihan Li authored
      The hci_conn_unlink function is being called by hci_conn_del, which
      means it should not call hci_conn_del with the input parameter conn
      again. If it does, conn may have already been released when
      hci_conn_unlink returns, leading to potential UAF and double-free
      issues.
      
      This patch resolves the problem by modifying hci_conn_unlink to release
      only conn's child links when necessary, but never release conn itself.
      
      Reported-by: syzbot+690b90b14f14f43f4688@syzkaller.appspotmail.com
      Closes: https://lore.kernel.org/linux-bluetooth/000000000000484a8205faafe216@google.com/
      Fixes: 06149746 ("Bluetooth: hci_conn: Add support for linking multiple hcon")
      Signed-off-by: default avatarRuihan Li <lrh2000@pku.edu.cn>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Reported-by: syzbot+690b90b14f14f43f4688@syzkaller.appspotmail.com
      Reported-by: default avatarLuiz Augusto von Dentz <luiz.dentz@gmail.com>
      Reported-by: syzbot+8bb72f86fc823817bc5d@syzkaller.appspotmail.com
      ca1fd42e
  2. 24 Apr, 2023 5 commits
  3. 10 Apr, 2023 3 commits
  4. 09 Feb, 2023 3 commits
    • Archie Pusaka's avatar
      Bluetooth: Make sure LE create conn cancel is sent when timeout · 5cd39700
      Archie Pusaka authored
      When sending LE create conn command, we set a timer with a duration of
      HCI_LE_CONN_TIMEOUT before timing out and calling
      create_le_conn_complete. Additionally, when receiving the command
      complete, we also set a timer with the same duration to call
      le_conn_timeout.
      
      Usually the latter will be triggered first, which then sends a LE
      create conn cancel command. However, due to the nature of racing, it
      is possible for the former to be called first, thereby calling the
      chain hci_conn_failed -> hci_conn_del -> cancel_delayed_work, thereby
      preventing LE create conn cancel to be sent. In this situation, the
      controller will be stuck in trying the LE connection.
      
      This patch flushes le_conn_timeout on create_le_conn_complete to make
      sure we always send LE create connection cancel, if necessary.
      Signed-off-by: default avatarArchie Pusaka <apusaka@chromium.org>
      Reviewed-by: default avatarYing Hsu <yinghsu@chromium.org>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      5cd39700
    • Archie Pusaka's avatar
      Bluetooth: Free potentially unfreed SCO connection · 0f00cd32
      Archie Pusaka authored
      It is possible to initiate a SCO connection while deleting the
      corresponding ACL connection, e.g. in below scenario:
      
      (1) < hci setup sync connect command
      (2) > hci disconn complete event (for the acl connection)
      (3) > hci command complete event (for(1), failure)
      
      When it happens, hci_cs_setup_sync_conn won't be able to obtain the
      reference to the SCO connection, so it will be stuck and potentially
      hinder subsequent connections to the same device.
      
      This patch prevents that by also deleting the SCO connection if it is
      still not established when the corresponding ACL connection is deleted.
      Signed-off-by: default avatarArchie Pusaka <apusaka@chromium.org>
      Reviewed-by: default avatarYing Hsu <yinghsu@chromium.org>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      0f00cd32
    • Kees Cook's avatar
      Bluetooth: hci_conn: Refactor hci_bind_bis() since it always succeeds · a00a29b0
      Kees Cook authored
      The compiler thinks "conn" might be NULL after a call to hci_bind_bis(),
      which cannot happen. Avoid any confusion by just making it not return a
      value since it cannot fail. Fixes the warnings seen with GCC 13:
      
      In function 'arch_atomic_dec_and_test',
          inlined from 'atomic_dec_and_test' at ../include/linux/atomic/atomic-instrumented.h:576:9,
          inlined from 'hci_conn_drop' at ../include/net/bluetooth/hci_core.h:1391:6,
          inlined from 'hci_connect_bis' at ../net/bluetooth/hci_conn.c:2124:3:
      ../arch/x86/include/asm/rmwcc.h:37:9: warning: array subscript 0 is outside array bounds of 'atomic_t[0]' [-Warray-bounds=]
         37 |         asm volatile (fullop CC_SET(cc) \
            |         ^~~
      ...
      In function 'hci_connect_bis':
      cc1: note: source object is likely at address zero
      
      Fixes: eca0ae4a ("Bluetooth: Add initial implementation of BIS connections")
      Cc: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Cc: Marcel Holtmann <marcel@holtmann.org>
      Cc: Johan Hedberg <johan.hedberg@gmail.com>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: Paolo Abeni <pabeni@redhat.com>
      Cc: linux-bluetooth@vger.kernel.org
      Cc: netdev@vger.kernel.org
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      a00a29b0
  5. 17 Jan, 2023 1 commit
  6. 12 Dec, 2022 4 commits
  7. 02 Nov, 2022 2 commits
  8. 31 Aug, 2022 1 commit
  9. 25 Aug, 2022 1 commit
  10. 09 Aug, 2022 1 commit
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_conn: Fix updating ISO QoS PHY · 10b9adb5
      Luiz Augusto von Dentz authored
      BT_ISO_QOS has different semantics when it comes to QoS PHY as it uses
      0x00 to disable a direction but that value is invalid over HCI and
      sockets using DEFER_SETUP to connect may attempt to use hci_bind_cis
      multiple times in order to detect if the parameters have changed, so to
      fix the code will now just mirror the PHY for the parameters of
      HCI_OP_LE_SET_CIG_PARAMS and will not update the PHY of the socket
      leaving it disabled.
      
      Fixes: 26afbd82 ("Bluetooth: Add initial implementation of CIS connections")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      10b9adb5
  11. 23 Jul, 2022 2 commits
    • Luiz Augusto von Dentz's avatar
      Bluetooth: Add initial implementation of BIS connections · eca0ae4a
      Luiz Augusto von Dentz authored
      This adds initial support for BIS/BIG which includes:
      
      == Broadcaster role: Setup a periodic advertising and create a BIG ==
      
      > tools/isotest -s 00:00:00:00:00:00
      isotest[63]: Connected [00:00:00:00:00:00]
      isotest[63]: QoS BIG 0x00 BIS 0x00 Packing 0x00 Framing 0x00]
      isotest[63]: Output QoS [Interval 10000 us Latency 10 ms SDU 40 PHY 0x02
      RTN 2]
      isotest[63]: Sending ...
      isotest[63]: Number of packets: 1
      isotest[63]: Socket jitter buffer: 80 buffer
      < HCI Command: LE Set Perio.. (0x08|0x003e) plen 7
      ...
      > HCI Event: Command Complete (0x0e) plen 4
            LE Set Periodic Advertising Parameters (0x08|0x003e) ncmd 1
              Status: Success (0x00)
      < HCI Command: LE Set Perio.. (0x08|0x003f) plen 7
      ...
      > HCI Event: Command Complete (0x0e) plen 4
            LE Set Periodic Advertising Data (0x08|0x003f) ncmd 1
              Status: Success (0x00)
      < HCI Command: LE Set Perio.. (0x08|0x0040) plen 2
      ...
      > HCI Event: Command Complete (0x0e) plen 4
            LE Set Periodic Advertising Enable (0x08|0x0040) ncmd 1
              Status: Success (0x00)
      < HCI Command: LE Create B.. (0x08|0x0068) plen 31
      ...
      > HCI Event: Command Status (0x0f) plen 4
            LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
              Status: Success (0x00)
      > HCI Event: LE Meta Event (0x3e) plen 21
            LE Broadcast Isochronous Group Complete (0x1b)
            ...
      
      == Broadcast Receiver role: Create a PA Sync and BIG Sync ==
      
      > tools/isotest -i hci1 -d 00:AA:01:00:00:00
      isotest[66]: Waiting for connection 00:AA:01:00:00:00...
      < HCI Command: LE Periodic Advert.. (0x08|0x0044) plen 14
      ...
      > HCI Event: Command Status (0x0f) plen 4
            LE Periodic Advertising Create Sync (0x08|0x0044) ncmd 1
              Status: Success (0x00)
      < HCI Command: LE Set Extended Sca.. (0x08|0x0041) plen 8
      ...
      > HCI Event: Command Complete (0x0e) plen 4
            LE Set Extended Scan Parameters (0x08|0x0041) ncmd 1
              Status: Success (0x00)
      < HCI Command: LE Set Extended Sca.. (0x08|0x0042) plen 6
      ...
      > HCI Event: Command Complete (0x0e) plen 4
            LE Set Extended Scan Enable (0x08|0x0042) ncmd 1
              Status: Success (0x00)
      > HCI Event: LE Meta Event (0x3e) plen 29
            LE Extended Advertising Report (0x0d)
            ...
      > HCI Event: LE Meta Event (0x3e) plen 16
            LE Periodic Advertising Sync Established (0x0e)
            ...
      < HCI Command: LE Broadcast Isoch.. (0x08|0x006b) plen 25
      ...
      > HCI Event: Command Status (0x0f) plen 4
            LE Broadcast Isochronous Group Create Sync (0x08|0x006b) ncmd 1
              Status: Success (0x00)
      > HCI Event: LE Meta Event (0x3e) plen 17
            LE Broadcast Isochronous Group Sync Estabilished (0x1d)
            ...
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      eca0ae4a
    • Luiz Augusto von Dentz's avatar
      Bluetooth: Add initial implementation of CIS connections · 26afbd82
      Luiz Augusto von Dentz authored
      This adds the initial implementation of CIS connections and introduces
      the ISO packets/links.
      
      == Central: Set CIG Parameters, create a CIS and Setup Data Path ==
      
      > tools/isotest -s <address>
      
      < HCI Command: LE Extended Create... (0x08|0x0043) plen 26
      ...
      > HCI Event: Command Status (0x0f) plen 4
            LE Extended Create Connection (0x08|0x0043) ncmd 1
              Status: Success (0x00)
      > HCI Event: LE Meta Event (0x3e) plen 31
            LE Enhanced Connection Complete (0x0a)
            ...
      < HCI Command: LE Create Connected... (0x08|0x0064) plen 5
      ...
      > HCI Event: Command Status (0x0f) plen 4
            LE Create Connected Isochronous Stream (0x08|0x0064) ncmd 1
              Status: Success (0x00)
      > HCI Event: LE Meta Event (0x3e) plen 29
            LE Connected Isochronous Stream Established (0x19)
            ...
      < HCI Command: LE Setup Isochronou.. (0x08|0x006e) plen 13
      ...
      > HCI Event: Command Complete (0x0e) plen 6
            LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
              Status: Success (0x00)
              Handle: 257
      < HCI Command: LE Setup Isochronou.. (0x08|0x006e) plen 13
      ...
      > HCI Event: Command Complete (0x0e) plen 6
            LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
              Status: Success (0x00)
              Handle: 257
      
      == Peripheral: Accept CIS and Setup Data Path ==
      
      > tools/isotest -d
      
       HCI Event: LE Meta Event (0x3e) plen 7
            LE Connected Isochronous Stream Request (0x1a)
      ...
      < HCI Command: LE Accept Co.. (0x08|0x0066) plen 2
      ...
      > HCI Event: LE Meta Event (0x3e) plen 29
            LE Connected Isochronous Stream Established (0x19)
      ...
      < HCI Command: LE Setup Is.. (0x08|0x006e) plen 13
      ...
      > HCI Event: Command Complete (0x0e) plen 6
            LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
              Status: Success (0x00)
              Handle: 257
      < HCI Command: LE Setup Is.. (0x08|0x006e) plen 13
      ...
      > HCI Event: Command Complete (0x0e) plen 6
            LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
              Status: Success (0x00)
              Handle: 257
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      26afbd82
  12. 22 Jul, 2022 2 commits
  13. 23 May, 2022 1 commit
  14. 13 May, 2022 1 commit
  15. 26 Apr, 2022 1 commit
  16. 18 Mar, 2022 1 commit
  17. 25 Jan, 2022 1 commit
  18. 22 Dec, 2021 1 commit
  19. 29 Oct, 2021 3 commits
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Rework hci_suspend_notifier · 182ee45d
      Luiz Augusto von Dentz authored
      This makes hci_suspend_notifier use the hci_*_sync which can be
      executed synchronously which is allowed in the suspend_notifier and
      simplifies a lot of the handling since the status of each command can
      be checked inline so no other work need to be scheduled thus can be
      performed without using of a state machine.
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
      182ee45d
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Convert MGMT_OP_START_DISCOVERY · abfeea47
      Luiz Augusto von Dentz authored
      This make use of hci_cmd_sync_queue for MGMT_OP_START_DISCOVERY,
      MGMT_OP_START_SERVICE_DISCOVERY and MGMT_OP_STOP_DISCOVERY to use
      hci_cmd_sync_queue so they no longer depend on hdev->discov_update work
      to send any commands.
      
      Tested with:
      
      tools/mgmt-tester -s "Start Discovery"
      
      Test Summary
      ------------
      Start Discovery - Not powered 1                      Passed
      Start Discovery - Invalid parameters 1               Passed
      Start Discovery - Not supported 1                    Passed
      Start Discovery - Success 1                          Passed
      Start Discovery - Success 2                          Passed
      Start Discovery - Power Off 1                        Passed
      Start Discovery BREDR LE - (Ext Scan Enable)         Passed
      Start Discovery LE - (Ext Scan Enable)               Passed
      Start Discovery LE - (Ext Scan Param)                Passed
      Start Discovery - (2m, Scan Param)                   Passed
      Start Discovery - (coded, Scan Param)                Passed
      Start Discovery - (1m, 2m, coded, Scan Param)        Passed
      LL Privacy - Start Discovery 1 (Disable RL)          Passed
      LL Privacy - Start Discovery 2 (Disable RL)          Passed
      Total: 14, Passed: 14 (100.0%), Failed: 0, Not Run: 0
      
      tools/mgmt-tester -s "Start Service"
      
      Test Summary
      ------------
      Start Service Discovery - Not powered 1              Passed
      Start Service Discovery - Invalid parameters 1       Passed
      Start Service Discovery - Not supported 1            Passed
      Start Service Discovery - Success 1                  Passed
      Start Service Discovery - Success 2                  Passed
      Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0
      
      tools/mgmt-tester -s "Stop Discovery"
      
      Test Summary
      ------------
      Stop Discovery - Success 1                           Passed
      Stop Discovery - BR/EDR (Inquiry) Success 1          Passed
      Stop Discovery - Rejected 1                          Passed
      Stop Discovery - Invalid parameters 1                Passed
      Stop Discovery - (Ext Scan Disable)                  Passed
      Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
      abfeea47
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_sync: Rework background scan · 5bee2fd6
      Luiz Augusto von Dentz authored
      This replaces the use of hci_update_background_scan with
      hci_update_passive_scan which runs from cmd_work_sync and deal properly
      with resolving list when LL privacy is enabled.
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
      5bee2fd6
  20. 07 Sep, 2021 2 commits