Blame SOURCES/CVE-2022-3564.patch

c5c6e7
From 63f63d3ce535ca59a9da05ba3004187033495b7d Mon Sep 17 00:00:00 2001
c5c6e7
From: Ryan Sullivan <rysulliv@redhat.com>
c5c6e7
Date: Mon, 23 Jan 2023 11:41:37 -0500
c5c6e7
Subject: [KPATCH CVE-2022-3564] kpatch fixes for CVE-2022-3564
c5c6e7
c5c6e7
Kernels:
c5c6e7
3.10.0-1160.71.1.el7
c5c6e7
3.10.0-1160.76.1.el7
c5c6e7
3.10.0-1160.80.1.el7
c5c6e7
3.10.0-1160.81.1.el7
c5c6e7
c5c6e7
c5c6e7
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-7/-/merge_requests/49
c5c6e7
Approved-by: Yannick Cote (@ycote1)
c5c6e7
Approved-by: Joe Lawrence (@joe.lawrence)
c5c6e7
Changes since last build:
c5c6e7
[x86_64]:
c5c6e7
l2cap_core.o: changed function: l2cap_data_channel
c5c6e7
l2cap_core.o: changed function: l2cap_rx_state_recv
c5c6e7
nf_tables_api.o: changed function: __nf_tables_abort
c5c6e7
nf_tables_api.o: changed function: nf_tables_delsetelem
c5c6e7
nf_tables_api.o: changed function: nf_tables_newset
c5c6e7
nf_tables_api.o: changed function: nft_delrule
c5c6e7
nf_tables_api.o: changed function: nft_set_destroy
c5c6e7
nf_tables_api.o: changed function: nft_validate_register_store
c5c6e7
nf_tables_api.o: new function: nf_tables_activate_set
c5c6e7
nf_tables_api.o: new function: nf_tables_deactivate_set
c5c6e7
nf_tables_api.o: new function: nft_rule_expr_deactivate
c5c6e7
nft_dynset.o: new function: klp_is_nft_dynset
c5c6e7
nft_dynset.o: new function: nft_dynset_activate
c5c6e7
nft_dynset.o: new function: nft_dynset_deactivate
c5c6e7
nft_lookup.o: new function: klp_is_nft_lookup
c5c6e7
nft_lookup.o: new function: nft_lookup_activate
c5c6e7
nft_lookup.o: new function: nft_lookup_deactivate
c5c6e7
c5c6e7
[ppc64le]:
c5c6e7
l2cap_core.o: changed function: l2cap_data_channel
c5c6e7
l2cap_core.o: changed function: l2cap_rx_state_recv
c5c6e7
nf_tables_api.o: changed function: __nf_tables_abort
c5c6e7
nf_tables_api.o: changed function: nf_tables_bind_check_setelem
c5c6e7
nf_tables_api.o: changed function: nf_tables_bind_set
c5c6e7
nf_tables_api.o: changed function: nf_tables_commit
c5c6e7
nf_tables_api.o: changed function: nf_tables_delrule
c5c6e7
nf_tables_api.o: changed function: nf_tables_delsetelem
c5c6e7
nf_tables_api.o: changed function: nf_tables_newset
c5c6e7
nf_tables_api.o: changed function: nf_tables_unbind_set
c5c6e7
nf_tables_api.o: changed function: nft_add_set_elem
c5c6e7
nf_tables_api.o: changed function: nft_delrule_by_chain
c5c6e7
nf_tables_api.o: changed function: nft_unregister_afinfo
c5c6e7
nf_tables_api.o: changed function: nft_validate_register_store
c5c6e7
nf_tables_api.o: new function: nf_tables_activate_set
c5c6e7
nf_tables_api.o: new function: nf_tables_deactivate_set
c5c6e7
nft_dynset.o: new function: klp_is_nft_dynset
c5c6e7
nft_dynset.o: new function: nft_dynset_activate
c5c6e7
nft_dynset.o: new function: nft_dynset_deactivate
c5c6e7
nft_lookup.o: new function: klp_is_nft_lookup
c5c6e7
nft_lookup.o: new function: nft_lookup_activate
c5c6e7
nft_lookup.o: new function: nft_lookup_deactivate
c5c6e7
c5c6e7
---------------------------
c5c6e7
c5c6e7
Modifications: none
c5c6e7
c5c6e7
commit ce15ab7416bca0378f144b0aa9183abb532bfb7d
c5c6e7
Author: Wander Lairson Costa <wander@redhat.com>
c5c6e7
Date:   Mon Jan 9 14:37:35 2023 -0300
c5c6e7
c5c6e7
    Bluetooth: L2CAP: Fix use-after-free caused by l2cap_reassemble_sdu
