kernel_samsung_a53x/net/bluetooth
Gui-Dong Han f8b9ebd7f6 Bluetooth: Fix atomicity violation in {min,max}_key_size_set
commit da9065caa594d19b26e1a030fd0cc27bd365d685 upstream.

In min_key_size_set():
    if (val > hdev->le_max_key_size || val < SMP_MIN_ENC_KEY_SIZE)
        return -EINVAL;
    hci_dev_lock(hdev);
    hdev->le_min_key_size = val;
    hci_dev_unlock(hdev);

In max_key_size_set():
    if (val > SMP_MAX_ENC_KEY_SIZE || val < hdev->le_min_key_size)
        return -EINVAL;
    hci_dev_lock(hdev);
    hdev->le_max_key_size = val;
    hci_dev_unlock(hdev);

The atomicity violation occurs due to concurrent execution of set_min and
set_max funcs.Consider a scenario where setmin writes a new, valid 'min'
value, and concurrently, setmax writes a value that is greater than the
old 'min' but smaller than the new 'min'. In this case, setmax might check
against the old 'min' value (before acquiring the lock) but write its
value after the 'min' has been updated by setmin. This leads to a
situation where the 'max' value ends up being smaller than the 'min'
value, which is an inconsistency.

This possible bug is found by an experimental static analysis tool
developed by our team, BassCheck[1]. This tool analyzes the locking APIs
to extract function pairs that can be concurrently executed, and then
analyzes the instructions in the paired functions to identify possible
concurrency bugs including data races and atomicity violations. The above
possible bug is reported when our tool analyzes the source code of
Linux 5.17.

To resolve this issue, it is suggested to encompass the validity checks
within the locked sections in both set_min and set_max funcs. The
modification ensures that the validation of 'val' against the
current min/max values is atomic, thus maintaining the integrity of the
settings. With this patch applied, our tool no longer reports the bug,
with the kernel configuration allyesconfig for x86_64. Due to the lack of
associated hardware, we cannot test the patch in runtime testing, and just
verify it according to the code logic.

[1] https://sites.google.com/view/basscheck/

Fixes: 18f81241b74f ("Bluetooth: Move {min,max}_key_size debugfs ...")
Cc: stable@vger.kernel.org
Signed-off-by: Gui-Dong Han <2045gemini@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-18 12:12:47 +01:00
..
bnep Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cmtp Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hidp Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rfcomm Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
6lowpan.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
a2mp.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
a2mp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
af_bluetooth.c Bluetooth: af_bluetooth: Fix Use-After-Free in bt_sock_recvmsg 2024-11-18 12:12:02 +01:00
amp.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
amp.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ecdh_helper.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ecdh_helper.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hci_conn.c Bluetooth: Fix bogus check for re-auth no supported with non-ssp 2024-11-18 12:12:38 +01:00
hci_core.c Bluetooth: hci_core: Fix build warnings 2024-11-08 11:26:16 +01:00
hci_debugfs.c Bluetooth: Fix atomicity violation in {min,max}_key_size_set 2024-11-18 12:12:47 +01:00
hci_debugfs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hci_event.c Bluetooth: Fix bogus check for re-auth no supported with non-ssp 2024-11-18 12:12:38 +01:00
hci_request.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hci_request.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hci_sock.c Bluetooth: hci_sock: Correctly bounds check and pad HCI_MON_NEW_INDEX name 2024-11-08 11:26:20 +01:00
hci_sysfs.c Bluetooth: Fix double free in hci_conn_cleanup 2024-11-18 11:43:12 +01:00
Kconfig Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
l2cap_core.c Bluetooth: L2CAP: Send reject on command corrupted request 2024-11-18 12:12:01 +01:00
l2cap_sock.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
leds.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
leds.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lib.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mgmt.c Bluetooth: MGMT/SMP: Fix address type when using SMP over BREDR/LE 2024-11-18 12:12:02 +01:00
mgmt_config.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mgmt_config.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mgmt_util.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mgmt_util.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
msft.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
msft.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sco.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
selftest.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
selftest.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
smp.c Bluetooth: SMP: Fix crash when receiving new connection when debug is enabled 2024-11-18 12:12:04 +01:00
smp.h Bluetooth: use inclusive language in SMP 2024-11-18 12:12:01 +01:00