072600
From 71c4471290abc5888cf1cb13a7661e06367d3c5f Mon Sep 17 00:00:00 2001
072600
From: Jamal Hadi Salim <jhs@mojatatu.com>
072600
Date: Sun, 1 Jan 2023 16:57:44 -0500
072600
Subject: [PATCH 1/2] net: sched: cbq: dont intepret cls results when asked to
072600
 drop
072600
Git-commit: caa4b35b4317d5147b3ab0fbdc9c075c7d2e9c12
88c4e7
References: bsc#1207036 CVE-2023-23454
072600
Patch-mainline: v6.2-rc3
072600
072600
If asked to drop a packet via TC_ACT_SHOT it is unsafe to assume that
072600
res.class contains a valid pointer
072600
072600
Sample splat reported by Kyle Zeng
072600
072600
[    5.405624] 0: reclassify loop, rule prio 0, protocol 800
072600
[    5.406326] ==================================================================
072600
[    5.407240] BUG: KASAN: slab-out-of-bounds in cbq_enqueue+0x54b/0xea0
072600
[    5.407987] Read of size 1 at addr ffff88800e3122aa by task poc/299
072600
[    5.408731]
072600
[    5.408897] CPU: 0 PID: 299 Comm: poc Not tainted 5.10.155+ #15
072600
[    5.409516] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
072600
BIOS 1.15.0-1 04/01/2014
072600
[    5.410439] Call Trace:
072600
[    5.410764]  dump_stack+0x87/0xcd
072600
[    5.411153]  print_address_description+0x7a/0x6b0
072600
[    5.411687]  ? vprintk_func+0xb9/0xc0
072600
[    5.411905]  ? printk+0x76/0x96
072600
[    5.412110]  ? cbq_enqueue+0x54b/0xea0
072600
[    5.412323]  kasan_report+0x17d/0x220
072600
[    5.412591]  ? cbq_enqueue+0x54b/0xea0
072600
[    5.412803]  __asan_report_load1_noabort+0x10/0x20
072600
[    5.413119]  cbq_enqueue+0x54b/0xea0
072600
[    5.413400]  ? __kasan_check_write+0x10/0x20
072600
[    5.413679]  __dev_queue_xmit+0x9c0/0x1db0
072600
[    5.413922]  dev_queue_xmit+0xc/0x10
072600
[    5.414136]  ip_finish_output2+0x8bc/0xcd0
072600
[    5.414436]  __ip_finish_output+0x472/0x7a0
072600
[    5.414692]  ip_finish_output+0x5c/0x190
072600
[    5.414940]  ip_output+0x2d8/0x3c0
072600
[    5.415150]  ? ip_mc_finish_output+0x320/0x320
072600
[    5.415429]  __ip_queue_xmit+0x753/0x1760
072600
[    5.415664]  ip_queue_xmit+0x47/0x60
072600
[    5.415874]  __tcp_transmit_skb+0x1ef9/0x34c0
072600
[    5.416129]  tcp_connect+0x1f5e/0x4cb0
072600
[    5.416347]  tcp_v4_connect+0xc8d/0x18c0
072600
[    5.416577]  __inet_stream_connect+0x1ae/0xb40
072600
[    5.416836]  ? local_bh_enable+0x11/0x20
072600
[    5.417066]  ? lock_sock_nested+0x175/0x1d0
072600
[    5.417309]  inet_stream_connect+0x5d/0x90
072600
[    5.417548]  ? __inet_stream_connect+0xb40/0xb40
072600
[    5.417817]  __sys_connect+0x260/0x2b0
072600
[    5.418037]  __x64_sys_connect+0x76/0x80
072600
[    5.418267]  do_syscall_64+0x31/0x50
072600
[    5.418477]  entry_SYSCALL_64_after_hwframe+0x61/0xc6
072600
[    5.418770] RIP: 0033:0x473bb7
072600
[    5.418952] Code: 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00
072600
00 00 90 f3 0f 1e fa 64 8b 04 25 18 00 00 00 85 c0 75 10 b8 2a 00 00
072600
00 0f 05 <48> 3d 00 f0 ff ff 77 51 c3 48 83 ec 18 89 54 24 0c 48 89 34
072600
24 89
072600
[    5.420046] RSP: 002b:00007fffd20eb0f8 EFLAGS: 00000246 ORIG_RAX:
072600
000000000000002a
072600
[    5.420472] RAX: ffffffffffffffda RBX: 00007fffd20eb578 RCX: 0000000000473bb7
072600
[    5.420872] RDX: 0000000000000010 RSI: 00007fffd20eb110 RDI: 0000000000000007
072600
[    5.421271] RBP: 00007fffd20eb150 R08: 0000000000000001 R09: 0000000000000004
072600
[    5.421671] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
072600
[    5.422071] R13: 00007fffd20eb568 R14: 00000000004fc740 R15: 0000000000000002
072600
[    5.422471]
072600
[    5.422562] Allocated by task 299:
072600
[    5.422782]  __kasan_kmalloc+0x12d/0x160
072600
[    5.423007]  kasan_kmalloc+0x5/0x10
072600
[    5.423208]  kmem_cache_alloc_trace+0x201/0x2e0
072600
[    5.423492]  tcf_proto_create+0x65/0x290
072600
[    5.423721]  tc_new_tfilter+0x137e/0x1830
072600
[    5.423957]  rtnetlink_rcv_msg+0x730/0x9f0
072600
[    5.424197]  netlink_rcv_skb+0x166/0x300
072600
[    5.424428]  rtnetlink_rcv+0x11/0x20
072600
[    5.424639]  netlink_unicast+0x673/0x860
072600
[    5.424870]  netlink_sendmsg+0x6af/0x9f0
072600
[    5.425100]  __sys_sendto+0x58d/0x5a0
072600
[    5.425315]  __x64_sys_sendto+0xda/0xf0
072600
[    5.425539]  do_syscall_64+0x31/0x50
072600
[    5.425764]  entry_SYSCALL_64_after_hwframe+0x61/0xc6
072600
[    5.426065]
072600
[    5.426157] The buggy address belongs to the object at ffff88800e312200
072600
[    5.426157]  which belongs to the cache kmalloc-128 of size 128
072600
[    5.426955] The buggy address is located 42 bytes to the right of
072600
[    5.426955]  128-byte region [ffff88800e312200, ffff88800e312280)
072600
[    5.427688] The buggy address belongs to the page:
072600
[    5.427992] page:000000009875fabc refcount:1 mapcount:0
072600
mapping:0000000000000000 index:0x0 pfn:0xe312
072600
[    5.428562] flags: 0x100000000000200(slab)
072600
[    5.428812] raw: 0100000000000200 dead000000000100 dead000000000122
072600
ffff888007843680
072600
[    5.429325] raw: 0000000000000000 0000000000100010 00000001ffffffff
072600
ffff88800e312401
072600
[    5.429875] page dumped because: kasan: bad access detected
072600
[    5.430214] page->mem_cgroup:ffff88800e312401
072600
[    5.430471]
072600
[    5.430564] Memory state around the buggy address:
072600
[    5.430846]  ffff88800e312180: fc fc fc fc fc fc fc fc fc fc fc fc
072600
fc fc fc fc
072600
[    5.431267]  ffff88800e312200: 00 00 00 00 00 00 00 00 00 00 00 00
072600
00 00 00 fc
072600
[    5.431705] >ffff88800e312280: fc fc fc fc fc fc fc fc fc fc fc fc
072600
fc fc fc fc
072600
[    5.432123]                                   ^
072600
[    5.432391]  ffff88800e312300: 00 00 00 00 00 00 00 00 00 00 00 00
072600
00 00 00 fc
072600
[    5.432810]  ffff88800e312380: fc fc fc fc fc fc fc fc fc fc fc fc
072600
fc fc fc fc
072600
[    5.433229] ==================================================================
072600
[    5.433648] Disabling lock debugging due to kernel taint
072600
072600
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
072600
Reported-by: Kyle Zeng <zengyhkyle@gmail.com>
072600
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
072600
Signed-off-by: David S. Miller <davem@davemloft.net>
072600
Signed-off-by: Denis Kirjanov <denis.kirjanov@suse.com>
072600
---
072600
 net/sched/sch_cbq.c | 4 ++--
072600
 1 file changed, 2 insertions(+), 2 deletions(-)
072600
072600
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
072600
index 39b427dc7512..845f62c82ab4 100644
072600
--- a/net/sched/sch_cbq.c
072600
+++ b/net/sched/sch_cbq.c
072600
@@ -231,6 +231,8 @@ cbq_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
072600
 		result = tcf_classify(skb, fl, &res, true);
072600
 		if (!fl || result < 0)
072600
 			goto fallback;
072600
+		if (result == TC_ACT_SHOT)
072600
+			return NULL;
072600
 
072600
 		cl = (void *)res.class;
072600
 		if (!cl) {
072600
@@ -251,8 +253,6 @@ cbq_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
072600
 		case TC_ACT_TRAP:
072600
 			*qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
072600
 			/* fall through */
072600
-		case TC_ACT_SHOT:
072600
-			return NULL;
072600
 		case TC_ACT_RECLASSIFY:
072600
 			return cbq_reclassify(skb, cl);
072600
 		}
072600
-- 
072600
2.16.4
072600