linux-stable/net/bluetooth
Bastien Nocera 18e189442a Bluetooth: Fix TOCTOU in HCI debugfs implementation
commit 7835fcfd13 upstream.

struct hci_dev members conn_info_max_age, conn_info_min_age,
le_conn_max_interval, le_conn_min_interval, le_adv_max_interval,
and le_adv_min_interval can be modified from the HCI core code, as well
through debugfs.

The debugfs implementation, that's only available to privileged users,
will check for boundaries, making sure that the minimum value being set
is strictly above the maximum value that already exists, and vice-versa.

However, as both minimum and maximum values can be changed concurrently
to us modifying them, we need to make sure that the value we check is
the value we end up using.

For example, with ->conn_info_max_age set to 10, conn_info_min_age_set()
gets called from vfs handlers to set conn_info_min_age to 8.

In conn_info_min_age_set(), this goes through:
	if (val == 0 || val > hdev->conn_info_max_age)
		return -EINVAL;

Concurrently, conn_info_max_age_set() gets called to set to set the
conn_info_max_age to 7:
	if (val == 0 || val > hdev->conn_info_max_age)
		return -EINVAL;
That check will also pass because we used the old value (10) for
conn_info_max_age.

After those checks that both passed, the struct hci_dev access
is mutex-locked, disabling concurrent access, but that does not matter
because the invalid value checks both passed, and we'll end up with
conn_info_min_age = 8 and conn_info_max_age = 7

To fix this problem, we need to lock the structure access before so the
check and assignment are not interrupted.

This fix was originally devised by the BassCheck[1] team, and
considered the problem to be an atomicity one. This isn't the case as
there aren't any concerns about the variable changing while we check it,
but rather after we check it parallel to another change.

This patch fixes CVE-2024-24858 and CVE-2024-24857.

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

Co-developed-by: Gui-Dong Han <2045gemini@gmail.com>
Signed-off-by: Gui-Dong Han <2045gemini@gmail.com>
Link: https://lore.kernel.org/linux-bluetooth/20231222161317.6255-1-2045gemini@gmail.com/
Link: https://nvd.nist.gov/vuln/detail/CVE-2024-24858
Link: https://lore.kernel.org/linux-bluetooth/20231222162931.6553-1-2045gemini@gmail.com/
Link: https://lore.kernel.org/linux-bluetooth/20231222162310.6461-1-2045gemini@gmail.com/
Link: https://nvd.nist.gov/vuln/detail/CVE-2024-24857
Fixes: 31ad169148 ("Bluetooth: Add conn info lifetime parameters to debugfs")
Fixes: 729a1051da ("Bluetooth: Expose default LE advertising interval via debugfs")
Fixes: 71c3b60ec6 ("Bluetooth: Move BR/EDR debugfs file creation into hci_debugfs.c")
Signed-off-by: Bastien Nocera <hadess@hadess.net>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-10 16:28:24 +02:00
..
bnep bluetooth: Use netif_rx(). 2022-03-07 11:40:41 +00:00
cmtp Merge branch 'signal-for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace 2022-01-17 05:49:30 +02:00
hidp Bluetooth: Fix race condition in hidp_session_thread 2023-04-20 12:35:06 +02:00
rfcomm Bluetooth: rfcomm: Fix null-ptr-deref in rfcomm_check_security 2024-03-26 18:20:27 -04:00
6lowpan.c use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
Kconfig Bluetooth: Add initial implementation of CIS connections 2022-07-22 17:13:22 -07:00
Makefile Bluetooth: Add BTPROTO_ISO socket type 2022-07-22 17:13:39 -07:00
a2mp.c use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
a2mp.h
af_bluetooth.c Bluetooth: af_bluetooth: Fix deadlock 2024-03-26 18:20:40 -04:00
amp.c
amp.h
aosp.c Bluetooth: Fix null pointer deref on unexpected status event 2022-08-08 17:04:37 -07:00
aosp.h Bluetooth: aosp: Support AOSP Bluetooth Quality Report 2021-11-02 19:37:52 +01:00
ecdh_helper.c
ecdh_helper.h
eir.c Bluetooth: Fix eir name length 2024-03-26 18:20:42 -04:00
eir.h Bluetooth: Add initial implementation of BIS connections 2022-07-22 17:13:56 -07:00
hci_codec.c Bluetooth: Fix support for Read Local Supported Codecs V2 2022-12-02 13:09:31 -08:00
hci_codec.h
hci_conn.c Bluetooth: hci_sync: Fix overwriting request callback 2024-03-26 18:20:40 -04:00
hci_core.c Bluetooth: hci_sync: Fix not checking error on hci_cmd_sync_cancel_sync 2024-04-03 15:19:50 +02:00
hci_debugfs.c Bluetooth: Fix TOCTOU in HCI debugfs implementation 2024-04-10 16:28:24 +02:00
hci_debugfs.h Bluetooth: hci_core: Move all debugfs handling to hci_debugfs.c 2021-09-22 16:17:13 +02:00
hci_event.c Bluetooth: hci_event: set the conn encrypted before conn establishes 2024-04-10 16:28:24 +02:00
hci_request.c Bluetooth: hci_core: Cancel request on command timeout 2024-03-26 18:20:40 -04:00
hci_request.h Bluetooth: Delete unused hci_req_prepare_suspend() declaration 2023-10-10 22:00:40 +02:00
hci_sock.c Bluetooth: hci_sock: Correctly bounds check and pad HCI_MON_NEW_INDEX name 2023-10-25 12:03:16 +02:00
hci_sync.c Bluetooth: add quirk for broken address properties 2024-04-10 16:28:24 +02:00
hci_sysfs.c Bluetooth: Fix double free in hci_conn_cleanup 2023-11-28 17:06:56 +00:00
iso.c Bluetooth: ISO: Fix handling of listen for unicast 2023-10-10 22:00:40 +02:00
l2cap_core.c Bluetooth: Enforce validation on max value of connection interval 2024-03-06 14:45:07 +00:00
l2cap_sock.c Bluetooth: L2CAP: Fix use-after-free in l2cap_sock_ready_cb 2023-08-11 12:08:23 +02:00
leds.c
leds.h
lib.c Bluetooth: Fix EALREADY and ELOOP cases in bt_status() 2022-12-31 13:32:28 +01:00
mgmt.c Bluetooth: Fix eir name length 2024-03-26 18:20:42 -04:00
mgmt_config.c
mgmt_config.h
mgmt_util.c Bluetooth: Implement support for Mesh 2022-09-06 13:18:24 -07:00
mgmt_util.h Bluetooth: Fix a buffer overflow in mgmt_mesh_add() 2023-02-01 08:34:21 +01:00
msft.c Bluetooth: Fix null pointer deref on unexpected status event 2022-08-08 17:04:37 -07:00
msft.h Bluetooth: hci_sync: Refactor remove Adv Monitor 2022-07-21 17:14:55 -07:00
sco.c net: annotate data-races around sk->sk_lingertime 2023-09-13 09:42:33 +02:00
selftest.c
selftest.h
smp.c Bluetooth: MGMT/SMP: Fix address type when using SMP over BREDR/LE 2024-01-01 12:39:03 +00:00
smp.h