Blame SOURCES/CVE-2021-32399.patch

2c8af9
From: Artem Savkov <asavkov@redhat.com>
2c8af9
Subject: [RHEL-7.9 CVE-2021-32399 KPATCH] bluetooth: eliminate the potential race condition when removing the HCI controller
2c8af9
Date: Wed,  7 Jul 2021 17:13:32 +0200
2c8af9
2c8af9
Kernels:
2c8af9
3.10.0-1160.el7
2c8af9
3.10.0-1160.2.1.el7
2c8af9
3.10.0-1160.2.2.el7
2c8af9
3.10.0-1160.6.1.el7
2c8af9
3.10.0-1160.11.1.el7
2c8af9
3.10.0-1160.15.2.el7
2c8af9
3.10.0-1160.21.1.el7
2c8af9
3.10.0-1160.24.1.el7
2c8af9
3.10.0-1160.25.1.el7
2c8af9
3.10.0-1160.31.1.el7
2c8af9
2c8af9
Changes since last build:
2c8af9
[x86_64]:
2c8af9
hci_request.o: changed function: hci_req_sync
2c8af9
2c8af9
[ppc64le]:
2c8af9
hci_request.o: changed function: bg_scan_update
2c8af9
hci_request.o: changed function: connectable_update_work
2c8af9
hci_request.o: changed function: discov_off
2c8af9
hci_request.o: changed function: discov_update
2c8af9
hci_request.o: changed function: discoverable_update_work
2c8af9
hci_request.o: changed function: hci_req_sync
2c8af9
hci_request.o: changed function: le_scan_disable_work
2c8af9
hci_request.o: changed function: le_scan_restart_work
2c8af9
hci_request.o: changed function: scan_update_work
2c8af9
2c8af9
---------------------------
2c8af9
2c8af9
Kernels:
2c8af9
3.10.0-1160.el7
2c8af9
3.10.0-1160.2.1.el7
2c8af9
3.10.0-1160.2.2.el7
2c8af9
3.10.0-1160.6.1.el7
2c8af9
3.10.0-1160.11.1.el7
2c8af9
3.10.0-1160.15.2.el7
2c8af9
3.10.0-1160.21.1.el7
2c8af9
3.10.0-1160.24.1.el7
2c8af9
3.10.0-1160.25.1.el7
2c8af9
3.10.0-1160.31.1.el7
2c8af9
3.10.0-1160.36.2.el7
2c8af9
2c8af9
Modifications: none
2c8af9
Z-MR: https://gitlab.com/redhat/rhel/src/kernel/rhel-7/-/merge_requests/171
2c8af9
2c8af9
commit 168b363c94eac82c2e3531bd2ae9dfa2f369d4be
2c8af9
Author: Gopal Tiwari <gtiwari@redhat.com>
2c8af9
Date:   Mon Jun 14 13:04:00 2021 +0530
2c8af9
2c8af9
    bluetooth: eliminate the potential race condition when removing the HCI controller
2c8af9
2c8af9
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1971457
2c8af9
2c8af9
    Upstream: merged.
2c8af9
2c8af9
    Testing: Sanity_only.
2c8af9
2c8af9
    commit e2cb6b891ad2b8caa9131e3be70f45243df82a80
2c8af9
    Author: Lin Ma <linma@zju.edu.cn>
2c8af9
    Date:   Mon Apr 12 19:17:57 2021 +0800
2c8af9
2c8af9
        bluetooth: eliminate the potential race condition when removing the HCI controller
2c8af9
2c8af9
        There is a possible race condition vulnerability between issuing a HCI
2c8af9
        command and removing the cont.  Specifically, functions hci_req_sync()
2c8af9
        and hci_dev_do_close() can race each other like below:
2c8af9
2c8af9
        thread-A in hci_req_sync()      |   thread-B in hci_dev_do_close()
2c8af9
                                        |   hci_req_sync_lock(hdev);
2c8af9
        test_bit(HCI_UP, &hdev->flags); |
2c8af9
        ...                             |   test_and_clear_bit(HCI_UP, &hdev->flags)
2c8af9
        hci_req_sync_lock(hdev);        |
2c8af9
                                        |
2c8af9
        In this commit we alter the sequence in function hci_req_sync(). Hence,
2c8af9
        the thread-A cannot issue th.
2c8af9
2c8af9
        Signed-off-by: Lin Ma <linma@zju.edu.cn>
2c8af9
        Cc: Marcel Holtmann <marcel@holtmann.org>
2c8af9
        Fixes: 7c6a329e4447 ("[Bluetooth] Fix regression from using default link policy")
2c8af9
        Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2c8af9
2c8af9
    Signed-off-by: Gopal Tiwari <gtiwari@redhat.com>
2c8af9
2c8af9
Signed-off-by: Artem Savkov <asavkov@redhat.com>
2c8af9
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
2c8af9
Acked-by: Yannick Cote <ycote@redhat.com>
2c8af9
---
2c8af9
 net/bluetooth/hci_request.c | 12 ++++++++----
2c8af9
 1 file changed, 8 insertions(+), 4 deletions(-)
2c8af9
2c8af9
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
2c8af9
index 1015d9c8d97dd..9e25e77042503 100644
2c8af9
--- a/net/bluetooth/hci_request.c
2c8af9
+++ b/net/bluetooth/hci_request.c
2c8af9
@@ -275,12 +275,16 @@ int hci_req_sync(struct hci_dev *hdev, int (*req)(struct hci_request *req,
2c8af9
 {
2c8af9
 	int ret;
2c8af9
 
2c8af9
-	if (!test_bit(HCI_UP, &hdev->flags))
2c8af9
-		return -ENETDOWN;
2c8af9
-
2c8af9
 	/* Serialize all requests */
2c8af9
 	hci_req_sync_lock(hdev);
2c8af9
-	ret = __hci_req_sync(hdev, req, opt, timeout, hci_status);
2c8af9
+	/* check the state after obtaing the lock to protect the HCI_UP
2c8af9
+	 * against any races from hci_dev_do_close when the controller
2c8af9
+	 * gets removed.
2c8af9
+	 */
2c8af9
+	if (test_bit(HCI_UP, &hdev->flags))
2c8af9
+		ret = __hci_req_sync(hdev, req, opt, timeout, hci_status);
2c8af9
+	else
2c8af9
+		ret = -ENETDOWN;
2c8af9
 	hci_req_sync_unlock(hdev);
2c8af9
 
2c8af9
 	return ret;
2c8af9
-- 
2c8af9
2.26.3
2c8af9
2c8af9