[Syzkaller & bisect] There is KASAN: slab-use-after-free Read in __nf_unregister_net_hook in v6.10

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Andrii and bpf experts,

Greetings!

There is KASAN: slab-use-after-free Read in __nf_unregister_net_hook in v6.10:

Found the first bad commit:
"
f42bcd168d03 bpf: teach verifier actual bounds of bpf_get_smp_processor_id() result
"

All detailed info: https://github.com/xupengfe/syzkaller_logs/tree/main/240725_142422___nf_unregister_net_hook
Syzkaller reproduced code: https://github.com/xupengfe/syzkaller_logs/blob/main/240725_142422___nf_unregister_net_hook/repro.c
Syzkaller repro syscall steps: https://github.com/xupengfe/syzkaller_logs/blob/main/240725_142422___nf_unregister_net_hook/repro.prog
Syzkaller report analysis: https://github.com/xupengfe/syzkaller_logs/blob/main/240725_142422___nf_unregister_net_hook/repro.report
Kconfig(make olddefconfig): https://github.com/xupengfe/syzkaller_logs/blob/main/240725_142422___nf_unregister_net_hook/kconfig_origin
Bisect info: https://github.com/xupengfe/syzkaller_logs/blob/main/240725_142422___nf_unregister_net_hook/bisect_info.log
v6.10 bzImage: https://github.com/xupengfe/syzkaller_logs/raw/main/240725_142422___nf_unregister_net_hook/bzImage_0c3836482481200ead7b416ca80c68a29cfdaabd.tar.gz
Mount repro img: https://github.com/xupengfe/syzkaller_logs/raw/main/240725_142422___nf_unregister_net_hook/mount_4.gz
Issue dmesg: https://github.com/xupengfe/syzkaller_logs/blob/main/240725_142422___nf_unregister_net_hook/0c3836482481200ead7b416ca80c68a29cfdaabd_dmesg.log