c5c6e7
c5c6e7
    Bugzilla: https://bugzilla.redhat.com/2152941
c5c6e7
    CVE: CVE-2022-3564
c5c6e7
c5c6e7
    commit 3aff8aaca4e36dc8b17eaa011684881a80238966
c5c6e7
    Author: Maxim Mikityanskiy <maxtram95@gmail.com>
c5c6e7
    Date:   Wed Oct 5 00:27:18 2022 +0300
c5c6e7
c5c6e7
        Bluetooth: L2CAP: Fix use-after-free caused by l2cap_reassemble_sdu
c5c6e7
c5c6e7
        Fix the race condition between the following two flows that run in
c5c6e7
        parallel:
c5c6e7
c5c6e7
        1. l2cap_reassemble_sdu -> chan->ops->recv (l2cap_sock_recv_cb) ->
c5c6e7
           __sock_queue_rcv_skb.
c5c6e7
c5c6e7
        2. bt_sock_recvmsg -> skb_recv_datagram, skb_free_datagram.
c5c6e7
c5c6e7
        An SKB can be queued by the first flow and immediately dequeued and
c5c6e7
        freed by the second flow, therefore the callers of l2cap_reassemble_sdu
c5c6e7
        can't use the SKB after that function returns. However, some places
c5c6e7
        continue accessing struct l2cap_ctrl that resides in the SKB's CB for a
c5c6e7
        short time after l2cap_reassemble_sdu returns, leading to a
c5c6e7
        use-after-free condition (the stack trace is below, line numbers for
c5c6e7
        kernel 5.19.8).
c5c6e7
c5c6e7
        Fix it by keeping a local copy of struct l2cap_ctrl.
c5c6e7
c5c6e7
        BUG: KASAN: use-after-free in l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
c5c6e7
        Read of size 1 at addr ffff88812025f2f0 by task kworker/u17:3/43169
c5c6e7
c5c6e7
        Workqueue: hci0 hci_rx_work [bluetooth]
c5c6e7
        Call Trace:
c5c6e7
         <TASK>
c5c6e7
         dump_stack_lvl (lib/dump_stack.c:107 (discriminator 4))
c5c6e7
         print_report.cold (mm/kasan/report.c:314 mm/kasan/report.c:429)
c5c6e7
         ? l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
c5c6e7
         kasan_report (mm/kasan/report.c:162 mm/kasan/report.c:493)
c5c6e7
         ? l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
c5c6e7
         l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
c5c6e7
         l2cap_rx (net/bluetooth/l2cap_core.c:7236 net/bluetooth/l2cap_core.c:7271) bluetooth
c5c6e7
         ret_from_fork (arch/x86/entry/entry_64.S:306)
c5c6e7
         </TASK>
c5c6e7
c5c6e7
        Allocated by task 43169:
c5c6e7
         kasan_save_stack (mm/kasan/common.c:39)
c5c6e7
         __kasan_slab_alloc (mm/kasan/common.c:45 mm/kasan/common.c:436 mm/kasan/common.c:469)
c5c6e7
         kmem_cache_alloc_node (mm/slab.h:750 mm/slub.c:3243 mm/slub.c:3293)
c5c6e7
         __alloc_skb (net/core/skbuff.c:414)
c5c6e7
         l2cap_recv_frag (./include/net/bluetooth/bluetooth.h:425 net/bluetooth/l2cap_core.c:8329) bluetooth
c5c6e7
         l2cap_recv_acldata (net/bluetooth/l2cap_core.c:8442) bluetooth
c5c6e7
         hci_rx_work (net/bluetooth/hci_core.c:3642 net/bluetooth/hci_core.c:3832) bluetooth
c5c6e7
         process_one_work (kernel/workqueue.c:2289)
c5c6e7
         worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2437)
c5c6e7
         kthread (kernel/kthread.c:376)
c5c6e7
         ret_from_fork (arch/x86/entry/entry_64.S:306)
c5c6e7
c5c6e7
        Freed by task 27920:
c5c6e7
         kasan_save_stack (mm/kasan/common.c:39)
c5c6e7
         kasan_set_track (mm/kasan/common.c:45)
c5c6e7
         kasan_set_free_info (mm/kasan/generic.c:372)
c5c6e7
         ____kasan_slab_free (mm/kasan/common.c:368 mm/kasan/common.c:328)
c5c6e7
         slab_free_freelist_hook (mm/slub.c:1780)
c5c6e7
         kmem_cache_free (mm/slub.c:3536 mm/slub.c:3553)
c5c6e7
         skb_free_datagram (./include/net/sock.h:1578 ./include/net/sock.h:1639 net/core/datagram.c:323)
c5c6e7
         bt_sock_recvmsg (net/bluetooth/af_bluetooth.c:295) bluetooth
c5c6e7
         l2cap_sock_recvmsg (net/bluetooth/l2cap_sock.c:1212) bluetooth
c5c6e7
         sock_read_iter (net/socket.c:1087)
c5c6e7
         new_sync_read (./include/linux/fs.h:2052 fs/read_write.c:401)
c5c6e7
         vfs_read (fs/read_write.c:482)
c5c6e7
         ksys_read (fs/read_write.c:620)
c5c6e7
         do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80)
c5c6e7
         entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120)
c5c6e7
c5c6e7
        Link: https://lore.kernel.org/linux-bluetooth/CAKErNvoqga1WcmoR3-0875esY6TVWFQDandbVZncSiuGPBQXLA@mail.gmail.com/T/#u
c5c6e7
        Fixes: d2a7ac5d5d3a ("Bluetooth: Add the ERTM receive state machine")
c5c6e7
        Fixes: 4b51dae96731 ("Bluetooth: Add streaming mode receive and incoming packet classifier")
c5c6e7
        Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
c5c6e7
        Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
c5c6e7
c5c6e7
    Signed-off-by: Wander Lairson Costa <wander@redhat.com>
c5c6e7
c5c6e7
Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
c5c6e7
---
c5c6e7
 net/bluetooth/l2cap_core.c | 48 ++++++++++++++++++++++++++++++++------
c5c6e7
 1 file changed, 41 insertions(+), 7 deletions(-)
c5c6e7
c5c6e7
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
c5c6e7
index 6e94fd907d89..4338810b0d58 100644
c5c6e7
--- a/net/bluetooth/l2cap_core.c
c5c6e7
+++ b/net/bluetooth/l2cap_core.c
c5c6e7
@@ -6197,6 +6197,7 @@ static int l2cap_rx_state_recv(struct l2cap_chan *chan,
c5c6e7
 			       struct l2cap_ctrl *control,
c5c6e7
 			       struct sk_buff *skb, u8 event)
