[PATCH] cgroups: test css_put_many on the css_kill path

8 views
Skip to first unread message

Tadeusz Struk

unread,
May 23, 2022, 3:31:30 PM5/23/22
to syzbot+badfd0...@syzkaller.appspotmail.com, syzkaller-a...@googlegroups.com, tadeus...@linaro.org
#syz test: https://android.googlesource.com/kernel/common android12-5.10-lts

============================================================
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index adb820e98f24..f9ee03dadc38 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -5552,7 +5552,7 @@ static void css_killed_work_fn(struct work_struct *work)

do {
offline_css(css);
- css_put(css);
+ css_put_many(css, 2);
/* @css can't go away while we're holding cgroup_mutex */
css = css->parent;
} while (css && atomic_dec_and_test(&css->online_cnt));
@@ -5600,7 +5600,7 @@ static void kill_css(struct cgroup_subsys_state *css)
* Killing would put the base ref, but we need to keep it alive
* until after ->css_offline().
*/
- css_get(css);
+ css_get_many(css, 2);

/*
* cgroup core guarantees that, by the time ->css_offline() is
--
2.36.1

Tadeusz Struk

unread,
May 23, 2022, 3:31:56 PM5/23/22
to syzbot+e42ae4...@syzkaller.appspotmail.com, syzkaller-a...@googlegroups.com, tadeus...@linaro.org

Tadeusz Struk

unread,
May 23, 2022, 3:32:41 PM5/23/22
to syzbot+badfd0...@syzkaller.appspotmail.com, syzkaller-a...@googlegroups.com, tadeus...@linaro.org

syzbot

unread,
May 23, 2022, 3:52:11 PM5/23/22
to syzkaller-a...@googlegroups.com, tadeus...@linaro.org
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: use-after-free Read in ip6_pol_route

==================================================================
BUG: KASAN: use-after-free in rt6_get_pcpu_route net/ipv6/route.c:1394 [inline]
BUG: KASAN: use-after-free in ip6_pol_route+0x12cd/0x15c0 net/ipv6/route.c:2256
Read of size 4 at addr ffff88810ff8b2f8 by task kworker/0:3/377

CPU: 0 PID: 377 Comm: kworker/0:3 Not tainted 5.10.117-syzkaller-986967-g0974b8411a58-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: events linkwatch_event
Call Trace:
<IRQ>
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack_lvl+0x1e2/0x24b lib/dump_stack.c:118
print_address_description+0x81/0x3c0 mm/kasan/report.c:233
__kasan_report mm/kasan/report.c:419 [inline]
kasan_report+0x1a4/0x1f0 mm/kasan/report.c:436
__asan_report_load4_noabort+0x14/0x20 mm/kasan/report_generic.c:308
rt6_get_pcpu_route net/ipv6/route.c:1394 [inline]
ip6_pol_route+0x12cd/0x15c0 net/ipv6/route.c:2256
ip6_pol_route_input+0x54/0x80 net/ipv6/route.c:2280
pol_lookup_func include/net/ip6_fib.h:593 [inline]
fib6_rule_lookup+0x259/0x600 net/ipv6/fib6_rules.c:115
ip6_route_input_lookup net/ipv6/route.c:2292 [inline]
ip6_route_input+0x736/0xb30 net/ipv6/route.c:2461
ip6_rcv_finish_core net/ipv6/ip6_input.c:63 [inline]
ip6_rcv_finish net/ipv6/ip6_input.c:74 [inline]
NF_HOOK include/linux/netfilter.h:304 [inline]
ipv6_rcv+0x260/0x550 net/ipv6/ip6_input.c:297
__netif_receive_skb_one_core net/core/dev.c:5361 [inline]
__netif_receive_skb+0x1c5/0x500 net/core/dev.c:5475
process_backlog+0x352/0x690 net/core/dev.c:6381
napi_poll+0x1a3/0x650 net/core/dev.c:6832
net_rx_action+0x387/0x970 net/core/dev.c:6902
__do_softirq+0x27e/0x596 kernel/softirq.c:305
asm_call_irq_on_stack+0xf/0x20
</IRQ>
__run_on_irqstack arch/x86/include/asm/irq_stack.h:26 [inline]
run_on_irqstack_cond arch/x86/include/asm/irq_stack.h:77 [inline]
do_softirq_own_stack+0x60/0x80 arch/x86/kernel/irq_64.c:77
do_softirq+0xca/0x110 kernel/softirq.c:355
__local_bh_enable_ip+0x70/0x80 kernel/softirq.c:190
__raw_read_unlock_bh include/linux/rwlock_api_smp.h:251 [inline]
_raw_read_unlock_bh+0x29/0x30 kernel/locking/spinlock.c:279
ipv6_mc_up+0x238/0x2c0 net/ipv6/mcast.c:2569
ipv6_find_idev net/ipv6/addrconf.c:489 [inline]
addrconf_add_dev+0x1ab/0x620 net/ipv6/addrconf.c:2509
addrconf_dev_config+0x237/0x570 net/ipv6/addrconf.c:3389
addrconf_notify+0x8d9/0xe90 net/ipv6/addrconf.c:3635
notifier_call_chain kernel/notifier.c:83 [inline]
raw_notifier_call_chain+0x9e/0x110 kernel/notifier.c:410
call_netdevice_notifiers_info net/core/dev.c:2054 [inline]
netdev_state_change+0x1ba/0x280 net/core/dev.c:1484
linkwatch_do_dev+0xfe/0x140 net/core/link_watch.c:167
__linkwatch_run_queue+0x4f5/0x7f0 net/core/link_watch.c:213
linkwatch_event+0x4c/0x60 net/core/link_watch.c:252
process_one_work+0x726/0xc10 kernel/workqueue.c:2296
worker_thread+0xb27/0x1550 kernel/workqueue.c:2442
kthread+0x349/0x3d0 kernel/kthread.c:313
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

Allocated by task 377:
kasan_save_stack mm/kasan/common.c:38 [inline]
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:428 [inline]
__kasan_slab_alloc+0xb2/0xe0 mm/kasan/common.c:461
kasan_slab_alloc include/linux/kasan.h:259 [inline]
slab_post_alloc_hook mm/slab.h:583 [inline]
slab_alloc_node mm/slub.c:2956 [inline]
slab_alloc mm/slub.c:2964 [inline]
kmem_cache_alloc+0x16c/0x300 mm/slub.c:2969
dst_alloc+0x187/0x590 net/core/dst.c:93
ip6_dst_alloc net/ipv6/route.c:339 [inline]
ip6_rt_pcpu_alloc net/ipv6/route.c:1367 [inline]
rt6_make_pcpu_route net/ipv6/route.c:1415 [inline]
ip6_pol_route+0xd06/0x15c0 net/ipv6/route.c:2259
ip6_pol_route_input+0x54/0x80 net/ipv6/route.c:2280
pol_lookup_func include/net/ip6_fib.h:593 [inline]
fib6_rule_lookup+0x259/0x600 net/ipv6/fib6_rules.c:115
ip6_route_input_lookup net/ipv6/route.c:2292 [inline]
ip6_route_input+0x736/0xb30 net/ipv6/route.c:2461
ip6_rcv_finish_core net/ipv6/ip6_input.c:63 [inline]
ip6_rcv_finish net/ipv6/ip6_input.c:74 [inline]
NF_HOOK include/linux/netfilter.h:304 [inline]
ipv6_rcv+0x260/0x550 net/ipv6/ip6_input.c:297
__netif_receive_skb_one_core net/core/dev.c:5361 [inline]
__netif_receive_skb+0x1c5/0x500 net/core/dev.c:5475
process_backlog+0x352/0x690 net/core/dev.c:6381
napi_poll+0x1a3/0x650 net/core/dev.c:6832
net_rx_action+0x387/0x970 net/core/dev.c:6902
__do_softirq+0x27e/0x596 kernel/softirq.c:305

Freed by task 377:
kasan_save_stack mm/kasan/common.c:38 [inline]
kasan_set_track+0x4c/0x80 mm/kasan/common.c:46
kasan_set_free_info+0x23/0x40 mm/kasan/generic.c:357
____kasan_slab_free+0x121/0x160 mm/kasan/common.c:360
__kasan_slab_free+0x11/0x20 mm/kasan/common.c:368
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:1604 [inline]
slab_free_freelist_hook+0xcc/0x1a0 mm/slub.c:1630
slab_free mm/slub.c:3212 [inline]
kmem_cache_free+0xa9/0x1f0 mm/slub.c:3228
dst_destroy+0x244/0x330 net/core/dst.c:129
dst_release_immediate+0x90/0xe0 net/core/dst.c:194
rt_fibinfo_free_cpus+0xf6/0x1c0 net/ipv4/fib_semantics.c:204
fib_nh_common_release+0x8d/0x240 net/ipv4/fib_semantics.c:216
fib_nh_release net/ipv4/fib_semantics.c:228 [inline]
free_fib_info_rcu+0x98/0x190 net/ipv4/fib_semantics.c:240
rcu_do_batch+0x59e/0xc40 kernel/rcu/tree.c:2485
rcu_core+0x59b/0xe30 kernel/rcu/tree.c:2726
rcu_core_si+0x9/0x10 kernel/rcu/tree.c:2739
__do_softirq+0x27e/0x596 kernel/softirq.c:305

The buggy address belongs to the object at ffff88810ff8b280
which belongs to the cache ip6_dst_cache of size 240
The buggy address is located 120 bytes inside of
240-byte region [ffff88810ff8b280, ffff88810ff8b370)
The buggy address belongs to the page:
page:ffffea00043fe2c0 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10ff8b
flags: 0x8000000000000200(slab)
raw: 8000000000000200 dead000000000100 dead000000000122 ffff88810ae12780
raw: 0000000000000000 00000000000c000c 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x112a20(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_HARDWALL), pid 377, ts 39819635610, free_ts 38073197990
set_page_owner include/linux/page_owner.h:35 [inline]
post_alloc_hook mm/page_alloc.c:2385 [inline]
prep_new_page mm/page_alloc.c:2391 [inline]
get_page_from_freelist+0x745/0x760 mm/page_alloc.c:4067
__alloc_pages_nodemask+0x3b6/0x890 mm/page_alloc.c:5117
alloc_slab_page mm/slub.c:1815 [inline]
allocate_slab+0x78/0x540 mm/slub.c:1817
new_slab mm/slub.c:1878 [inline]
new_slab_objects mm/slub.c:2637 [inline]
___slab_alloc+0x131/0x2e0 mm/slub.c:2800
__slab_alloc+0x63/0xa0 mm/slub.c:2840
slab_alloc_node mm/slub.c:2922 [inline]
slab_alloc mm/slub.c:2964 [inline]
kmem_cache_alloc+0x1ef/0x300 mm/slub.c:2969
dst_alloc+0x187/0x590 net/core/dst.c:93
ip6_dst_alloc net/ipv6/route.c:339 [inline]
icmp6_dst_alloc+0xfb/0x5a0 net/ipv6/route.c:3160
mld_sendpack+0x49a/0xaf0 net/ipv6/mcast.c:1665
mld_send_cr net/ipv6/mcast.c:1972 [inline]
mld_ifc_timer_expire+0x85b/0xc50 net/ipv6/mcast.c:2471
call_timer_fn+0x35/0x270 kernel/time/timer.c:1420
expire_timers+0x21b/0x3a0 kernel/time/timer.c:1465
__run_timers+0x598/0x6f0 kernel/time/timer.c:1759
run_timer_softirq+0x69/0xf0 kernel/time/timer.c:1772
__do_softirq+0x27e/0x596 kernel/softirq.c:305
asm_call_irq_on_stack+0xf/0x20
page last free stack trace:
reset_page_owner include/linux/page_owner.h:28 [inline]
free_pages_prepare mm/page_alloc.c:1331 [inline]
__free_pages_ok+0x7f8/0x830 mm/page_alloc.c:1611
free_the_page mm/page_alloc.c:5178 [inline]
__free_pages+0x2d2/0x4c0 mm/page_alloc.c:5184
__free_slab+0xd3/0x190 mm/slub.c:1903
free_slab mm/slub.c:1918 [inline]
discard_slab mm/slub.c:1924 [inline]
unfreeze_partials+0x17d/0x1b0 mm/slub.c:2418
put_cpu_partial+0xc8/0x190 mm/slub.c:2454
__slab_free+0x2d8/0x3a0 mm/slub.c:3104
do_slab_free mm/slub.c:3200 [inline]
___cache_free+0x11f/0x140 mm/slub.c:3219
qlink_free+0x38/0x40 mm/kasan/quarantine.c:146
qlist_free_all+0x4c/0xc0 mm/kasan/quarantine.c:165
kasan_quarantine_reduce+0x15a/0x170 mm/kasan/quarantine.c:272
__kasan_slab_alloc+0x2f/0xe0 mm/kasan/common.c:438
kasan_slab_alloc include/linux/kasan.h:259 [inline]
slab_post_alloc_hook mm/slab.h:583 [inline]
slab_alloc_node mm/slub.c:2956 [inline]
slab_alloc mm/slub.c:2964 [inline]
kmem_cache_alloc+0x16c/0x300 mm/slub.c:2969
kmem_cache_alloc_node include/linux/slab.h:423 [inline]
__alloc_skb+0x7e/0x580 net/core/skbuff.c:199
alloc_skb include/linux/skbuff.h:1101 [inline]
netlink_alloc_large_skb net/netlink/af_netlink.c:1185 [inline]
netlink_sendmsg+0x7a4/0xd00 net/netlink/af_netlink.c:1909
sock_sendmsg_nosec net/socket.c:652 [inline]
sock_sendmsg net/socket.c:672 [inline]
__sys_sendto+0x541/0x700 net/socket.c:1982
__do_sys_sendto net/socket.c:1994 [inline]
__se_sys_sendto net/socket.c:1990 [inline]
__x64_sys_sendto+0xe5/0x100 net/socket.c:1990

Memory state around the buggy address:
ffff88810ff8b180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff88810ff8b200: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
>ffff88810ff8b280: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88810ff8b300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fc fc
ffff88810ff8b380: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
==================================================================
general protection fault, probably for non-canonical address 0xdffffc000000000f: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000078-0x000000000000007f]
CPU: 0 PID: 386 Comm: kworker/0:5 Tainted: G B 5.10.117-syzkaller-986967-g0974b8411a58-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: ipv6_addrconf addrconf_dad_work

RIP: 0010:rt6_get_pcpu_route net/ipv6/route.c:1394 [inline]
RIP: 0010:ip6_pol_route+0x741/0x15c0 net/ipv6/route.c:2256
Code: e8 54 c1 7d fd 48 8b 03 65 4c 8b 30 31 ff 4c 89 f6 e8 33 f3 43 fd 4d 85 f6 0f 84 a7 00 00 00 49 8d 5e 78 48 89 d8 48 c1 e8 03 <42> 8a 04 28 84 c0 0f 85 68 0b 00 00 44 8b 3b 31 ff 44 89 fe e8 56
RSP: 0018:ffffc90000007580 EFLAGS: 00010206

RAX: 000000000000000f RBX: 0000000000000079 RCX: 0000000080000301
RDX: ffff888103ff8000 RSI: 0000000000000001 RDI: 0000000000000000
RBP: ffffc90000007718 R08: ffffffff8428c43d R09: ffff8881108c2000
R10: ffffc90000007500 R11: 1ffff92000000ece R12: ffff88810cad1340
R13: dffffc0000000000 R14: 0000000000000001 R15: ffffc90000007670
FS: 0000000000000000(0000) GS:ffff8881f7200000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fd728f38922 CR3: 000000010c3f4000 CR4: 00000000003506b0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<IRQ>
ip6_pol_route_input+0x54/0x80 net/ipv6/route.c:2280
pol_lookup_func include/net/ip6_fib.h:593 [inline]
fib6_rule_lookup+0x259/0x600 net/ipv6/fib6_rules.c:115
ip6_route_input_lookup net/ipv6/route.c:2292 [inline]
ip6_route_input+0x736/0xb30 net/ipv6/route.c:2461
ip6_rcv_finish_core net/ipv6/ip6_input.c:63 [inline]
ip6_rcv_finish net/ipv6/ip6_input.c:74 [inline]
NF_HOOK include/linux/netfilter.h:304 [inline]
ipv6_rcv+0x260/0x550 net/ipv6/ip6_input.c:297
__netif_receive_skb_one_core net/core/dev.c:5361 [inline]
__netif_receive_skb+0x1c5/0x500 net/core/dev.c:5475
process_backlog+0x352/0x690 net/core/dev.c:6381
napi_poll+0x1a3/0x650 net/core/dev.c:6832
net_rx_action+0x387/0x970 net/core/dev.c:6902
__do_softirq+0x27e/0x596 kernel/softirq.c:305
asm_call_irq_on_stack+0xf/0x20
</IRQ>
__run_on_irqstack arch/x86/include/asm/irq_stack.h:26 [inline]
run_on_irqstack_cond arch/x86/include/asm/irq_stack.h:77 [inline]
do_softirq_own_stack+0x60/0x80 arch/x86/kernel/irq_64.c:77
do_softirq+0xca/0x110 kernel/softirq.c:355
__local_bh_enable_ip+0x70/0x80 kernel/softirq.c:190
local_bh_enable+0x1f/0x30 include/linux/bottom_half.h:32
rcu_read_unlock_bh include/linux/rcupdate.h:740 [inline]
ip6_finish_output2+0x1094/0x1950 net/ipv6/ip6_output.c:146
__ip6_finish_output+0x653/0x810 net/ipv6/ip6_output.c:210
ip6_finish_output+0x1c9/0x1e0 net/ipv6/ip6_output.c:220
NF_HOOK_COND include/linux/netfilter.h:293 [inline]
ip6_output+0x211/0x4c0 net/ipv6/ip6_output.c:243
dst_output include/net/dst.h:443 [inline]
NF_HOOK include/linux/netfilter.h:304 [inline]
ndisc_send_skb+0x6fe/0xc10 net/ipv6/ndisc.c:508
ndisc_send_ns+0x629/0x810 net/ipv6/ndisc.c:650
addrconf_dad_work+0xba6/0x15d0 net/ipv6/addrconf.c:4165
process_one_work+0x726/0xc10 kernel/workqueue.c:2296
worker_thread+0xb27/0x1550 kernel/workqueue.c:2442
kthread+0x349/0x3d0 kernel/kthread.c:313
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296
Modules linked in:

---[ end trace f8aa0e220c2dcc15 ]---
RIP: 0010:rt6_get_pcpu_route net/ipv6/route.c:1394 [inline]
RIP: 0010:ip6_pol_route+0x741/0x15c0 net/ipv6/route.c:2256
Code: e8 54 c1 7d fd 48 8b 03 65 4c 8b 30 31 ff 4c 89 f6 e8 33 f3 43 fd 4d 85 f6 0f 84 a7 00 00 00 49 8d 5e 78 48 89 d8 48 c1 e8 03 <42> 8a 04 28 84 c0 0f 85 68 0b 00 00 44 8b 3b 31 ff 44 89 fe e8 56
RSP: 0018:ffffc90000007580 EFLAGS: 00010206

RAX: 000000000000000f RBX: 0000000000000079 RCX: 0000000080000301
RDX: ffff888103ff8000 RSI: 0000000000000001 RDI: 0000000000000000
RBP: ffffc90000007718 R08: ffffffff8428c43d R09: ffff8881108c2000
R10: ffffc90000007500 R11: 1ffff92000000ece R12: ffff88810cad1340
R13: dffffc0000000000 R14: 0000000000000001 R15: ffffc90000007670
FS: 0000000000000000(0000) GS:ffff8881f7200000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fd728f38922 CR3: 000000010c3f4000 CR4: 00000000003506b0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: e8 54 c1 7d fd callq 0xfd7dc159
5: 48 8b 03 mov (%rbx),%rax
8: 65 4c 8b 30 mov %gs:(%rax),%r14
c: 31 ff xor %edi,%edi
e: 4c 89 f6 mov %r14,%rsi
11: e8 33 f3 43 fd callq 0xfd43f349
16: 4d 85 f6 test %r14,%r14
19: 0f 84 a7 00 00 00 je 0xc6
1f: 49 8d 5e 78 lea 0x78(%r14),%rbx
23: 48 89 d8 mov %rbx,%rax
26: 48 c1 e8 03 shr $0x3,%rax
* 2a: 42 8a 04 28 mov (%rax,%r13,1),%al <-- trapping instruction
2e: 84 c0 test %al,%al
30: 0f 85 68 0b 00 00 jne 0xb9e
36: 44 8b 3b mov (%rbx),%r15d
39: 31 ff xor %edi,%edi
3b: 44 89 fe mov %r15d,%esi
3e: e8 .byte 0xe8
3f: 56 push %rsi


Tested on:

commit: 0974b841 Merge 5.10.117 into android12-5.10-lts
git tree: android12-5.10-lts
console output: https://syzkaller.appspot.com/x/log.txt?x=17c01fc3f00000
kernel config: https://syzkaller.appspot.com/x/.config?x=b9b19582654944dd
dashboard link: https://syzkaller.appspot.com/bug?extid=badfd07a93cffefd7317
compiler: Debian clang version 13.0.1-++20220126092033+75e33f71c2da-1~exp1~20220126212112.63, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=121e2b8df00000

syzbot

unread,
May 23, 2022, 4:03:11 PM5/23/22
to syzkaller-a...@googlegroups.com, tadeus...@linaro.org
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
BUG: corrupted list in insert_work

list_add corruption. prev->next should be next (ffff8881f725c060), but was ffff888112e29870. (prev=ffff888112e29870).
------------[ cut here ]------------
kernel BUG at lib/list_debug.c:28!
invalid opcode: 0000 [#1] PREEMPT SMP KASAN
CPU: 0 PID: 423 Comm: syz-executor.2 Tainted: G W 5.10.117-syzkaller-986967-g0974b8411a58-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:__list_add_valid+0xc6/0xd0 lib/list_debug.c:26
Code: 48 c7 c7 40 db 43 85 4c 89 e6 4c 89 f1 31 c0 e8 ad 2b 40 02 0f 0b 48 c7 c7 00 dc 43 85 4c 89 f6 4c 89 e1 31 c0 e8 97 2b 40 02 <0f> 0b 0f 1f 84 00 00 00 00 00 55 48 89 e5 41 57 41 56 41 54 53 49
RSP: 0018:ffffc90000007a00 EFLAGS: 00010046
RAX: 0000000000000075 RBX: ffff8881f725c068 RCX: d6a1f122e57fa000
RDX: 0000000000000102 RSI: 0000000000000102 RDI: 0000000000000000
RBP: ffffc90000007a28 R08: ffffffff8153a998 R09: ffffed103ee44e83
R10: ffffed103ee44e83 R11: 1ffff1103ee44e82 R12: ffff888112e29870
R13: dffffc0000000000 R14: ffff8881f725c060 R15: ffff888112e29870
FS: 0000555555cf8400(0000) GS:ffff8881f7200000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f46e63de280 CR3: 00000001085ed000 CR4: 00000000003506b0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<IRQ>
__list_add include/linux/list.h:67 [inline]
list_add_tail include/linux/list.h:100 [inline]
insert_work+0x107/0x330 kernel/workqueue.c:1352
__queue_work+0x971/0xd30 kernel/workqueue.c:1514
queue_work_on+0xf2/0x150 kernel/workqueue.c:1541
queue_work include/linux/workqueue.h:513 [inline]
css_release+0xae/0xc0 kernel/cgroup/cgroup.c:5161
percpu_ref_put_many include/linux/percpu-refcount.h:322 [inline]
percpu_ref_put include/linux/percpu-refcount.h:338 [inline]
percpu_ref_call_confirm_rcu lib/percpu-refcount.c:162 [inline]
percpu_ref_switch_to_atomic_rcu+0x5a2/0x5b0 lib/percpu-refcount.c:199
rcu_do_batch+0x59e/0xc40 kernel/rcu/tree.c:2485
rcu_core+0x59b/0xe30 kernel/rcu/tree.c:2726
rcu_core_si+0x9/0x10 kernel/rcu/tree.c:2739
__do_softirq+0x27e/0x596 kernel/softirq.c:305
asm_call_irq_on_stack+0xf/0x20
</IRQ>
__run_on_irqstack arch/x86/include/asm/irq_stack.h:26 [inline]
run_on_irqstack_cond arch/x86/include/asm/irq_stack.h:77 [inline]
do_softirq_own_stack+0x60/0x80 arch/x86/kernel/irq_64.c:77
invoke_softirq kernel/softirq.c:402 [inline]
__irq_exit_rcu+0x128/0x150 kernel/softirq.c:432
irq_exit_rcu+0x9/0x10 kernel/softirq.c:444
sysvec_apic_timer_interrupt+0xbf/0xe0 arch/x86/kernel/apic/apic.c:1095
asm_sysvec_apic_timer_interrupt+0x12/0x20 arch/x86/include/asm/idtentry.h:635
RIP: 0010:native_restore_fl arch/x86/include/asm/irqflags.h:41 [inline]
RIP: 0010:arch_local_irq_restore arch/x86/include/asm/irqflags.h:84 [inline]
RIP: 0010:console_unlock+0xb5c/0xf20 kernel/printk/printk.c:2555
Code: 85 db 4c 8d b4 24 60 01 00 00 0f 85 82 03 00 00 e8 49 6e 00 00 48 8b 44 24 30 48 89 84 24 90 00 00 00 ff b4 24 90 00 00 00 9d <48> 8b 44 24 38 42 80 3c 38 00 74 08 4c 89 f7 e8 f0 e0 52 00 48 c7
RSP: 0018:ffffc90000c976c0 EFLAGS: 00000246
RAX: 0000000000000246 RBX: 0000000000000000 RCX: ffff88810c290000
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000001
RBP: ffffc90000c97950 R08: ffffffff8153a4db R09: 0000000000000003
R10: fffff52000192ec9 R11: 1ffff92000192ec8 R12: ffffc90000c978c0
R13: 1ffffffff0c3ad81 R14: ffffc90000c97820 R15: dffffc0000000000
vprintk_emit+0x44b/0x640 kernel/printk/printk.c:2063
vprintk_default+0x26/0x30 kernel/printk/printk.c:2080
vprintk_func+0x19d/0x1e0 kernel/printk/printk_safe.c:401
printk+0xcf/0x10f kernel/printk/printk.c:2111
print_modules+0xf8/0x1f0 kernel/module.c:4777
__warn+0xf5/0x260 kernel/panic.c:592
report_bug+0x410/0x580 lib/bug.c:197
handle_bug+0x41/0x70 arch/x86/kernel/traps.c:235
exc_invalid_op+0x1b/0x50 arch/x86/kernel/traps.c:255
asm_exc_invalid_op+0x12/0x20 arch/x86/include/asm/idtentry.h:569
RIP: 0010:cleanup_mnt+0x4c5/0x510 fs/namespace.c:1109
Code: 01 a1 ff 48 83 c4 28 5b 41 5c 41 5d 41 5e 41 5f 5d c3 e8 4e 06 b5 ff 48 8b 7d d0 e8 c5 07 05 00 e9 21 fd ff ff e8 3b 06 b5 ff <0f> 0b e9 e5 fc ff ff 48 c7 c1 58 db 5e 86 80 e1 07 80 c1 03 38 c1
RSP: 0018:ffffc90000c97e30 EFLAGS: 00010293
RAX: ffffffff81b7ac15 RBX: ffffe8ffffd49fcc RCX: ffff88810c290000
RDX: 0000000000000000 RSI: 00000000ffffffff RDI: 0000000000000000
RBP: ffffc90000c97e80 R08: ffffffff81b7a8f3 R09: 0000000000000003
R10: fffff52000192fc5 R11: 1ffff92000192fc4 R12: ffff888121b1b728
R13: 0000000000000008 R14: dffffc0000000000 R15: 00000000ffffffff
__cleanup_mnt+0x19/0x20 fs/namespace.c:1125
task_work_run+0x147/0x1b0 kernel/task_work.c:154
tracehook_notify_resume include/linux/tracehook.h:188 [inline]
exit_to_user_mode_loop+0xc8/0xe0 kernel/entry/common.c:164
exit_to_user_mode_prepare kernel/entry/common.c:191 [inline]
syscall_exit_to_user_mode+0x77/0xa0 kernel/entry/common.c:266
do_syscall_64+0x40/0x70 arch/x86/entry/common.c:56
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f0c7456e557
Code: ff ff ff f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 31 f6 e9 09 00 00 00 66 0f 1f 84 00 00 00 00 00 b8 a6 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffc9ba36c78 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 00007f0c7456e557
RDX: 00007ffc9ba36d49 RSI: 000000000000000a RDI: 00007ffc9ba36d40
RBP: 00007ffc9ba36d40 R08: 00000000ffffffff R09: 00007ffc9ba36b10
R10: 0000555555cf9ba3 R11: 0000000000000246 R12: 00007f0c745c61f8
R13: 00007ffc9ba37e00 R14: 0000555555cf9b00 R15: 00007ffc9ba37e40
Modules linked in:
---[ end trace 8a172ed32f86a6e9 ]---
RIP: 0010:__list_add_valid+0xc6/0xd0 lib/list_debug.c:26
Code: 48 c7 c7 40 db 43 85 4c 89 e6 4c 89 f1 31 c0 e8 ad 2b 40 02 0f 0b 48 c7 c7 00 dc 43 85 4c 89 f6 4c 89 e1 31 c0 e8 97 2b 40 02 <0f> 0b 0f 1f 84 00 00 00 00 00 55 48 89 e5 41 57 41 56 41 54 53 49
RSP: 0018:ffffc90000007a00 EFLAGS: 00010046
RAX: 0000000000000075 RBX: ffff8881f725c068 RCX: d6a1f122e57fa000
RDX: 0000000000000102 RSI: 0000000000000102 RDI: 0000000000000000
RBP: ffffc90000007a28 R08: ffffffff8153a998 R09: ffffed103ee44e83
R10: ffffed103ee44e83 R11: 1ffff1103ee44e82 R12: ffff888112e29870
R13: dffffc0000000000 R14: ffff8881f725c060 R15: ffff888112e29870
FS: 0000555555cf8400(0000) GS:ffff8881f7200000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f46e63de280 CR3: 00000001085ed000 CR4: 00000000003506b0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: 85 db test %ebx,%ebx
2: 4c 8d b4 24 60 01 00 lea 0x160(%rsp),%r14
9: 00
a: 0f 85 82 03 00 00 jne 0x392
10: e8 49 6e 00 00 callq 0x6e5e
15: 48 8b 44 24 30 mov 0x30(%rsp),%rax
1a: 48 89 84 24 90 00 00 mov %rax,0x90(%rsp)
21: 00
22: ff b4 24 90 00 00 00 pushq 0x90(%rsp)
29: 9d popfq
* 2a: 48 8b 44 24 38 mov 0x38(%rsp),%rax <-- trapping instruction
2f: 42 80 3c 38 00 cmpb $0x0,(%rax,%r15,1)
34: 74 08 je 0x3e
36: 4c 89 f7 mov %r14,%rdi
39: e8 f0 e0 52 00 callq 0x52e12e
3e: 48 rex.W
3f: c7 .byte 0xc7


Tested on:

commit: 0974b841 Merge 5.10.117 into android12-5.10-lts
git tree: android12-5.10-lts
console output: https://syzkaller.appspot.com/x/log.txt?x=122b5781f00000
kernel config: https://syzkaller.appspot.com/x/.config?x=89bdb361ba397fca
dashboard link: https://syzkaller.appspot.com/bug?extid=e42ae441c3b10acf9e9d
compiler: Debian clang version 13.0.1-++20220126092033+75e33f71c2da-1~exp1~20220126212112.63, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=1264b23df00000

syzbot

unread,
May 23, 2022, 4:20:10 PM5/23/22
to syzkaller-a...@googlegroups.com, tadeus...@linaro.org
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: use-after-free Write in put_task_stack

</TASK>
==================================================================
BUG: KASAN: use-after-free in instrument_atomic_read_write include/linux/instrumented.h:101 [inline]
BUG: KASAN: use-after-free in atomic_fetch_sub_release include/linux/atomic/atomic-instrumented.h:176 [inline]
BUG: KASAN: use-after-free in __refcount_sub_and_test include/linux/refcount.h:272 [inline]
BUG: KASAN: use-after-free in __refcount_dec_and_test include/linux/refcount.h:315 [inline]
BUG: KASAN: use-after-free in refcount_dec_and_test include/linux/refcount.h:333 [inline]
BUG: KASAN: use-after-free in put_task_stack+0x2a/0x220 kernel/fork.c:533
Write of size 4 at addr ffff88810cdd2c80 by task kworker/1:3/396

CPU: 1 PID: 396 Comm: kworker/1:3 Tainted: G W 5.18.0-syzkaller-00161-g1e57930e9f40-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: rcu_gp wait_rcu_exp_gp
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x151/0x1b7 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:313 [inline]
print_report+0x15f/0x620 mm/kasan/report.c:429
kasan_report+0xe6/0x110 mm/kasan/report.c:491
kasan_check_range+0x2aa/0x2e0 mm/kasan/generic.c:189
__kasan_check_write+0x14/0x20 mm/kasan/shadow.c:37
instrument_atomic_read_write include/linux/instrumented.h:101 [inline]
atomic_fetch_sub_release include/linux/atomic/atomic-instrumented.h:176 [inline]
__refcount_sub_and_test include/linux/refcount.h:272 [inline]
__refcount_dec_and_test include/linux/refcount.h:315 [inline]
refcount_dec_and_test include/linux/refcount.h:333 [inline]
put_task_stack+0x2a/0x220 kernel/fork.c:533
sched_show_task+0x380/0x520 kernel/sched/core.c:8732
dump_cpu_task+0x73/0x90 kernel/sched/core.c:11046
synchronize_rcu_expedited_wait+0xc17/0x1310 kernel/rcu/tree_exp.h:668
rcu_exp_wait_wake kernel/rcu/tree_exp.h:685 [inline]
rcu_exp_sel_wait_wake+0x4c9/0x8a0 kernel/rcu/tree_exp.h:719
wait_rcu_exp_gp+0x33/0x40 kernel/rcu/tree_exp.h:510
process_one_work+0x6cb/0xbf0 kernel/workqueue.c:2289
worker_thread+0xb3c/0x1390 kernel/workqueue.c:2436
kthread+0x26b/0x300 kernel/kthread.c:376
ret_from_fork+0x1f/0x30
</TASK>

Allocated by task 450:
kasan_save_stack mm/kasan/common.c:38 [inline]
kasan_set_track mm/kasan/common.c:45 [inline]
set_alloc_info mm/kasan/common.c:436 [inline]
__kasan_slab_alloc+0xb2/0xe0 mm/kasan/common.c:469
kasan_slab_alloc include/linux/kasan.h:224 [inline]
slab_post_alloc_hook mm/slab.h:749 [inline]
slab_alloc_node mm/slub.c:3217 [inline]
slab_alloc mm/slub.c:3225 [inline]
__kmem_cache_alloc_lru mm/slub.c:3232 [inline]
kmem_cache_alloc+0x192/0x300 mm/slub.c:3242
kmem_cache_alloc_node include/linux/slab.h:453 [inline]
alloc_task_struct_node kernel/fork.c:172 [inline]
dup_task_struct+0x54/0x490 kernel/fork.c:971
copy_process+0x582/0x34c0 kernel/fork.c:2068
kernel_clone+0x224/0x8d0 kernel/fork.c:2639
__do_sys_clone kernel/fork.c:2756 [inline]
__se_sys_clone kernel/fork.c:2740 [inline]
__x64_sys_clone+0x289/0x310 kernel/fork.c:2740
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x2f/0x50 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae

Freed by task 14:
kasan_save_stack mm/kasan/common.c:38 [inline]
kasan_set_track+0x4c/0x70 mm/kasan/common.c:45
kasan_set_free_info+0x23/0x40 mm/kasan/generic.c:370
____kasan_slab_free+0x133/0x170 mm/kasan/common.c:366
__kasan_slab_free+0x11/0x20 mm/kasan/common.c:374
kasan_slab_free include/linux/kasan.h:200 [inline]
slab_free_hook mm/slub.c:1728 [inline]
slab_free_freelist_hook+0xc9/0x1a0 mm/slub.c:1754
slab_free mm/slub.c:3510 [inline]
kmem_cache_free+0x110/0x2d0 mm/slub.c:3527
free_task_struct kernel/fork.c:177 [inline]
free_task kernel/fork.c:561 [inline]
__put_task_struct+0x32b/0x4d0 kernel/fork.c:850
put_task_struct include/linux/sched/task.h:115 [inline]
delayed_put_task_struct+0x5c/0x180 kernel/exit.c:177
rcu_do_batch+0x507/0xbc0 kernel/rcu/tree.c:2578
rcu_core+0x4dc/0xef0 kernel/rcu/tree.c:2838
rcu_core_si+0x9/0x10 kernel/rcu/tree.c:2855
__do_softirq+0x24e/0x586 kernel/softirq.c:558

Last potentially related work creation:
kasan_save_stack+0x3b/0x60 mm/kasan/common.c:38
__kasan_record_aux_stack+0xb3/0xc0 mm/kasan/generic.c:348
kasan_record_aux_stack_noalloc+0xb/0x10 mm/kasan/generic.c:358
call_rcu+0xf9/0x1390 kernel/rcu/tree.c:3126
put_task_struct_rcu_user+0x58/0xa0 kernel/exit.c:183
finish_task_switch+0x34a/0x700 kernel/sched/core.c:4987
context_switch kernel/sched/core.c:5076 [inline]
__schedule+0xb2a/0x1020 kernel/sched/core.c:6388
schedule_idle+0x50/0x90 kernel/sched/core.c:6488
do_idle+0x583/0x5e0 kernel/sched/idle.c:331
cpu_startup_entry+0x25/0x30 kernel/sched/idle.c:400
rest_init+0x107/0x130 init/main.c:726
start_kernel+0x0/0x4d7 init/main.c:882
start_kernel+0x465/0x4d7 init/main.c:1140
x86_64_start_reservations+0x2a/0x2c arch/x86/kernel/head64.c:546
x86_64_start_kernel+0x9b/0xa0 arch/x86/kernel/head64.c:527
secondary_startup_64_no_verify+0xc4/0xcb

Second to last potentially related work creation:
kasan_save_stack+0x3b/0x60 mm/kasan/common.c:38
__kasan_record_aux_stack+0xb3/0xc0 mm/kasan/generic.c:348
kasan_record_aux_stack_noalloc+0xb/0x10 mm/kasan/generic.c:358
call_rcu+0xf9/0x1390 kernel/rcu/tree.c:3126
put_task_struct_rcu_user+0x58/0xa0 kernel/exit.c:183
finish_task_switch+0x34a/0x700 kernel/sched/core.c:4987
context_switch kernel/sched/core.c:5076 [inline]
__schedule+0xb2a/0x1020 kernel/sched/core.c:6388
preempt_schedule_common+0xa7/0x100 kernel/sched/core.c:6553
preempt_schedule+0xd9/0xe0 kernel/sched/core.c:6577
preempt_schedule_thunk+0x16/0x18
try_to_wake_up+0x748/0xce0 kernel/sched/core.c:4204
wake_up_process+0x10/0x20 kernel/sched/core.c:4282
__kthread_create_on_node+0x2a5/0x540 kernel/kthread.c:435
kthread_create_on_node+0xda/0x120 kernel/kthread.c:512
cryptomgr_schedule_test crypto/algboss.c:219 [inline]
cryptomgr_notify+0x12a/0xcd0 crypto/algboss.c:240
notifier_call_chain kernel/notifier.c:84 [inline]
blocking_notifier_call_chain+0xbe/0x140 kernel/notifier.c:319
crypto_probing_notify crypto/api.c:306 [inline]
crypto_wait_for_test+0x4e/0x100 crypto/api.c:169
crypto_start_tests+0x15b/0x250 crypto/algapi.c:1338
crypto_algapi_init+0x13/0x17 crypto/algapi.c:1347
do_one_initcall+0x1b5/0x600 init/main.c:1298
do_initcall_level+0x192/0x2f0 init/main.c:1371
do_initcalls+0x50/0x94 init/main.c:1387
do_basic_setup+0x81/0x8a init/main.c:1406
kernel_init_freeable+0x2bd/0x3f3 init/main.c:1613
kernel_init+0x1d/0x2b0 init/main.c:1502
ret_from_fork+0x1f/0x30

The buggy address belongs to the object at ffff88810cdd2180
which belongs to the cache task_struct of size 4032
The buggy address is located 2816 bytes inside of
4032-byte region [ffff88810cdd2180, ffff88810cdd3140)

The buggy address belongs to the physical page:
page:ffffea0004337400 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10cdd0
head:ffffea0004337400 order:3 compound_mapcount:0 compound_pincount:0
flags: 0x8000000000010200(slab|head|zone=2)
raw: 8000000000010200 dead000000000100 dead000000000122 ffff888100132780
raw: 0000000000000000 0000000080070007 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 2, tgid 2 (kthreadd), ts 2251343001, free_ts 0
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook+0x15b/0x160 mm/page_alloc.c:2434
prep_new_page mm/page_alloc.c:2441 [inline]
get_page_from_freelist+0x3f6/0x8b0 mm/page_alloc.c:4182
__alloc_pages+0x3bd/0x850 mm/page_alloc.c:5408
allocate_slab+0x69/0x4d0 mm/slub.c:1944
new_slab mm/slub.c:2004 [inline]
___slab_alloc+0x2c2/0x6a0 mm/slub.c:3005
__slab_alloc+0x4a/0x90 mm/slub.c:3092
slab_alloc_node mm/slub.c:3183 [inline]
slab_alloc mm/slub.c:3225 [inline]
__kmem_cache_alloc_lru mm/slub.c:3232 [inline]
kmem_cache_alloc+0x20e/0x300 mm/slub.c:3242
kmem_cache_alloc_node include/linux/slab.h:453 [inline]
alloc_task_struct_node kernel/fork.c:172 [inline]
dup_task_struct+0x54/0x490 kernel/fork.c:971
copy_process+0x582/0x34c0 kernel/fork.c:2068
kernel_clone+0x224/0x8d0 kernel/fork.c:2639
kernel_thread+0x167/0x1e0 kernel/fork.c:2691
create_kthread kernel/kthread.c:399 [inline]
kthreadd+0x38d/0x4e0 kernel/kthread.c:745
ret_from_fork+0x1f/0x30
page_owner free stack trace missing

Memory state around the buggy address:
ffff88810cdd2b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88810cdd2c00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88810cdd2c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88810cdd2d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88810cdd2d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


Tested on:

commit: 1e57930e Merge tag 'rcu.2022.05.19a' of git://git.kern..
git tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=171eb5c5f00000
kernel config: https://syzkaller.appspot.com/x/.config?x=1cf097d61b4172e1
dashboard link: https://syzkaller.appspot.com/bug?extid=badfd07a93cffefd7317
compiler: Debian clang version 13.0.1-++20220126092033+75e33f71c2da-1~exp1~20220126212112.63, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=17058581f00000

Reply all
Reply to author
Forward
0 new messages