Commit Graph

868 Commits

Author SHA1 Message Date
CKI Backport Bot 9a5a431f40 Bluetooth: hci_event: Fix using rcu_read_(un)lock while iterating
JIRA: https://issues.redhat.com/browse/RHEL-72255
CVE: CVE-2024-56654

commit 581dd2dc168fe0ed2a7a5534a724f0d3751c93ae
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Wed Dec 4 11:40:59 2024 -0500

    Bluetooth: hci_event: Fix using rcu_read_(un)lock while iterating

    The usage of rcu_read_(un)lock while inside list_for_each_entry_rcu is
    not safe since for the most part entries fetched this way shall be
    treated as rcu_dereference:

            Note that the value returned by rcu_dereference() is valid
            only within the enclosing RCU read-side critical section [1]_.
            For example, the following is **not** legal::

                    rcu_read_lock();
                    p = rcu_dereference(head.next);
                    rcu_read_unlock();
                    x = p->address; /* BUG!!! */
                    rcu_read_lock();
                    y = p->data;    /* BUG!!! */
                    rcu_read_unlock();

    Fixes: a0bfde167b50 ("Bluetooth: ISO: Add support for connecting multiple BISes")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
2025-01-06 09:44:24 +00:00
Bastien Nocera f611f1492b Bluetooth: hci_event: Align BR/EDR JUST_WORKS paring with LE
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit b25e11f978b63cb7857890edb3a698599cddb10e
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Thu Sep 12 12:17:00 2024 -0400

    Bluetooth: hci_event: Align BR/EDR JUST_WORKS paring with LE

    This aligned BR/EDR JUST_WORKS method with LE which since 92516cd97f
    ("Bluetooth: Always request for user confirmation for Just Works")
    always request user confirmation with confirm_hint set since the
    likes of bluetoothd have dedicated policy around JUST_WORKS method
    (e.g. main.conf:JustWorksRepairing).

    CVE: CVE-2024-8805
    Cc: stable@vger.kernel.org
    Fixes: ba15a58b17 ("Bluetooth: Fix SSP acceptor just-works confirmation without MITM")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
    Tested-by: Kiran K <kiran.k@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:22 +01:00
Bastien Nocera 12ff68ea20 Bluetooth: HCI: Invert LE State quirk to be opt-out rather then opt-in
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit aae6b81260fd9a7224f7eb4fc440d625852245bb
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Mon Aug 12 10:43:48 2024 -0400

    Bluetooth: HCI: Invert LE State quirk to be opt-out rather then opt-in

    This inverts the LE State quirk so by default we assume the controllers
    would report valid states rather than invalid which is how quirks
    normally behave, also this would result in HCI command failing it the LE
    States are really broken thus exposing the controllers that are really
    broken in this respect.

    Link: https://github.com/bluez/bluez/issues/584
    Fixes: 220915857e ("Bluetooth: Adding driver and quirk defs for multi-role LE")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:18 +01:00
Bastien Nocera 9340866c5f Bluetooth: hci_event: Fix setting DISCOVERY_FINDING for passive scanning
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit df3d6a3e01fd82cb74b6bb309f7be71e728a3448
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Thu Jul 25 18:28:08 2024 -0400

    Bluetooth: hci_event: Fix setting DISCOVERY_FINDING for passive scanning

    DISCOVERY_FINDING shall only be set for active scanning as passive
    scanning is not meant to generate MGMT Device Found events causing
    discovering state to go out of sync since userspace would believe it
    is discovering when in fact it is just passive scanning.

    Cc: stable@vger.kernel.org
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=219088
    Fixes: 2e2515c1ba38 ("Bluetooth: hci_event: Set DISCOVERY_FINDING on SCAN_ENABLED")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:17 +01:00
Bastien Nocera 45e241df61 Bluetooth: Remove hci_request.{c,h}
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit 936daee9cf08c5e58c9a0fe687f52adb2d80e87d
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Mon Jul 1 17:10:41 2024 -0400

    Bluetooth: Remove hci_request.{c,h}

    This removes hci_request.{c,h} since it shall no longer be used.

    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:14 +01:00
Bastien Nocera e39acfc715 Bluetooth: hci_event: Set QoS encryption from BIGInfo report
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit 5a820b13db3988122080f8de2920721f770c37a0
Author: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Date:   Mon Jun 17 11:52:06 2024 +0300

    Bluetooth: hci_event: Set QoS encryption from BIGInfo report

    On a Broadcast Sink, after synchronizing to the PA transimitted by a
    Broadcast Source, the BIGInfo advertising reports emitted by the
    Controller hold the encryption field, which indicates whether the
    Broadcast Source is transmitting encrypted streams.

    This updates the PA sync hcon QoS with the encryption value reported
    in the BIGInfo report, so that this information is accurate if the
    userspace tries to access the QoS struct via getsockopt.

    Fixes: 1d11d70d1f6b ("Bluetooth: ISO: Pass BIG encryption info through QoS")
    Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:12 +01:00
Bastien Nocera 86d80141c6 Bluetooth: hci_event: Fix setting of unicast qos interval
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit ac65ecccae802417ce42e857defacad60e4b8329
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Thu Jun 6 12:04:30 2024 -0400

    Bluetooth: hci_event: Fix setting of unicast qos interval

    qos->ucast interval reffers to the SDU interval, and should not
    be set to the interval value reported by the LE CIS Established
    event since the latter reffers to the ISO interval. These two
    interval are not the same thing:

    BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part G

    Isochronous interval:
    The time between two consecutive BIS or CIS events (designated
    ISO_Interval in the Link Layer)

    SDU interval:
    The nominal time between two consecutive SDUs that are sent or
    received by the upper layer.

    So this instead uses the following formula from the spec to calculate
    the resulting SDU interface:

    BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 6, Part G
    page 3075:

    Transport_Latency_C_To_P = CIG_Sync_Delay + (FT_C_To_P) ×
    ISO_Interval + SDU_Interval_C_To_P
    Transport_Latency_P_To_C = CIG_Sync_Delay + (FT_P_To_C) ×
    ISO_Interval + SDU_Interval_P_To_C

    Link: https://github.com/bluez/bluez/issues/823
    Fixes: 2be22f1941d5 ("Bluetooth: hci_event: Fix parsing of CIS Established Event")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:08 +01:00
Bastien Nocera 8adab174e4 Bluetooth: Add quirk to ignore reserved PHY bits in LE Extended Adv Report
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit ed2a2ef16a6b9197a0e452308bf6acee6e01f709
Author: Sven Peter <sven@svenpeter.dev>
Date:   Wed May 15 18:02:58 2024 +0000

    Bluetooth: Add quirk to ignore reserved PHY bits in LE Extended Adv Report

    Some Broadcom controllers found on Apple Silicon machines abuse the
    reserved bits inside the PHY fields of LE Extended Advertising Report
    events for additional flags. Add a quirk to drop these and correctly
    extract the Primary/Secondary_PHY field.

    The following excerpt from a btmon trace shows a report received with
    "Reserved" for "Primary PHY" on a 4388 controller:

    > HCI Event: LE Meta Event (0x3e) plen 26
          LE Extended Advertising Report (0x0d)
            Num reports: 1
            Entry 0
              Event type: 0x2515
                Props: 0x0015
                  Connectable
                  Directed
                  Use legacy advertising PDUs
                Data status: Complete
                Reserved (0x2500)
             Legacy PDU Type: Reserved (0x2515)
              Address type: Random (0x01)
              Address: 00:00:00:00:00:00 (Static)
              Primary PHY: Reserved
              Secondary PHY: No packets
              SID: no ADI field (0xff)
              TX power: 127 dBm
              RSSI: -60 dBm (0xc4)
              Periodic advertising interval: 0.00 msec (0x0000)
              Direct address type: Public (0x00)
              Direct address: 00:00:00:00:00:00 (Apple, Inc.)
              Data length: 0x00

    Cc: stable@vger.kernel.org
    Fixes: 2e7ed5f5e69b ("Bluetooth: hci_sync: Use advertised PHYs on hci_le_ext_create_conn_sync")
    Reported-by: Janne Grunau <j@jannau.net>
    Closes: https://lore.kernel.org/all/Zjz0atzRhFykROM9@robin
    Tested-by: Janne Grunau <j@jannau.net>
    Signed-off-by: Sven Peter <sven@svenpeter.dev>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:08 +01:00