c5c6e7
 {
c5c6e7
+	struct l2cap_ctrl local_control;
c5c6e7
 	int err = 0;
c5c6e7
 	bool skb_in_use = false;
c5c6e7
 
c5c6e7
@@ -6221,15 +6222,32 @@ static int l2cap_rx_state_recv(struct l2cap_chan *chan,
c5c6e7
 			chan->buffer_seq = chan->expected_tx_seq;
c5c6e7
 			skb_in_use = true;
c5c6e7
 
c5c6e7
+			/* l2cap_reassemble_sdu may free skb, hence invalidate
c5c6e7
+			 * control, so make a copy in advance to use it after
c5c6e7
+			 * l2cap_reassemble_sdu returns and to avoid the race
c5c6e7
+			 * condition, for example:
c5c6e7
+			 *
c5c6e7
+			 * The current thread calls:
c5c6e7
+			 *   l2cap_reassemble_sdu
c5c6e7
+			 *     chan->ops->recv == l2cap_sock_recv_cb
c5c6e7
+			 *       __sock_queue_rcv_skb
c5c6e7
+			 * Another thread calls:
c5c6e7
+			 *   bt_sock_recvmsg
c5c6e7
+			 *     skb_recv_datagram
c5c6e7
+			 *     skb_free_datagram
c5c6e7
+			 * Then the current thread tries to access control, but
c5c6e7
+			 * it was freed by skb_free_datagram.
c5c6e7
+			 */
c5c6e7
+			local_control = *control;
c5c6e7
 			err = l2cap_reassemble_sdu(chan, skb, control);
c5c6e7
 			if (err)
c5c6e7
 				break;
c5c6e7
 
c5c6e7
-			if (control->final) {
c5c6e7
+			if (local_control.final) {
c5c6e7
 				if (!test_and_clear_bit(CONN_REJ_ACT,
c5c6e7
 							&chan->conn_state)) {
c5c6e7
-					control->final = 0;
c5c6e7
-					l2cap_retransmit_all(chan, control);
c5c6e7
+					local_control.final = 0;
c5c6e7
+					l2cap_retransmit_all(chan, &local_control);
c5c6e7
 					l2cap_ertm_send(chan);
c5c6e7
 				}
c5c6e7
 			}
c5c6e7
@@ -6609,11 +6627,27 @@ static int l2cap_rx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
c5c6e7
 static int l2cap_stream_rx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
c5c6e7
 			   struct sk_buff *skb)
c5c6e7
 {
c5c6e7
+	/* l2cap_reassemble_sdu may free skb, hence invalidate control, so store
c5c6e7
+	 * the txseq field in advance to use it after l2cap_reassemble_sdu
c5c6e7
+	 * returns and to avoid the race condition, for example:
c5c6e7
+	 *
c5c6e7
+	 * The current thread calls:
c5c6e7
+	 *   l2cap_reassemble_sdu
c5c6e7
+	 *     chan->ops->recv == l2cap_sock_recv_cb
c5c6e7
+	 *       __sock_queue_rcv_skb
c5c6e7
+	 * Another thread calls:
c5c6e7
+	 *   bt_sock_recvmsg
c5c6e7
+	 *     skb_recv_datagram
c5c6e7
+	 *     skb_free_datagram
c5c6e7
+	 * Then the current thread tries to access control, but it was freed by
c5c6e7
+	 * skb_free_datagram.
c5c6e7
+	 */
c5c6e7
+	u16 txseq = control->txseq;
c5c6e7
+
c5c6e7
 	BT_DBG("chan %p, control %p, skb %p, state %d", chan, control, skb,
c5c6e7
 	       chan->rx_state);
c5c6e7
 
c5c6e7
-	if (l2cap_classify_txseq(chan, control->txseq) ==
c5c6e7
-	    L2CAP_TXSEQ_EXPECTED) {
c5c6e7
+	if (l2cap_classify_txseq(chan, txseq) == L2CAP_TXSEQ_EXPECTED) {
c5c6e7
 		l2cap_pass_to_tx(chan, control);
c5c6e7
 
c5c6e7
 		BT_DBG("buffer_seq %d->%d", chan->buffer_seq,
c5c6e7
@@ -6636,8 +6670,8 @@ static int l2cap_stream_rx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
c5c6e7
 		}
c5c6e7
 	}
c5c6e7
 
c5c6e7
-	chan->last_acked_seq = control->txseq;
c5c6e7
-	chan->expected_tx_seq = __next_seq(chan, control->txseq);
c5c6e7
+	chan->last_acked_seq = txseq;
c5c6e7
+	chan->expected_tx_seq = __next_seq(chan, txseq);
c5c6e7
 
c5c6e7
 	return 0;
c5c6e7
 }
c5c6e7
-- 
c5c6e7
2.40.1
c5c6e7
c5c6e7