Blame SOURCES/CVE-2021-32399.patch

db14cb
From d50512e6312824861ce342eb68bb1eb7dea984e2 Mon Sep 17 00:00:00 2001
db14cb
From: Artem Savkov <asavkov@redhat.com>
db14cb
Date: Mon, 21 Jun 2021 12:09:28 +0200
db14cb
Subject: [PATCH] bluetooth: eliminate the potential race condition when
db14cb
 removing the HCI controller
db14cb
db14cb
Kernels:
db14cb
4.18.0-305.el8
db14cb
4.18.0-305.3.1.el8_4
db14cb
4.18.0-305.7.1.el8_4
db14cb
db14cb
Changes since last build:
db14cb
[x86_64]:
db14cb
hci_request.o: changed function: hci_req_sync
db14cb
db14cb
[ppc64le]:
db14cb
hci_request.o: changed function: bg_scan_update
db14cb
hci_request.o: changed function: connectable_update_work
db14cb
hci_request.o: changed function: discov_off
db14cb
hci_request.o: changed function: discov_update
db14cb
hci_request.o: changed function: discoverable_update_work
db14cb
hci_request.o: changed function: hci_req_sync
db14cb
hci_request.o: changed function: le_scan_disable_work
db14cb
hci_request.o: changed function: le_scan_restart_work
db14cb
hci_request.o: changed function: scan_update_work
db14cb
db14cb
---------------------------
db14cb
db14cb
Kernels:
db14cb
4.18.0-305.el8
db14cb
4.18.0-305.3.1.el8_4
db14cb
4.18.0-305.7.1.el8_4
db14cb
db14cb
Modifications: none
db14cb
Z-MR: https://gitlab.com/redhat/rhel/src/kernel/rhel-8/-/merge_requests/804
db14cb
db14cb
commit 84466ca3bdf0d5d77d4c8a851336406627de2628
db14cb
Author: Gopal Tiwari <gtiwari@redhat.com>
db14cb
Date:   Mon Jun 14 13:47:30 2021 +0530
db14cb
db14cb
    bluetooth: eliminate the potential race condition when removing the HCI controller
db14cb
db14cb
    Bugzilla: https://bugzilla.redhat.com/1971464
db14cb
    CVE: CVE-2021-32399
db14cb
    Y-Commit: 54c81477df19422cbc3c8cf3b555159ff642f15b
db14cb
db14cb
    O-Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1971488
db14cb
db14cb
    Upstream: Merged
db14cb
db14cb
    Testing: Sanity_only.
db14cb
db14cb
    commit e2cb6b891ad2b8caa9131e3be70f45243df82a80
db14cb
    Author: Lin Ma <linma@zju.edu.cn>
db14cb
    Date:   Mon Apr 12 19:17:57 2021 +0800
db14cb
db14cb
    bluetooth: eliminate the potential race condition when removing the HCI controller
db14cb
db14cb
    There is a possible race condition vulnerability between issuing a HCI
db14cb
    command and removing the cont.  Specifically, functions hci_req_sync()
db14cb
    and hci_dev_do_close() can race each other like below:
db14cb
db14cb
    thread-A in hci_req_sync()      |   thread-B in hci_dev_do_close()
db14cb
                                    |   hci_req_sync_lock(hdev);
db14cb
    test_bit(HCI_UP, &hdev->flags); |
db14cb
    ...                             |   test_and_clear_bit(HCI_UP, &hdev->flags)
db14cb
    hci_req_sync_lock(hdev);        |
db14cb
                                    |
db14cb
    In this commit we alter the sequence in function hci_req_sync(). Hence,
db14cb
    the thread-A cannot issue th.
db14cb
db14cb
    Signed-off-by: Lin Ma <linma@zju.edu.cn>
db14cb
    Cc: Marcel Holtmann <marcel@holtmann.org>
db14cb
    Fixes: 7c6a329e4447 ("[Bluetooth] Fix regression from using default link policy")
db14cb
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
db14cb
    (cherry picked from commit e2cb6b891ad2b8caa9131e3be70f45243df82a80)
db14cb
    Signed-off-by: Gopal Tiwari <gtiwari@redhat.com>
db14cb
    Signed-off-by: Jan Stancek <jstancek@redhat.com>
db14cb
db14cb
Signed-off-by: Artem Savkov <asavkov@redhat.com>
db14cb
Acked-by: Yannick Cote <ycote@redhat.com>
db14cb
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
db14cb
---
db14cb
 net/bluetooth/hci_request.c | 12 ++++++++----
db14cb
 1 file changed, 8 insertions(+), 4 deletions(-)
db14cb
db14cb
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
db14cb
index cf1b42ec40af97..ca9088d439460e 100644
db14cb
--- a/net/bluetooth/hci_request.c
db14cb
+++ b/net/bluetooth/hci_request.c
db14cb
@@ -274,12 +274,16 @@ int hci_req_sync(struct hci_dev *hdev, int (*req)(struct hci_request *req,
db14cb
 {
db14cb
 	int ret;
db14cb
 
db14cb
-	if (!test_bit(HCI_UP, &hdev->flags))
db14cb
-		return -ENETDOWN;
db14cb
-
db14cb
 	/* Serialize all requests */
db14cb
 	hci_req_sync_lock(hdev);
db14cb
-	ret = __hci_req_sync(hdev, req, opt, timeout, hci_status);
db14cb
+	/* check the state after obtaing the lock to protect the HCI_UP
db14cb
+	 * against any races from hci_dev_do_close when the controller
db14cb
+	 * gets removed.
db14cb
+	 */
db14cb
+	if (test_bit(HCI_UP, &hdev->flags))
db14cb
+		ret = __hci_req_sync(hdev, req, opt, timeout, hci_status);
db14cb
+	else
db14cb
+		ret = -ENETDOWN;
db14cb
 	hci_req_sync_unlock(hdev);
db14cb
 
db14cb
 	return ret;
db14cb
-- 
db14cb
2.26.3
db14cb