Bastien Nocera fc0efe479b Bluetooth: hci_conn, hci_sync: Use __counted_by() to avoid -Wfamnae warnings
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit c4585edf708edb5277a3cc4b8581ccb833f3307d
Author: Gustavo A. R. Silva <gustavoars@kernel.org>
Date:   Fri Apr 26 16:52:46 2024 -0600

    Bluetooth: hci_conn, hci_sync: Use __counted_by() to avoid -Wfamnae warnings

    Prepare for the coming implementation by GCC and Clang of the
    __counted_by attribute. Flexible array members annotated with
    __counted_by can have their accesses bounds-checked at run-time
    via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE
    (for strcpy/memcpy-family functions).

    Also, -Wflex-array-member-not-at-end is coming in GCC-14, and we are
    getting ready to enable it globally.

    So, use the `DEFINE_FLEX()` helper for multiple on-stack definitions
    of a flexible structure where the size of the flexible-array member
    is known at compile-time, and refactor the rest of the code,
    accordingly.

    Notice that, due to the use of `__counted_by()` in `struct
    hci_cp_le_create_cis`, the for loop in function `hci_cs_le_create_cis()`
    had to be modified. Once the index `i`, through which `cp->cis[i]` is
    accessed, falls in the interval [0, cp->num_cis), `cp->num_cis` cannot
    be decremented all the way down to zero while accessing `cp->cis[]`:

    net/bluetooth/hci_event.c:4310:
    4310    for (i = 0; cp->num_cis; cp->num_cis--, i++) {
                    ...
    4314            handle = __le16_to_cpu(cp->cis[i].cis_handle);

    otherwise, only half (one iteration before `cp->num_cis == i`) or half
    plus one (one iteration before `cp->num_cis < i`) of the items in the
    array will be accessed before running into an out-of-bounds issue. So,
    in order to avoid this, set `cp->num_cis` to zero just after the for
    loop.

    Also, make use of `aux_num_cis` variable to update `cmd->num_cis` after
    a `list_for_each_entry_rcu()` loop.

    With these changes, fix the following warnings:
    net/bluetooth/hci_sync.c:1239:56: warning: structure containing a flexible
    array member is not at the end of another structure
    [-Wflex-array-member-not-at-end]
    net/bluetooth/hci_sync.c:1415:51: warning: structure containing a flexible
    array member is not at the end of another structure
    [-Wflex-array-member-not-at-end]
    net/bluetooth/hci_sync.c:1731:51: warning: structure containing a flexible
    array member is not at the end of another structure
    [-Wflex-array-member-not-at-end]
    net/bluetooth/hci_sync.c:6497:45: warning: structure containing a flexible
    array member is not at the end of another structure
    [-Wflex-array-member-not-at-end]

    Link: https://github.com/KSPP/linux/issues/202
    Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:05 +01:00
Bastien Nocera 7660b70269 Bluetooth: hci_event: Set DISCOVERY_FINDING on SCAN_ENABLED
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit 2e2515c1ba384ae44f6bf13dd64b9a0a950798c4
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Thu Mar 28 17:40:53 2024 -0400

    Bluetooth: hci_event: Set DISCOVERY_FINDING on SCAN_ENABLED

    This makes sure that discovery state is properly synchronized otherwise
    reports may not generate MGMT DeviceFound events as it would be assumed
    that it was not initiated by a discovery session.

    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:03 +01:00
Bastien Nocera 92b33c3121 Bluetooth: hci_event: Fix sending HCI_OP_READ_ENC_KEY_SIZE
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit a9a830a676a9a93c5020f5c61236166931fa4266
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Mon Apr 15 13:41:01 2024 -0400

    Bluetooth: hci_event: Fix sending HCI_OP_READ_ENC_KEY_SIZE

    The code shall always check if HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE has
    been set before attempting to use HCI_OP_READ_ENC_KEY_SIZE.

    Fixes: c569242cd492 ("Bluetooth: hci_event: set the conn encrypted before conn establishes")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:01 +01:00
Bastien Nocera 960c66101c Bluetooth: hci_sync: Use advertised PHYs on hci_le_ext_create_conn_sync
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit 2e7ed5f5e69b6fe93dd3c6b651d041e0a7a456d1
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Fri Apr 5 16:40:33 2024 -0400

    Bluetooth: hci_sync: Use advertised PHYs on hci_le_ext_create_conn_sync

    The extended advertising reports do report the PHYs so this store then
    in hci_conn so it can be later used in hci_le_ext_create_conn_sync to
    narrow the PHYs to be scanned since the controller will also perform a
    scan having a smaller set of PHYs shall reduce the time it takes to
    find and connect peers.

    Fixes: 288c90224eec ("Bluetooth: Enable all supported LE PHY by default")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:01 +01:00
Bastien Nocera cb017c9212 Bluetooth: hci_event: set the conn encrypted before conn establishes
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit c569242cd49287d53b73a94233db40097d838535
Author: Hui Wang <hui.wang@canonical.com>
Date:   Wed Mar 27 12:30:30 2024 +0800

    Bluetooth: hci_event: set the conn encrypted before conn establishes

    We have a BT headset (Lenovo Thinkplus XT99), the pairing and
    connecting has no problem, once this headset is paired, bluez will
    remember this device and will auto re-connect it whenever the device
    is powered on. The auto re-connecting works well with Windows and
    Android, but with Linux, it always fails. Through debugging, we found
    at the rfcomm connection stage, the bluetooth stack reports
    "Connection refused - security block (0x0003)".

    For this device, the re-connecting negotiation process is different
    from other BT headsets, it sends the Link_KEY_REQUEST command before
    the CONNECT_REQUEST completes, and it doesn't send ENCRYPT_CHANGE
    command during the negotiation. When the device sends the "connect
    complete" to hci, the ev->encr_mode is 1.

    So here in the conn_complete_evt(), if ev->encr_mode is 1, link type
    is ACL and HCI_CONN_ENCRYPT is not set, we set HCI_CONN_ENCRYPT to
    this conn, and update conn->enc_key_size accordingly.

    After this change, this BT headset could re-connect with Linux
    successfully. This is the btmon log after applying the patch, after
    receiving the "Connect Complete" with "Encryption: Enabled", will send
    the command to read encryption key size:
    > HCI Event: Connect Request (0x04) plen 10
            Address: 8C:3C:AA:D8:11:67 (OUI 8C-3C-AA)
            Class: 0x240404
              Major class: Audio/Video (headset, speaker, stereo, video, vcr)
              Minor class: Wearable Headset Device
              Rendering (Printing, Speaker)
              Audio (Speaker, Microphone, Headset)
            Link type: ACL (0x01)
    ...
    > HCI Event: Link Key Request (0x17) plen 6
            Address: 8C:3C:AA:D8:11:67 (OUI 8C-3C-AA)
    < HCI Command: Link Key Request Reply (0x01|0x000b) plen 22
            Address: 8C:3C:AA:D8:11:67 (OUI 8C-3C-AA)
            Link key: ${32-hex-digits-key}
    ...
    > HCI Event: Connect Complete (0x03) plen 11
            Status: Success (0x00)
            Handle: 256
            Address: 8C:3C:AA:D8:11:67 (OUI 8C-3C-AA)
            Link type: ACL (0x01)
            Encryption: Enabled (0x01)
    < HCI Command: Read Encryption Key... (0x05|0x0008) plen 2
            Handle: 256
    < ACL Data TX: Handle 256 flags 0x00 dlen 10
          L2CAP: Information Request (0x0a) ident 1 len 2
            Type: Extended features supported (0x0002)
    > HCI Event: Command Complete (0x0e) plen 7
          Read Encryption Key Size (0x05|0x0008) ncmd 1
            Status: Success (0x00)
            Handle: 256
            Key size: 16

    Cc: stable@vger.kernel.org
    Link: https://github.com/bluez/bluez/issues/704
    Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
    Reviewed-by: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
    Signed-off-by: Hui Wang <hui.wang@canonical.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:00 +01:00
Bastien Nocera a27f397ebf Bluetooth: Add new quirk for broken read key length on ATS2851
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit 48201a3b3f398be6a01f78a14b18bd5d31c47458
Author: Vinicius Peixoto <nukelet64@gmail.com>
Date:   Mon Feb 26 22:43:26 2024 -0300

    Bluetooth: Add new quirk for broken read key length on ATS2851

    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: Vinicius Peixoto <nukelet64@gmail.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:25:00 +01:00
Bastien Nocera 6ccb253435 Bluetooth: hci_sync: Fix overwriting request callback
JIRA: https://issues.redhat.com/browse/RHEL-61734

commit 2615fd9a7c2507eb3be3fbe49dcec88a2f56454a
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Fri Feb 16 16:20:11 2024 -0500

    Bluetooth: hci_sync: Fix overwriting request callback

    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: 6a98e3836fa2 ("Bluetooth: Add helper for serialized HCI command execution")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-12-11 15:24:58 +01:00
Rado Vrbovsky 3c85f60e2f Merge: CVE-2024-36011: Bluetooth: HCI: Fix potential null-ptr-deref
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5012

JIRA: https://issues.redhat.com/browse/RHEL-38466
CVE: CVE-2024-36011

```
Bluetooth: HCI: Fix potential null-ptr-deref

Fix potential null-ptr-deref in hci_le_big_sync_established_evt().

Fixes: f777d8827817 (Bluetooth: ISO: Notify user space about failed bis connections)
Signed-off-by: Sungwoo Kim <iam@sung-woo.kim>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
(cherry picked from commit d2706004a1b8b526592e823d7e52551b518a7941)
```

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>

Approved-by: Bastien Nocera <bnocera@redhat.com>
Approved-by: David Marlin <dmarlin@redhat.com>
Approved-by: Tony Camuso <tcamuso@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2024-11-28 20:19:07 +00:00
Rado Vrbovsky dc02fffe75 Merge: CVE-2024-49950: Bluetooth: L2CAP: Fix uaf in l2cap_connect
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5519

JIRA: https://issues.redhat.com/browse/RHEL-63624
CVE: CVE-2024-49950

```
Bluetooth: L2CAP: Fix uaf in l2cap_connect

[Syzbot reported]
BUG: KASAN: slab-use-after-free in l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949
Read of size 8 at addr ffff8880241e9800 by task kworker/u9:0/54

CPU: 0 UID: 0 PID: 54 Comm: kworker/u9:0 Not tainted 6.11.0-rc6-syzkaller-00268-g788220eee30d #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
Workqueue: hci2 hci_rx_work
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:93 [inline]
 dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119
 print_address_description mm/kasan/report.c:377 [inline]
 print_report+0xc3/0x620 mm/kasan/report.c:488
 kasan_report+0xd9/0x110 mm/kasan/report.c:601
 l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949
 l2cap_connect_req net/bluetooth/l2cap_core.c:4080 [inline]
 l2cap_bredr_sig_cmd net/bluetooth/l2cap_core.c:4772 [inline]
 l2cap_sig_channel net/bluetooth/l2cap_core.c:5543 [inline]
 l2cap_recv_frame+0xf0b/0x8eb0 net/bluetooth/l2cap_core.c:6825
 l2cap_recv_acldata+0x9b4/0xb70 net/bluetooth/l2cap_core.c:7514
 hci_acldata_packet net/bluetooth/hci_core.c:3791 [inline]
 hci_rx_work+0xaab/0x1610 net/bluetooth/hci_core.c:4028
 process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231
 process_scheduled_works kernel/workqueue.c:3312 [inline]
 worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389
 kthread+0x2c1/0x3a0 kernel/kthread.c:389
 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
...

Freed by task 5245:
 kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
 kasan_save_track+0x14/0x30 mm/kasan/common.c:68
 kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579
 poison_slab_object+0xf7/0x160 mm/kasan/common.c:240
 __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256
 kasan_slab_free include/linux/kasan.h:184 [inline]
 slab_free_hook mm/slub.c:2256 [inline]
 slab_free mm/slub.c:4477 [inline]
 kfree+0x12a/0x3b0 mm/slub.c:4598
 l2cap_conn_free net/bluetooth/l2cap_core.c:1810 [inline]
 kref_put include/linux/kref.h:65 [inline]
 l2cap_conn_put net/bluetooth/l2cap_core.c:1822 [inline]
 l2cap_conn_del+0x59d/0x730 net/bluetooth/l2cap_core.c:1802
 l2cap_connect_cfm+0x9e6/0xf80 net/bluetooth/l2cap_core.c:7241
 hci_connect_cfm include/net/bluetooth/hci_core.h:1960 [inline]
 hci_conn_failed+0x1c3/0x370 net/bluetooth/hci_conn.c:1265
 hci_abort_conn_sync+0x75a/0xb50 net/bluetooth/hci_sync.c:5583
 abort_conn_sync+0x197/0x360 net/bluetooth/hci_conn.c:2917
 hci_cmd_sync_work+0x1a4/0x410 net/bluetooth/hci_sync.c:328
 process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231
 process_scheduled_works kernel/workqueue.c:3312 [inline]
 worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389
 kthread+0x2c1/0x3a0 kernel/kthread.c:389
 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

Reported-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com
Tested-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c
Fixes: 7b064edae3 ("Bluetooth: Fix authentication if acl data comes before remote feature evt")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
(cherry picked from commit 333b4fd11e89b29c84c269123f871883a30be586)
```

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>

---

Signed-off-by: Bastien Nocera <bnocera@redhat.com>

Omitted-Fix: 55abbd148dfb604ebf3f72d6c3dd2a8063d40718 (duplicate of `7967dc8f797f454d4f4acec15c7df0cdf4801617`)

<small>Created 2024-10-22 10:00 UTC by backporter - [KWF FAQ](https://red.ht/kernel_workflow_doc) - [Slack #team-kernel-workflow](https://redhat-internal.slack.com/archives/C04LRUPMJQ5) - [Source](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/webhook/utils/backporter.py) - [Documentation](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/docs/README.backporter.md) - [Report an issue](https://gitlab.com/cki-project/kernel-workflow/-/issues/new?issue%5Btitle%5D=backporter%20webhook%20issue)</small>

Approved-by: José Ignacio Tornos Martínez <jtornosm@redhat.com>
Approved-by: Daniel Horak <dhorak@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2024-11-28 20:19:04 +00:00
Bastien Nocera 4ebfb7ac6b Bluetooth: Remove pending ACL connection attempts
JIRA: https://issues.redhat.com/browse/RHEL-63875
CVE: CVE-2024-50029

commit 4aa42119d971603dc9e4d8cf4f53d5fcf082ea7d
Author: Jonas Dreßler <verdre@v0yd.nl>
Date:   Tue Feb 6 12:08:14 2024 +0100

    Bluetooth: Remove pending ACL connection attempts

    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 4c67bc74f0 ("[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: Jonas Dreßler <verdre@v0yd.nl>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-11-07 10:39:03 +01:00
Bastien Nocera 574ba8a4e8 Bluetooth: hci_event: Use HCI error defines instead of magic values
JIRA: https://issues.redhat.com/browse/RHEL-63875
CVE: CVE-2024-50029

commit 79c0868ad65a8fc7cdfaa5f2b77a4b70d0b0ea16
Author: Jonas Dreßler <verdre@v0yd.nl>
Date:   Mon Jan 8 23:46:07 2024 +0100

    Bluetooth: hci_event: Use HCI error defines instead of magic values

    We have error defines already, so let's use them.

    Signed-off-by: Jonas Dreßler <verdre@v0yd.nl>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-11-07 10:38:57 +01:00
Bastien Nocera 92f50035a2 Bluetooth: Remove superfluous call to hci_conn_check_pending()
JIRA: https://issues.redhat.com/browse/RHEL-63875
CVE: CVE-2024-50029

commit 78e3639fc8031275010c3287ac548c0bc8de83b1
Author: Jonas Dreßler <verdre@v0yd.nl>
Date:   Mon Jan 8 23:46:06 2024 +0100

    Bluetooth: Remove superfluous call to hci_conn_check_pending()

    The "pending connections" feature was originally introduced with commit
    4c67bc74f0 ("[Bluetooth] Support concurrent connect requests") and
    6bd5741612 ("[Bluetooth] Handling pending connect attempts after
    inquiry") to handle controllers supporting only a single connection request
    at a time. Later things were extended to also cancel ongoing inquiries on
    connect() with commit 89e65975fe ("Bluetooth: Cancel Inquiry before
    Create Connection").

    With commit a9de924806 ("[Bluetooth] Switch from OGF+OCF to using only
    opcodes"), hci_conn_check_pending() was introduced as a helper to
    consolidate a few places where we check for pending connections (indicated
    by the BT_CONNECT2 flag) and then try to connect.

    This refactoring commit also snuck in two more calls to
    hci_conn_check_pending():

    - One is in the failure callback of hci_cs_inquiry(), this one probably
    makes sense: If we send an "HCI Inquiry" command and then immediately
    after a "Create Connection" command, the "Create Connection" command might
    fail before the "HCI Inquiry" command, and then we want to retry the
    "Create Connection" on failure of the "HCI Inquiry".

    - The other added call to hci_conn_check_pending() is in the event handler
    for the "Remote Name" event, this seems unrelated and is possibly a
    copy-paste error, so remove that one.

    Fixes: a9de924806 ("[Bluetooth] Switch from OGF+OCF to using only opcodes")
    Signed-off-by: Jonas Dreßler <verdre@v0yd.nl>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-11-07 10:38:54 +01:00
CKI Backport Bot e63366bd36 Bluetooth: HCI: Fix potential null-ptr-deref
JIRA: https://issues.redhat.com/browse/RHEL-38466
CVE: CVE-2024-36011

commit d2706004a1b8b526592e823d7e52551b518a7941
Author: Sungwoo Kim <iam@sung-woo.kim>
Date:   Thu May 2 12:09:31 2024 -0400

    Bluetooth: HCI: Fix potential null-ptr-deref

    Fix potential null-ptr-deref in hci_le_big_sync_established_evt().

    Fixes: f777d8827817 (Bluetooth: ISO: Notify user space about failed bis connections)
    Signed-off-by: Sungwoo Kim <iam@sung-woo.kim>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
2024-11-06 10:14:52 +00:00
CKI Backport Bot 4d924089ac Bluetooth: L2CAP: Fix uaf in l2cap_connect
JIRA: https://issues.redhat.com/browse/RHEL-63624
CVE: CVE-2024-49950

commit 333b4fd11e89b29c84c269123f871883a30be586
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Mon Sep 23 12:47:39 2024 -0400

    Bluetooth: L2CAP: Fix uaf in l2cap_connect

    [Syzbot reported]
    BUG: KASAN: slab-use-after-free in l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949
    Read of size 8 at addr ffff8880241e9800 by task kworker/u9:0/54

    CPU: 0 UID: 0 PID: 54 Comm: kworker/u9:0 Not tainted 6.11.0-rc6-syzkaller-00268-g788220eee30d #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
    Workqueue: hci2 hci_rx_work
    Call Trace:
     <TASK>
     __dump_stack lib/dump_stack.c:93 [inline]
     dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119
     print_address_description mm/kasan/report.c:377 [inline]
     print_report+0xc3/0x620 mm/kasan/report.c:488
     kasan_report+0xd9/0x110 mm/kasan/report.c:601
     l2cap_connect.constprop.0+0x10d8/0x1270 net/bluetooth/l2cap_core.c:3949
     l2cap_connect_req net/bluetooth/l2cap_core.c:4080 [inline]
     l2cap_bredr_sig_cmd net/bluetooth/l2cap_core.c:4772 [inline]
     l2cap_sig_channel net/bluetooth/l2cap_core.c:5543 [inline]
     l2cap_recv_frame+0xf0b/0x8eb0 net/bluetooth/l2cap_core.c:6825
     l2cap_recv_acldata+0x9b4/0xb70 net/bluetooth/l2cap_core.c:7514
     hci_acldata_packet net/bluetooth/hci_core.c:3791 [inline]
     hci_rx_work+0xaab/0x1610 net/bluetooth/hci_core.c:4028
     process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231
     process_scheduled_works kernel/workqueue.c:3312 [inline]
     worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389
     kthread+0x2c1/0x3a0 kernel/kthread.c:389
     ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
     ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
    ...

    Freed by task 5245:
     kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
     kasan_save_track+0x14/0x30 mm/kasan/common.c:68
     kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579
     poison_slab_object+0xf7/0x160 mm/kasan/common.c:240
     __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256
     kasan_slab_free include/linux/kasan.h:184 [inline]
     slab_free_hook mm/slub.c:2256 [inline]
     slab_free mm/slub.c:4477 [inline]
     kfree+0x12a/0x3b0 mm/slub.c:4598
     l2cap_conn_free net/bluetooth/l2cap_core.c:1810 [inline]
     kref_put include/linux/kref.h:65 [inline]
     l2cap_conn_put net/bluetooth/l2cap_core.c:1822 [inline]
     l2cap_conn_del+0x59d/0x730 net/bluetooth/l2cap_core.c:1802
     l2cap_connect_cfm+0x9e6/0xf80 net/bluetooth/l2cap_core.c:7241
     hci_connect_cfm include/net/bluetooth/hci_core.h:1960 [inline]
     hci_conn_failed+0x1c3/0x370 net/bluetooth/hci_conn.c:1265
     hci_abort_conn_sync+0x75a/0xb50 net/bluetooth/hci_sync.c:5583
     abort_conn_sync+0x197/0x360 net/bluetooth/hci_conn.c:2917
     hci_cmd_sync_work+0x1a4/0x410 net/bluetooth/hci_sync.c:328
     process_one_work+0x9c5/0x1b40 kernel/workqueue.c:3231
     process_scheduled_works kernel/workqueue.c:3312 [inline]
     worker_thread+0x6c8/0xed0 kernel/workqueue.c:3389
     kthread+0x2c1/0x3a0 kernel/kthread.c:389
     ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
     ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

    Reported-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com
    Tested-by: syzbot+c12e2f941af1feb5632c@syzkaller.appspotmail.com
    Closes: https://syzkaller.appspot.com/bug?extid=c12e2f941af1feb5632c
    Fixes: 7b064edae3 ("Bluetooth: Fix authentication if acl data comes before remote feature evt")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
2024-10-22 10:00:34 +00:00
Rado Vrbovsky 5dbb51086d Merge: CVE-2024-36968 Bluetooth: L2CAP: Fix div-by-zero in l2cap_le_flowctl_init()
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5069

Bluetooth: L2CAP: Fix div-by-zero in l2cap_le_flowctl_init()

JIRA: https://issues.redhat.com/browse/RHEL-41144
CVE: CVE-2024-36968

Depends: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4996

```
commit a5b862c6a221459d54e494e88965b48dcfa6cc44
Author: Sungwoo Kim <iam@sung-woo.kim>
Date:   Sat May 4 15:23:29 2024 -0400

    Bluetooth: L2CAP: Fix div-by-zero in l2cap_le_flowctl_init()

    l2cap_le_flowctl_init() can cause both div-by-zero and an integer
    overflow since hdev->le_mtu may not fall in the valid range.

    Move MTU from hci_dev to hci_conn to validate MTU and stop the connection
    process earlier if MTU is invalid.
    Also, add a missing validation in read_buffer_size() and make it return
    an error value if the validation fails.
    Now hci_conn_add() returns ERR_PTR() as it can fail due to the both a
    kzalloc failure and invalid MTU value.

    divide error: 0000 [#1] PREEMPT SMP KASAN NOPTI
    CPU: 0 PID: 67 Comm: kworker/u5:0 Tainted: G        W          6.9.0-rc5+ #20
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
    Workqueue: hci0 hci_rx_work
    RIP: 0010:l2cap_le_flowctl_init+0x19e/0x3f0 net/bluetooth/l2cap_core.c:547
    Code: e8 17 17 0c 00 66 41 89 9f 84 00 00 00 bf 01 00 00 00 41 b8 02 00 00 00 4c
    89 fe 4c 89 e2 89 d9 e8 27 17 0c 00 44 89 f0 31 d2 <66> f7 f3 89 c3 ff c3 4d 8d
    b7 88 00 00 00 4c 89 f0 48 c1 e8 03 42
    RSP: 0018:ffff88810bc0f858 EFLAGS: 00010246
    RAX: 00000000000002a0 RBX: 0000000000000000 RCX: dffffc0000000000
    RDX: 0000000000000000 RSI: ffff88810bc0f7c0 RDI: ffffc90002dcb66f
    RBP: ffff88810bc0f880 R08: aa69db2dda70ff01 R09: 0000ffaaaaaaaaaa
    R10: 0084000000ffaaaa R11: 0000000000000000 R12: ffff88810d65a084
    R13: dffffc0000000000 R14: 00000000000002a0 R15: ffff88810d65a000
    FS:  0000000000000000(0000) GS:ffff88811ac00000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 0000000020000100 CR3: 0000000103268003 CR4: 0000000000770ef0
    PKRU: 55555554
    Call Trace:
     <TASK>
     l2cap_le_connect_req net/bluetooth/l2cap_core.c:4902 [inline]
     l2cap_le_sig_cmd net/bluetooth/l2cap_core.c:5420 [inline]
     l2cap_le_sig_channel net/bluetooth/l2cap_core.c:5486 [inline]
     l2cap_recv_frame+0xe59d/0x11710 net/bluetooth/l2cap_core.c:6809
     l2cap_recv_acldata+0x544/0x10a0 net/bluetooth/l2cap_core.c:7506
     hci_acldata_packet net/bluetooth/hci_core.c:3939 [inline]
     hci_rx_work+0x5e5/0xb20 net/bluetooth/hci_core.c:4176
     process_one_work kernel/workqueue.c:3254 [inline]
     process_scheduled_works+0x90f/0x1530 kernel/workqueue.c:3335
     worker_thread+0x926/0xe70 kernel/workqueue.c:3416
     kthread+0x2e3/0x380 kernel/kthread.c:388
     ret_from_fork+0x5c/0x90 arch/x86/kernel/process.c:147
     ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
     </TASK>
    Modules linked in:
    ---[ end trace 0000000000000000 ]---

    Fixes: 6ed58ec520 ("Bluetooth: Use LE buffers for LE traffic")
    Suggested-by: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
    Signed-off-by: Sungwoo Kim <iam@sung-woo.kim>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
```

Signed-off-by: Bastien Nocera <bnocera@redhat.com>

Approved-by: José Ignacio Tornos Martínez <jtornosm@redhat.com>
Approved-by: Tony Camuso <tcamuso@redhat.com>
Approved-by: David Marlin <dmarlin@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2024-10-16 12:13:04 +00:00
Rado Vrbovsky a582489b38 Merge: CVE-2024-42133: Bluetooth: Ignore too large handle values in BIG
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4899

JIRA: https://issues.redhat.com/browse/RHEL-51918  
CVE: CVE-2024-42133

```
Bluetooth: Ignore too large handle values in BIG

hci_le_big_sync_established_evt is necessary to filter out cases where the
handle value is belonging to ida id range, otherwise ida will be erroneously
released in hci_conn_cleanup.

Fixes: 181a42edddf5 ("Bluetooth: Make handle of hci_conn be unique")
Reported-by: syzbot+b2545b087a01a7319474@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b2545b087a01a7319474
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
(cherry picked from commit 015d79c96d62cd8a4a359fcf5be40d58088c936b)
```

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>

Approved-by: Bastien Nocera <bnocera@redhat.com>
Approved-by: David Marlin <dmarlin@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2024-10-02 08:38:31 +00:00
Bastien Nocera 7007afb70e Bluetooth: L2CAP: Fix div-by-zero in l2cap_le_flowctl_init()
JIRA: https://issues.redhat.com/browse/RHEL-41144
CVE: CVE-2024-36968

commit a5b862c6a221459d54e494e88965b48dcfa6cc44
Author: Sungwoo Kim <iam@sung-woo.kim>
Date:   Sat May 4 15:23:29 2024 -0400

    Bluetooth: L2CAP: Fix div-by-zero in l2cap_le_flowctl_init()

    l2cap_le_flowctl_init() can cause both div-by-zero and an integer
    overflow since hdev->le_mtu may not fall in the valid range.

    Move MTU from hci_dev to hci_conn to validate MTU and stop the connection
    process earlier if MTU is invalid.
    Also, add a missing validation in read_buffer_size() and make it return
    an error value if the validation fails.
    Now hci_conn_add() returns ERR_PTR() as it can fail due to the both a
    kzalloc failure and invalid MTU value.

    divide error: 0000 [#1] PREEMPT SMP KASAN NOPTI
    CPU: 0 PID: 67 Comm: kworker/u5:0 Tainted: G        W          6.9.0-rc5+ #20
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
    Workqueue: hci0 hci_rx_work
    RIP: 0010:l2cap_le_flowctl_init+0x19e/0x3f0 net/bluetooth/l2cap_core.c:547
    Code: e8 17 17 0c 00 66 41 89 9f 84 00 00 00 bf 01 00 00 00 41 b8 02 00 00 00 4c
    89 fe 4c 89 e2 89 d9 e8 27 17 0c 00 44 89 f0 31 d2 <66> f7 f3 89 c3 ff c3 4d 8d
    b7 88 00 00 00 4c 89 f0 48 c1 e8 03 42
    RSP: 0018:ffff88810bc0f858 EFLAGS: 00010246
    RAX: 00000000000002a0 RBX: 0000000000000000 RCX: dffffc0000000000
    RDX: 0000000000000000 RSI: ffff88810bc0f7c0 RDI: ffffc90002dcb66f
    RBP: ffff88810bc0f880 R08: aa69db2dda70ff01 R09: 0000ffaaaaaaaaaa
    R10: 0084000000ffaaaa R11: 0000000000000000 R12: ffff88810d65a084
    R13: dffffc0000000000 R14: 00000000000002a0 R15: ffff88810d65a000
    FS:  0000000000000000(0000) GS:ffff88811ac00000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 0000000020000100 CR3: 0000000103268003 CR4: 0000000000770ef0
    PKRU: 55555554
    Call Trace:
     <TASK>
     l2cap_le_connect_req net/bluetooth/l2cap_core.c:4902 [inline]
     l2cap_le_sig_cmd net/bluetooth/l2cap_core.c:5420 [inline]
     l2cap_le_sig_channel net/bluetooth/l2cap_core.c:5486 [inline]
     l2cap_recv_frame+0xe59d/0x11710 net/bluetooth/l2cap_core.c:6809
     l2cap_recv_acldata+0x544/0x10a0 net/bluetooth/l2cap_core.c:7506
     hci_acldata_packet net/bluetooth/hci_core.c:3939 [inline]
     hci_rx_work+0x5e5/0xb20 net/bluetooth/hci_core.c:4176
     process_one_work kernel/workqueue.c:3254 [inline]
     process_scheduled_works+0x90f/0x1530 kernel/workqueue.c:3335
     worker_thread+0x926/0xe70 kernel/workqueue.c:3416
     kthread+0x2e3/0x380 kernel/kthread.c:388
     ret_from_fork+0x5c/0x90 arch/x86/kernel/process.c:147
     ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
     </TASK>
    Modules linked in:
    ---[ end trace 0000000000000000 ]---

    Fixes: 6ed58ec520 ("Bluetooth: Use LE buffers for LE traffic")
    Suggested-by: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
    Signed-off-by: Sungwoo Kim <iam@sung-woo.kim>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-09-11 10:15:38 +02:00
Bastien Nocera 4b65308c2f Bluetooth: ISO: Handle PA sync when no BIGInfo reports are generated
JIRA: https://issues.redhat.com/browse/RHEL-41144
CVE: CVE-2024-36968

commit d356c924e7a3adbea1e3e4ff4e098bcd9b99a82d
Author: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Date:   Tue Apr 2 14:39:31 2024 +0300

    Bluetooth: ISO: Handle PA sync when no BIGInfo reports are generated

    In case of a Broadcast Source that has PA enabled but no active BIG,
    a Broadcast Sink needs to establish PA sync and parse BASE from PA
    reports.

    This commit moves the allocation of a PA sync hcon from the BIGInfo
    advertising report event to the PA sync established event. After the
    first complete PA report, the hcon is notified to the ISO layer. A
    child socket is allocated and enqueued in the parent's accept queue.

    BIGInfo reports also need to be processed, to extract the encryption
    field and inform userspace. After the first BIGInfo report is received,
    the PA sync hcon is notified again to the ISO layer. Since a socket will
    be found this time, the socket state will transition to BT_CONNECTED and
    the userspace will be woken up using sk_state_change.

    Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-09-11 10:15:38 +02:00
Bastien Nocera 4f5d2e0a95 Bluetooth: hci_event: Fix not indicating new connection for BIG Sync
JIRA: https://issues.redhat.com/browse/RHEL-41144
CVE: CVE-2024-36968

commit eeda1bf97bb500a901f7a9ee5615bad2160f2378
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Wed Jan 31 11:24:19 2024 -0500

    Bluetooth: hci_event: Fix not indicating new connection for BIG Sync

    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: 1d11d70d1f6b ("Bluetooth: ISO: Pass BIG encryption info through QoS")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-09-11 10:15:37 +02:00
Bastien Nocera d67f530cde Bluetooth: HCI: Remove HCI_AMP support
JIRA: https://issues.redhat.com/browse/RHEL-38459
CVE: CVE-2024-36013

commit 84a4bb6548a29326564f0e659fb8064503ecc1c7
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Mon May 6 18:33:52 2024 -0400

    Bluetooth: HCI: Remove HCI_AMP support

    Since BT_HS has been remove HCI_AMP controllers no longer has any use so
    remove it along with the capability of creating AMP controllers.

    Since we no longer need to differentiate between AMP and Primary
    controllers, as only HCI_PRIMARY is left, this also remove
    hdev->dev_type altogether.

    Fixes: e7b02296fb40 ("Bluetooth: Remove BT_HS")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-08-19 13:48:20 +02:00
Bastien Nocera 107e691cad Bluetooth: hci_event: Remove code to removed CONFIG_BT_HS
JIRA: https://issues.redhat.com/browse/RHEL-38459
CVE: CVE-2024-36013

commit f4b0c2b4cd78b75acde56c2ee5aa732b6fb2a6a9
Author: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Date:   Wed Feb 7 14:42:11 2024 +0100

    Bluetooth: hci_event: Remove code to removed CONFIG_BT_HS

    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: Lukas Bulwahn <lukas.bulwahn@gmail.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-08-19 13:48:19 +02:00
Bastien Nocera 0db5333ac9 Bluetooth: Remove BT_HS
JIRA: https://issues.redhat.com/browse/RHEL-38459
CVE: CVE-2024-36013

Conflicts: the one-line code conflict is in removed code, and avoids
us having pick up multi-system commit de4eda9de2d9 ("use less confusing
names for iov_iter direction initializers")

commit e7b02296fb400ee64822fbdd81a0718449066333
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Thu Feb 1 11:18:58 2024 -0500

    Bluetooth: Remove BT_HS

    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: 244bc37759 ("Bluetooth: Add BT_HS config option")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-08-19 13:48:19 +02:00
CKI Backport Bot f865cc1b92 Bluetooth: Ignore too large handle values in BIG
JIRA: https://issues.redhat.com/browse/RHEL-51918
CVE: CVE-2024-42133

commit 015d79c96d62cd8a4a359fcf5be40d58088c936b
Author: Edward Adam Davis <eadavis@qq.com>
Date:   Mon Jun 17 19:09:37 2024 +0800

    Bluetooth: Ignore too large handle values in BIG

    hci_le_big_sync_established_evt is necessary to filter out cases where the
    handle value is belonging to ida id range, otherwise ida will be erroneously
    released in hci_conn_cleanup.

    Fixes: 181a42edddf5 ("Bluetooth: Make handle of hci_conn be unique")
    Reported-by: syzbot+b2545b087a01a7319474@syzkaller.appspotmail.com
    Closes: https://syzkaller.appspot.com/bug?extid=b2545b087a01a7319474
    Signed-off-by: Edward Adam Davis <eadavis@qq.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
2024-07-31 09:55:23 +00:00
David Marlin 13b620b9f6 Bluetooth: Enforce validation on max value of connection interval
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit e4b019515f950b4e6e5b74b2e1bb03a90cb33039
Author: Kai-Heng Feng <kai.heng.feng@canonical.com>
Date:   Thu Jan 25 14:50:28 2024 +0800

    Bluetooth: Enforce validation on max value of connection interval

    Right now Linux BT stack cannot pass test case "GAP/CONN/CPUP/BV-05-C
    'Connection Parameter Update Procedure Invalid Parameters Central
    Responder'" in Bluetooth Test Suite revision GAP.TS.p44. [0]

    That was revoled by commit c49a8682fc ("Bluetooth: validate BLE
    connection interval updates"), but later got reverted due to devices
    like keyboards and mice may require low connection interval.

    So only validate the max value connection interval to pass the Test
    Suite, and let devices to request low connection interval if needed.

    [0] https://www.bluetooth.org/docman/handlers/DownloadDoc.ashx?doc_id=229869

    Fixes: 68d19d7d99 ("Revert "Bluetooth: validate BLE connection interval updates"")
    Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:37:33 -05:00
David Marlin 55c6c8c7c1 Bluetooth: hci_event: Fix handling of HCI_EV_IO_CAPA_REQUEST
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit 7e74aa53a68bf60f6019bd5d9a9a1406ec4d4865
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Mon Jan 22 09:02:47 2024 -0500

    Bluetooth: hci_event: Fix handling of HCI_EV_IO_CAPA_REQUEST

    If we received HCI_EV_IO_CAPA_REQUEST while
    HCI_OP_READ_REMOTE_EXT_FEATURES is yet to be responded assume the remote
    does support SSP since otherwise this event shouldn't be generated.

    Link: https://lore.kernel.org/linux-bluetooth/CABBYNZ+9UdG1cMZVmdtN3U2aS16AKMCyTARZZyFX7xTEDWcMOw@mail.gmail.com/T/#t
    Fixes: c7f59461f5a7 ("Bluetooth: Fix a refcnt underflow problem for hci_conn")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:37:33 -05:00
David Marlin 6d0a72f2e9 Bluetooth: hci_event: Fix wrongly recorded wakeup BD_ADDR
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit 61a5ab72edea7ebc3ad2c6beea29d966f528ebfb
Author: Zijun Hu <quic_zijuhu@quicinc.com>
Date:   Tue Jan 9 19:03:23 2024 +0800

    Bluetooth: hci_event: Fix wrongly recorded wakeup BD_ADDR

    hci_store_wake_reason() wrongly parses event HCI_Connection_Request
    as HCI_Connection_Complete and HCI_Connection_Complete as
    HCI_Connection_Request, so causes recording wakeup BD_ADDR error and
    potential stability issue, fix it by using the correct field.

    Fixes: 2f20216c1d ("Bluetooth: Emit controller suspend and resume events")
    Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:37:33 -05:00
David Marlin 50f5909103 Bluetooth: hci_event: shut up a false-positive warning
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit a5812c68d849505ea657f653446512b85887f813
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Wed Nov 22 23:17:44 2023 +0100

    Bluetooth: hci_event: shut up a false-positive warning

    Turning on -Wstringop-overflow globally exposed a misleading compiler
    warning in bluetooth:

    net/bluetooth/hci_event.c: In function 'hci_cc_read_class_of_dev':
    net/bluetooth/hci_event.c:524:9: error: 'memcpy' writing 3 bytes into a
    region of size 0 overflows the destination [-Werror=stringop-overflow=]
      524 |         memcpy(hdev->dev_class, rp->dev_class, 3);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    The problem here is the check for hdev being NULL in bt_dev_dbg() that
    leads the compiler to conclude that hdev->dev_class might be an invalid
    pointer access.

    Add another explicit check for the same condition to make sure gcc sees
    this cannot happen.

    Fixes: a9de924806 ("[Bluetooth] Switch from OGF+OCF to using only opcodes")
    Fixes: 1b56c90018f0 ("Makefile: Enable -Wstringop-overflow globally")
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:35:09 -05:00
David Marlin c1d769ca07 Bluetooth: hci_event: Fix not checking if HCI_OP_INQUIRY has been sent
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit 99e67d46e5ff3c7c901af6009edec72d3d363be8
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Mon Nov 20 10:04:39 2023 -0500

    Bluetooth: hci_event: Fix not checking if HCI_OP_INQUIRY has been sent

    Before setting HCI_INQUIRY bit check if HCI_OP_INQUIRY was really sent
    otherwise the controller maybe be generating invalid events or, more
    likely, it is a result of fuzzing tools attempting to test the right
    behavior of the stack when unexpected events are generated.

    Cc: stable@vger.kernel.org
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=218151
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:35:09 -05:00
David Marlin 5e9290efaf Bluetooth: Fix not notifying when connection encryption changes
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit f67eabffb57d0bee379994a18ec5f462b2cbdf86
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Mon Oct 23 16:26:23 2023 -0700

    Bluetooth: Fix not notifying when connection encryption changes

    Some layers such as SMP depend on getting notified about encryption
    changes immediately as they only allow certain PDU to be transmitted
    over an encrypted link which may cause SMP implementation to reject
    valid PDUs received thus causing pairing to fail when it shouldn't.

    Fixes: 7aca0ac4792e ("Bluetooth: Wait for HCI_OP_WRITE_AUTH_PAYLOAD_TO to complete")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:35:08 -05:00
David Marlin 9e513e2494 Bluetooth: Fix a refcnt underflow problem for hci_conn
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit c7f59461f5a78994613afc112cdd73688aef9076
Author: Ziyang Xuan <william.xuanziyang@huawei.com>
Date:   Wed Oct 4 20:42:24 2023 +0800

    Bluetooth: Fix a refcnt underflow problem for hci_conn

    Syzbot reports a warning as follows:

    WARNING: CPU: 1 PID: 26946 at net/bluetooth/hci_conn.c:619
    hci_conn_timeout+0x122/0x210 net/bluetooth/hci_conn.c:619
    ...
    Call Trace:
     <TASK>
     process_one_work+0x884/0x15c0 kernel/workqueue.c:2630
     process_scheduled_works kernel/workqueue.c:2703 [inline]
     worker_thread+0x8b9/0x1290 kernel/workqueue.c:2784
     kthread+0x33c/0x440 kernel/kthread.c:388
     ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
     ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
     </TASK>

    It is because the HCI_EV_SIMPLE_PAIR_COMPLETE event handler drops
    hci_conn directly without check Simple Pairing whether be enabled. But
    the Simple Pairing process can only be used if both sides have the
    support enabled in the host stack.

    Add hci_conn_ssp_enabled() for hci_conn in HCI_EV_IO_CAPA_REQUEST and
    HCI_EV_SIMPLE_PAIR_COMPLETE event handlers to fix the problem.

    Fixes: 0493684ed2 ("[Bluetooth] Disable disconnect timer during Simple Pairing")
    Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:35:07 -05:00
David Marlin 3575bb5ad2 Bluetooth: ISO: Add support for periodic adv reports processing
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit 9c0826310bfb784c9bac7d1d9454e304185446c5
Author: Claudia Draghicescu <claudia.rosu@nxp.com>
Date:   Fri Jun 30 12:59:28 2023 +0300

    Bluetooth: ISO: Add support for periodic adv reports processing

    In the case of a Periodic Synchronized Receiver,
    the PA report received from a Broadcaster contains the BASE,
    which has information about codec and other parameters of a BIG.
    This isnformation is stored and the application can retrieve it
    using getsockopt(BT_ISO_BASE).

    Signed-off-by: Claudia Draghicescu <claudia.rosu@nxp.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:35:07 -05:00
David Marlin ad0d3f716a Bluetooth: hci_event: drop only unbound CIS if Set CIG Parameters fails
JIRA: https://issues.redhat.com/browse/RHEL-30099

commit 66dee21524d9ac6461ec3052652b7bc0603ee0c5
Author: Pauli Virtanen <pav@iki.fi>
Date:   Sat Aug 5 19:08:41 2023 +0300

    Bluetooth: hci_event: drop only unbound CIS if Set CIG Parameters fails

    When user tries to connect a new CIS when its CIG is not configurable,
    that connection shall fail, but pre-existing connections shall not be
    affected.  However, currently hci_cc_le_set_cig_params deletes all CIS
    of the CIG on error so it doesn't work, even though controller shall not
    change CIG/CIS configuration if the command fails.

    Fix by failing on command error only the connections that are not yet
    bound, so that we keep the previous CIS configuration like the
    controller does.

    Fixes: 26afbd826ee3 ("Bluetooth: Add initial implementation of CIS connections")
    Signed-off-by: Pauli Virtanen <pav@iki.fi>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: David Marlin <dmarlin@redhat.com>
2024-05-22 21:35:06 -05:00
Lucas Zampieri c6e76e74ae Merge: Bluetooth: Fix bogus check for re-auth no supported with non-ssp
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3652

JIRA: https://issues.redhat.com/browse/RHEL-18225
JIRA: https://issues.redhat.com/browse/RHEL-18227
CVE: CVE-2020-10135

commit d03376c185926098cb4d668d6458801eb785c0a5
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Thu Nov 30 14:58:03 2023 +0100

    Bluetooth: Fix bogus check for re-auth no supported with non-ssp

    This reverts 19f8def031
    "Bluetooth: Fix auth_complete_evt for legacy units" which seems to be
    working around a bug on a broken controller rather then any limitation
    imposed by the Bluetooth spec, in fact if there ws not possible to
    re-auth the command shall fail not succeed.

    Fixes: 19f8def031 ("Bluetooth: Fix auth_complete_evt for legacy units")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>

Approved-by: Steve Best <sbest@redhat.com>
Approved-by: John B. Wyatt IV <jwyatt@redhat.com>
Approved-by: David Marlin <dmarlin@redhat.com>

Merged-by: Lucas Zampieri <lzampier@redhat.com>
2024-03-18 16:54:18 -03:00
Bastien Nocera 37098d552c Bluetooth: Add more enc key size check
CVE: CVE-2023-24023

JIRA: https://issues.redhat.com/browse/RHEL-19668

commit 04a342cc49a8522e99c9b3346371c329d841dcd2
Author: Alex Lu <alex_lu@realsil.com.cn>
Date:   Tue Dec 12 10:30:34 2023 +0800

    Bluetooth: Add more enc key size check

    When we are slave role and receives l2cap conn req when encryption has
    started, we should check the enc key size to avoid KNOB attack or BLUFFS
    attack.
    From SIG recommendation, implementations are advised to reject
    service-level connections on an encrypted baseband link with key
    strengths below 7 octets.
    A simple and clear way to achieve this is to place the enc key size
    check in hci_cc_read_enc_key_size()

    The btmon log below shows the case that lacks enc key size check.

    > HCI Event: Connect Request (0x04) plen 10
            Address: BB:22:33:44:55:99 (OUI BB-22-33)
            Class: 0x480104
              Major class: Computer (desktop, notebook, PDA, organizers)
              Minor class: Desktop workstation
              Capturing (Scanner, Microphone)
              Telephony (Cordless telephony, Modem, Headset)
            Link type: ACL (0x01)
    < HCI Command: Accept Connection Request (0x01|0x0009) plen 7
            Address: BB:22:33:44:55:99 (OUI BB-22-33)
            Role: Peripheral (0x01)
    > HCI Event: Command Status (0x0f) plen 4
          Accept Connection Request (0x01|0x0009) ncmd 2
            Status: Success (0x00)
    > HCI Event: Connect Complete (0x03) plen 11
            Status: Success (0x00)
            Handle: 1
            Address: BB:22:33:44:55:99 (OUI BB-22-33)
            Link type: ACL (0x01)
            Encryption: Disabled (0x00)
    ...

    > HCI Event: Encryption Change (0x08) plen 4
            Status: Success (0x00)
            Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33)
            Encryption: Enabled with E0 (0x01)
    < HCI Command: Read Encryption Key Size (0x05|0x0008) plen 2
            Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33)
    > HCI Event: Command Complete (0x0e) plen 7
          Read Encryption Key Size (0x05|0x0008) ncmd 2
            Status: Success (0x00)
            Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33)
            Key size: 6
    // We should check the enc key size
    ...

    > ACL Data RX: Handle 1 flags 0x02 dlen 12
          L2CAP: Connection Request (0x02) ident 3 len 4
            PSM: 25 (0x0019)
            Source CID: 64
    < ACL Data TX: Handle 1 flags 0x00 dlen 16
          L2CAP: Connection Response (0x03) ident 3 len 8
            Destination CID: 64
            Source CID: 64
            Result: Connection pending (0x0001)
            Status: Authorization pending (0x0002)
    > HCI Event: Number of Completed Packets (0x13) plen 5
            Num handles: 1
            Handle: 1 Address: BB:22:33:44:55:99 (OUI BB-22-33)
            Count: 1
            #35: len 16 (25 Kb/s)
            Latency: 5 msec (2-7 msec ~4 msec)
    < ACL Data TX: Handle 1 flags 0x00 dlen 16
          L2CAP: Connection Response (0x03) ident 3 len 8
            Destination CID: 64
            Source CID: 64
            Result: Connection successful (0x0000)
            Status: No further information available (0x0000)

    Cc: stable@vger.kernel.org
    Signed-off-by: Alex Lu <alex_lu@realsil.com.cn>
    Signed-off-by: Max Chou <max.chou@realtek.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-02-08 10:19:25 +01:00
Bastien Nocera 7483f16d3f Bluetooth: Fix bogus check for re-auth no supported with non-ssp
JIRA: https://issues.redhat.com/browse/RHEL-18225
JIRA: https://issues.redhat.com/browse/RHEL-18227
CVE: CVE-2020-10135

commit d03376c185926098cb4d668d6458801eb785c0a5
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Thu Nov 30 14:58:03 2023 +0100

    Bluetooth: Fix bogus check for re-auth no supported with non-ssp

    This reverts 19f8def031
    "Bluetooth: Fix auth_complete_evt for legacy units" which seems to be
    working around a bug on a broken controller rather then any limitation
    imposed by the Bluetooth spec, in fact if there ws not possible to
    re-auth the command shall fail not succeed.

    Fixes: 19f8def031 ("Bluetooth: Fix auth_complete_evt for legacy units")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-01-23 16:23:33 +01:00
Scott Weaver b978d02507 Merge: kernel: Bluetooth: BR/EDR PIN Pairing procedure is vulnerable to an impersonation attack
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3575

JIRA: https://issues.redhat.com/browse/RHEL-18222

CVE: CVE-2020-26555

```
    commit 1ffc6f8cc33268731fcf9629fc4438f6db1191fc
    Author: Lee, Chun-Yi <jlee@suse.com>
    Date:   Sun Oct 1 16:59:58 2023 +0800

        Bluetooth: Reject connection with the device which has same BD_ADDR

        This change is used to relieve CVE-2020-26555. The description of
        the CVE:

        Bluetooth legacy BR/EDR PIN code pairing in Bluetooth Core Specification
        1.0B through 5.2 may permit an unauthenticated nearby device to spoof
        the BD_ADDR of the peer device to complete pairing without knowledge
        of the PIN. [1]

        The detail of this attack is in IEEE paper:
        BlueMirror: Reflections on Bluetooth Pairing and Provisioning Protocols
        [2]

        It's a reflection attack. The paper mentioned that attacker can induce
        the attacked target to generate null link key (zero key) without PIN
        code. In BR/EDR, the key generation is actually handled in the controller
        which is below HCI.

        A condition of this attack is that attacker should change the
        BR_ADDR of his hacking device (Host B) to equal to the BR_ADDR with
        the target device being attacked (Host A).

        Thus, we reject the connection with device which has same BD_ADDR
        both on HCI_Create_Connection and HCI_Connection_Request to prevent
        the attack. A similar implementation also shows in btstack project.
        [3][4]

        Cc: stable@vger.kernel.org
        Link: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-26555 [1]
        Link: https://ieeexplore.ieee.org/abstract/document/9474325/authors#authors [2]
        Link: https://github.com/bluekitchen/btstack/blob/master/src/hci.c#L3523 [3]
        Link: https://github.com/bluekitchen/btstack/blob/master/src/hci.c#L7297 [4]
        Signed-off-by: Lee, Chun-Yi <jlee@suse.com>
        Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

```

Signed-off-by: David Marlin <dmarlin@redhat.com>

Approved-by: Bastien Nocera <bnocera@redhat.com>
Approved-by: Tony Camuso <tcamuso@redhat.com>

Signed-off-by: Scott Weaver <scweaver@redhat.com>
2024-01-18 10:16:22 -05:00
Bastien Nocera 46ec96833f Bluetooth: ISO: Fix invalid context error
JIRA: https://issues.redhat.com/browse/RHEL-17138

commit acab8ff29a2a226409cfe04e6d2e0896928c1b3a
Author: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Date:   Thu Sep 28 10:52:57 2023 +0300

    Bluetooth: ISO: Fix invalid context error

    This moves the hci_le_terminate_big_sync call from rx_work
    to cmd_sync_work, to avoid calling sleeping function from
    an invalid context.

    Reported-by: syzbot+c715e1bd8dfbcb1ab176@syzkaller.appspotmail.com
    Fixes: a0bfde167b50 ("Bluetooth: ISO: Add support for connecting multiple BISes")
    Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-01-11 22:36:07 +01:00
Bastien Nocera 00a0b5bb05 Bluetooth: Make handle of hci_conn be unique
JIRA: https://issues.redhat.com/browse/RHEL-17138

commit 181a42edddf51d5d9697ecdf365d72ebeab5afb0
Author: Ziyang Xuan <william.xuanziyang@huawei.com>
Date:   Wed Oct 11 17:57:31 2023 +0800

    Bluetooth: Make handle of hci_conn be unique

    The handle of new hci_conn is always HCI_CONN_HANDLE_MAX + 1 if
    the handle of the first hci_conn entry in hci_dev->conn_hash->list
    is not HCI_CONN_HANDLE_MAX + 1. Use ida to manage the allocation of
    hci_conn->handle to make it be unique.

    Fixes: 9f78191cc9f1 ("Bluetooth: hci_conn: Always allocate unique handles")
    Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-01-11 16:47:25 +01:00
Bastien Nocera 8e74dd7ef7 Bluetooth: ISO: Fix bcast listener cleanup
JIRA: https://issues.redhat.com/browse/RHEL-17138

commit fcb89f120376c054005e6d7a82bb89f95b3b04ef
Author: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Date:   Wed Oct 11 17:24:07 2023 +0300

    Bluetooth: ISO: Fix bcast listener cleanup

    This fixes the cleanup callback for slave bis and pa sync hcons.

    Closing all bis hcons will trigger BIG Terminate Sync, while closing
    all bises and the pa sync hcon will also trigger PA Terminate Sync.

    Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-01-11 16:47:25 +01:00
Bastien Nocera a701fc2c5a Bluetooth: ISO: Pass BIG encryption info through QoS
JIRA: https://issues.redhat.com/browse/RHEL-17138

commit 1d11d70d1f6b23e7d3fc00396c17b90b876162a4
Author: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Date:   Wed Sep 6 17:01:03 2023 +0300

    Bluetooth: ISO: Pass BIG encryption info through QoS

    This enables a broadcast sink to be informed if the PA
    it has synced with is associated with an encrypted BIG,
    by retrieving the socket QoS and checking the encryption
    field.

    After PA sync has been successfully established and the
    first BIGInfo advertising report is received, a new hcon
    is added and notified to the ISO layer. The ISO layer
    sets the encryption field of the socket and hcon QoS
    according to the encryption parameter of the BIGInfo
    advertising report event.

    After that, the userspace is woken up, and the QoS of the
    new PA sync socket can be read, to inspect the encryption
    field and follow up accordingly.

    Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-01-11 16:47:25 +01:00
Bastien Nocera 8210a32b68 Bluetooth: ISO: Use defer setup to separate PA sync and BIG sync
JIRA: https://issues.redhat.com/browse/RHEL-17138

commit fbdc4bc47268953c80853489f696e02d61f9a2c6
Author: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Date:   Thu Aug 17 09:44:27 2023 +0300

    Bluetooth: ISO: Use defer setup to separate PA sync and BIG sync

    This commit implements defer setup support for the Broadcast Sink
    scenario: By setting defer setup on a broadcast socket before calling
    listen, the user is able to trigger the PA sync and BIG sync procedures
    separately.

    This is useful if the user first wants to synchronize to the periodic
    advertising transmitted by a Broadcast Source, and trigger the BIG sync
    procedure later on.

    If defer setup is set, once a PA sync established event arrives, a new
    hcon is created and notified to the ISO layer. A child socket associated
    with the PA sync connection will be added to the accept queue of the
    listening socket.

    Once the accept call returns the fd for the PA sync child socket, the
    user should call read on that fd. This will trigger the BIG create sync
    procedure, and the PA sync socket will become a listening socket itself.

    When the BIG sync established event is notified to the ISO layer, the
    bis connections will be added to the accept queue of the PA sync parent.
    The user should call accept on the PA sync socket to get the final bis
    connections.

    Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-01-11 16:47:25 +01:00
Bastien Nocera c598950a24 Bluetooth: hci_codec: Fix leaking content of local_codecs
JIRA: https://issues.redhat.com/browse/RHEL-17138

commit b938790e70540bf4f2e653dcd74b232494d06c8f
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Date:   Fri Sep 15 13:24:47 2023 -0700

    Bluetooth: hci_codec: Fix leaking content of local_codecs

    The following memory leak can be observed when the controller supports
    codecs which are stored in local_codecs list but the elements are never
    freed:

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

    Cc: stable@vger.kernel.org
    Fixes: 8961987f3f5f ("Bluetooth: Enumerate local supported codec and cache details")
    Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Signed-off-by: Bastien Nocera <bnocera@redhat.com>
2024-01-11 16:47:24 +01:00