anolis-cloud-kernel/net/bluetooth
Yuxuan Hu 60e855a538 Bluetooth: rfcomm: Fix null-ptr-deref in rfcomm_check_security
ANBZ: #8097

commit 2535b848fa upstream.

During our fuzz testing of the connection and disconnection process at the
RFCOMM layer, we discovered this bug. By comparing the packets from a
normal connection and disconnection process with the testcase that
triggered a KASAN report. We analyzed the cause of this bug as follows:

1. In the packets captured during a normal connection, the host sends a
`Read Encryption Key Size` type of `HCI_CMD` packet
(Command Opcode: 0x1408) to the controller to inquire the length of
encryption key.After receiving this packet, the controller immediately
replies with a Command Completepacket (Event Code: 0x0e) to return the
Encryption Key Size.

2. In our fuzz test case, the timing of the controller's response to this
packet was delayed to an unexpected point: after the RFCOMM and L2CAP
layers had disconnected but before the HCI layer had disconnected.

3. After receiving the Encryption Key Size Response at the time described
in point 2, the host still called the rfcomm_check_security function.
However, by this time `struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;`
had already been released, and when the function executed
`return hci_conn_security(conn->hcon, d->sec_level, auth_type, d->out);`,
specifically when accessing `conn->hcon`, a null-ptr-deref error occurred.

To fix this bug, check if `sk->sk_state` is BT_CLOSED before calling
rfcomm_recv_frame in rfcomm_process_rx.

Signed-off-by: Yuxuan Hu <20373622@buaa.edu.cn>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Fixes: CVE-2024-22099
Signed-off-by: Xiao Long <xiaolong@openanolis.org>
Signed-off-by: Philo Lu <lulie@linux.alibaba.com>
Reviewed-by: D. Wythe <alibuda@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/2864
2024-03-11 12:31:16 +00:00
..
bnep net: remove sock_no_poll 2018-05-26 09:16:44 +02:00
cmtp Merge branch 'work.aio-1' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2018-06-04 13:57:43 -07:00
hidp Bluetooth: hidp: fix buffer overflow 2019-05-10 17:54:11 +02:00
rfcomm Bluetooth: rfcomm: Fix null-ptr-deref in rfcomm_check_security 2024-03-11 12:31:16 +00:00
6lowpan.c iov_iter: Separate type from direction and use accessor functions 2020-01-17 16:08:03 +08:00
Kconfig Revert "Bluetooth: Add option for disabling legacy ioctl interfaces" 2017-09-28 13:20:32 -07:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
a2mp.c iov_iter: Separate type from direction and use accessor functions 2020-01-17 16:08:03 +08:00
a2mp.h Bluetooth: Add BT_HS config option 2015-07-30 13:31:59 +02:00
af_bluetooth.c Bluetooth: af_bluetooth: Fix Use-After-Free in bt_sock_recvmsg 2024-03-11 12:27:09 +00:00
amp.c Bluetooth: Use bt_dev_err and bt_dev_info when possible 2017-10-30 12:25:45 +02:00
amp.h Bluetooth: Add BT_HS config option 2015-07-30 13:31:59 +02:00
ecdh_helper.c Bluetooth: let the crypto subsystem generate the ecc privkey 2017-10-06 20:35:47 +02:00
ecdh_helper.h Bluetooth: let the crypto subsystem generate the ecc privkey 2017-10-06 20:35:47 +02:00
hci_conn.c Bluetooth: Fix regression with minimum encryption key size alignment 2019-06-25 11:36:01 +08:00
hci_core.c Bluetooth: fix the erroneous flush_work() order 2021-10-29 10:12:39 +08:00
hci_debugfs.c Bluetooth: Store Resolv list size 2018-07-06 12:40:08 +02:00
hci_debugfs.h Bluetooth: Provide option to enable/disable debugfs information 2015-02-15 18:54:13 +02:00
hci_event.c Bluetooth: verify AMP hci_chan before amp_destroy 2021-10-29 10:12:38 +08:00
hci_request.c bluetooth: eliminate the potential race condition when removing the HCI controller 2021-10-29 10:12:38 +08:00
hci_request.h Bluetooth: Ignore CC events not matching the last HCI command 2019-05-31 06:46:09 -07:00
hci_sock.c bluetooth: Perform careful capability checks in hci_sock_ioctl() 2024-01-12 08:11:25 +00:00
hci_sysfs.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-11-04 09:26:51 +09:00
l2cap_core.c Bluetooth: L2CAP: Fix u8 overflow 2023-03-29 09:17:24 +00:00
l2cap_sock.c Bluetooth: Fix locking in bt_accept_enqueue() for BH context 2019-03-10 07:17:21 +01:00
leds.c leds: triggers: let struct led_trigger::activate() return an error code 2018-07-05 23:21:10 +02:00
leds.h Bluetooth: Add combined LED trigger for controller power 2016-09-19 20:19:34 +02:00
lib.c Bluetooth: make baswap src const 2017-09-01 22:49:47 +02:00
mgmt.c Bluetooth: SMP: fix crash in unpairing 2018-09-26 12:39:32 +03:00
mgmt_util.c networking: make skb_push & __skb_push return void pointers 2017-06-16 11:48:40 -04:00
mgmt_util.h Bluetooth: Add generic mgmt helper API 2015-03-17 18:03:08 +01:00
sco.c Bluetooth: Fix locking in bt_accept_enqueue() for BH context 2019-03-10 07:17:21 +01:00
selftest.c Bluetooth: Fix compiler warning with selftest duration calculation 2017-10-06 21:49:13 +03:00
selftest.h Bluetooth: Add support for self testing framework 2014-12-30 08:53:55 +02:00
smp.c Bluetooth: SMP: Fail if remote and local public keys are identical 2021-10-29 10:12:38 +08:00
smp.h Bluetooth: SMP: fix crash in unpairing 2018-09-26 12:39:32 +03:00