"
[   18.969108] ==================================================================
[   18.969429] BUG: KASAN: slab-use-after-free in __nf_unregister_net_hook+0x640/0x6b0
[   18.969781] Read of size 8 at addr ffff888014338f98 by task repro/730
[   18.970063] 
[   18.970140] CPU: 0 PID: 730 Comm: repro Not tainted 6.10.0-0c3836482481+ #1
[   18.970447] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014
[   18.970932] Call Trace:
[   18.971047]  <TASK>
[   18.971147]  dump_stack_lvl+0xea/0x150
[   18.971328]  print_report+0xce/0x610
[   18.971507]  ? __nf_unregister_net_hook+0x640/0x6b0
[   18.971726]  ? kasan_complete_mode_report_info+0x80/0x200
[   18.971969]  ? __nf_unregister_net_hook+0x640/0x6b0
[   18.972191]  kasan_report+0xcc/0x110
[   18.972360]  ? __nf_unregister_net_hook+0x640/0x6b0
[   18.972591]  ? __pfx_bpf_link_release+0x10/0x10
[   18.972804]  __asan_report_load8_noabort+0x18/0x20
[   18.973026]  __nf_unregister_net_hook+0x640/0x6b0
[   18.973243]  ? __pfx_bpf_link_release+0x10/0x10
[   18.973516]  ? __pfx_bpf_link_release+0x10/0x10
[   18.973745]  nf_unregister_net_hook+0xea/0x140
[   18.973950]  bpf_nf_link_release+0xda/0x1e0
[   18.974145]  bpf_link_free+0x139/0x2d0
[   18.974320]  bpf_link_release+0x6e/0x90
[   18.974499]  __fput+0x426/0xbc0
[   18.974649]  ____fput+0x1f/0x30
[   18.974799]  task_work_run+0x19c/0x2b0
[   18.974970]  ? __pfx_task_work_run+0x10/0x10
[   18.975163]  ? free_nsproxy+0x3b2/0x4e0
[   18.975337]  ? switch_task_namespaces+0xf7/0x130
[   18.975550]  do_exit+0xaf2/0x29f0
[   18.975707]  ? __this_cpu_preempt_check+0x21/0x30
[   18.975927]  ? lock_release+0x418/0x840
[   18.976108]  ? __pfx_do_exit+0x10/0x10
[   18.976283]  do_group_exit+0xe4/0x2c0
[   18.976456]  get_signal+0x2387/0x2460
[   18.976632]  ? do_futex+0x14b/0x3a0
[   18.976798]  ? __pfx_get_signal+0x10/0x10
[   18.976985]  ? __pfx_do_futex+0x10/0x10
[   18.977168]  arch_do_signal_or_restart+0x8e/0x7d0
[   18.977385]  ? __pfx_arch_do_signal_or_restart+0x10/0x10
[   18.977627]  ? trace_hardirqs_on+0x51/0x60
[   18.977817]  ? __this_cpu_preempt_check+0x21/0x30
[   18.978030]  ? syscall_exit_to_user_mode+0x109/0x1f0
[   18.978253]  syscall_exit_to_user_mode+0x13e/0x1f0
[   18.978473]  do_syscall_64+0x79/0x140
[   18.978644]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   18.978870] RIP: 0033:0x7f464083ee5d
[   18.979036] Code: Unable to access opcode bytes at 0x7f464083ee33.
[   18.979303] RSP: 002b:00007f4640b15e08 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca
[   18.979636] RAX: fffffffffffffe00 RBX: 00007f4640b16640 RCX: 00007f464083ee5d
[   18.979948] RDX: 0000000000000000 RSI: 0000000000000080 RDI: 00000000004101c8
[   18.980258] RBP: 00007f4640b15e20 R08: 0000000000000000 R09: 0000000000000000
[   18.980575] R10: 0000000000000000 R11: 0000000000000246 R12: 00007f4640b16640
[   18.980888] R13: 0000000000000013 R14: 00007f464089f560 R15: 0000000000000000
[   18.981210]  </TASK>
[   18.981314] 
[   18.981390] Allocated by task 730:
[   18.981547]  kasan_save_stack+0x2c/0x60
[   18.981724]  kasan_save_track+0x18/0x40
[   18.981898]  kasan_save_alloc_info+0x3c/0x50
[   18.982090]  __kasan_slab_alloc+0x62/0x80
[   18.982271]  kmem_cache_alloc_noprof+0x12b/0x380
[   18.982480]  copy_net_ns+0xf0/0x740
[   18.982644]  create_new_namespaces+0x403/0xb70
[   18.982842]  unshare_nsproxy_namespaces+0xca/0x200
[   18.983053]  ksys_unshare+0x424/0xa10
[   18.983218]  __x64_sys_unshare+0x3a/0x50
[   18.983393]  x64_sys_call+0x1b69/0x20d0
[   18.983571]  do_syscall_64+0x6d/0x140
[   18.983737]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   18.983956] 
[   18.984029] Freed by task 35:
[   18.984163]  kasan_save_stack+0x2c/0x60
[   18.984337]  kasan_save_track+0x18/0x40
[   18.984514]  kasan_save_free_info+0x3f/0x60
[   18.984703]  __kasan_slab_free+0x115/0x1a0
[   18.984890]  kmem_cache_free+0x174/0x430
[   18.985074]  cleanup_net+0x91d/0xb80
[   18.985244]  process_one_work+0x92e/0x1af0
[   18.985434]  worker_thread+0x68d/0xeb0
[   18.985606]  kthread+0x35a/0x470
[   18.985760]  ret_from_fork+0x56/0x90
[   18.985924]  ret_from_fork_asm+0x1a/0x30
[   18.986103] 
[   18.986177] The buggy address belongs to the object at ffff888014338000
[   18.986177]  which belongs to the cache net_namespace of size 6656
[   18.986729] The buggy address is located 3992 bytes inside of
[   18.986729]  freed 6656-byte region [ffff888014338000, ffff888014339a00)
[   18.987264] 
[   18.987341] The buggy address belongs to the physical page:
[   18.987594] page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x14338
[   18.987940] head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
[   18.988271] memcg:ffff88800e70ba81
[   18.988427] flags: 0xfffffc0000040(head|node=0|zone=1|lastcpupid=0x1fffff)
[   18.988724] page_type: 0xffffefff(slab)
[   18.988903] raw: 000fffffc0000040 ffff88800d313140 dead000000000122 0000000000000000
[   18.989240] raw: 0000000000000000 0000000080040004 00000001ffffefff ffff88800e70ba81
[   18.989580] head: 000fffffc0000040 ffff88800d313140 dead000000000122 0000000000000000
[   18.989920] head: 0000000000000000 0000000080040004 00000001ffffefff ffff88800e70ba81
[   18.990258] head: 000fffffc0000003 ffffea000050ce01 ffffffffffffffff 0000000000000000
[   18.990600] head: 0000000000000008 0000000000000000 00000000ffffffff 0000000000000000
[   18.990931] page dumped because: kasan: bad access detected
[   18.991166] 
[   18.991239] Memory state around the buggy address:
[   18.991446]  ffff888014338e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[   18.991758]  ffff888014338f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[   18.992069] >ffff888014338f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[   18.992378]                             ^
[   18.992560]  ffff888014339000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[   18.992872]  ffff888014339080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[   18.993184] ==================================================================
[   18.993552] Disabling lock debugging due to kernel taint
[   19.062957] loop0: detected capacity change from 0 to 32768
"

Hope it's helpful.

Thank you!

---

If you don't need the following environment to reproduce the problem or if you
already have one reproduced environment, please ignore the following information.

How to reproduce:
git clone https://gitlab.com/xupengfe/repro_vm_env.git
cd repro_vm_env
tar -xvf repro_vm_env.tar.gz
cd repro_vm_env; ./start3.sh  // it needs qemu-system-x86_64 and I used v7.1.0
  // start3.sh will load bzImage_2241ab53cbb5cdb08a6b2d4688feb13971058f65 v6.2-rc5 kernel
  // You could change the bzImage_xxx as you want
  // Maybe you need to remove line "-drive if=pflash,format=raw,readonly=on,file=./OVMF_CODE.fd \" for different qemu version
You could use below command to log in, there is no password for root.
ssh -p 10023 root@localhost

After login vm(virtual machine) successfully, you could transfer reproduced
binary to the vm by below way, and reproduce the problem in vm:
gcc -pthread -o repro repro.c
scp -P 10023 repro root@localhost:/root/

Get the bzImage for target kernel:
Please use target kconfig and copy it to kernel_src/.config
make olddefconfig
make -jx bzImage           //x should equal or less than cpu num your pc has

Fill the bzImage file into above start3.sh to load the target kernel in vm.


Tips:
If you already have qemu-system-x86_64, please ignore below info.
If you want to install qemu v7.1.0 version:
git clone https://github.com/qemu/qemu.git
cd qemu
git checkout -f v7.1.0
mkdir build
cd build
yum install -y ninja-build.x86_64
yum -y install libslirp-devel.x86_64
../configure --target-list=x86_64-softmmu --enable-kvm --enable-vnc --enable-gtk --enable-sdl --enable-usb-redir --enable-slirp
make
make install

Best Regards,
Thanks!




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux