syzbot


KASAN: use-after-free Read in scatterwalk_copychunks

Status: upstream: reported C repro on 2024/05/04 09:57
Subsystems: bcachefs
[Documentation on labels]
Reported-by: syzbot+8c4acf719c3fc41e8439@syzkaller.appspotmail.com
First crash: 41d, last: 15h30m
Cause bisection: introduced by (bisect log) :
commit dc6f2eb000d76ac8f93f4d59a8012ddfccca927a
Author: Kent Overstreet <kent.overstreet@linux.dev>
Date: Wed Apr 17 05:26:02 2024 +0000

  bcachefs: make btree read errors silent during scan

Crash: KASAN: use-after-free Read in scatterwalk_copychunks (log)
Repro: C syz .config
  
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [crypto?] KASAN: use-after-free Read in scatterwalk_copychunks 1 (3) 2024/05/05 00:35
Similar bugs (9)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream general protection fault in scatterwalk_copychunks (4) net crypto C done done 1341 175d 1186d 25/27 fixed on 2023/12/22 15:08
linux-4.14 KASAN: use-after-free Read in scatterwalk_copychunks C inconclusive 4 1227d 1881d 0/1 upstream: reported C repro on 2019/04/21 07:18
linux-4.19 KASAN: use-after-free Read in scatterwalk_copychunks C error 17 501d 1717d 0/1 upstream: reported C repro on 2019/10/03 04:34
linux-4.14 KASAN: slab-out-of-bounds Read in scatterwalk_copychunks C inconclusive 6 1235d 1738d 0/1 upstream: reported C repro on 2019/09/11 08:57
linux-4.14 general protection fault in scatterwalk_copychunks C error 204 489d 1881d 0/1 upstream: reported C repro on 2019/04/21 07:15
linux-5.15 BUG: unable to handle kernel paging request in scatterwalk_copychunks 3 415d 452d 0/3 auto-obsoleted due to no activity on 2023/08/23 09:08
linux-6.1 BUG: unable to handle kernel paging request in scatterwalk_copychunks 1 363d 363d 0/3 auto-obsoleted due to no activity on 2023/09/25 13:18
linux-4.19 general protection fault in scatterwalk_copychunks C error 152 490d 1821d 0/1 upstream: reported C repro on 2019/06/20 18:59
upstream general protection fault in scatterwalk_copychunks (5) crypto C done 2920 164d 171d 26/27 fixed on 2024/01/30 15:47

Sample crash report:
bcachefs (loop0): mounting version 1.7: mi_btree_bitmap opts=metadata_checksum=none,data_checksum=none,compression=lz4,nojournal_transaction_names
bcachefs (loop0): recovering from clean shutdown, journal seq 13
==================================================================
BUG: KASAN: use-after-free in memcpy_dir crypto/scatterwalk.c:23 [inline]
BUG: KASAN: use-after-free in scatterwalk_copychunks+0x1cc/0x460 crypto/scatterwalk.c:38
Read of size 32 at addr ffff888049380000 by task syz-executor169/5094

CPU: 0 PID: 5094 Comm: syz-executor169 Not tainted 6.9.0-rc6-next-20240503-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114
 print_address_description mm/kasan/report.c:377 [inline]
 print_report+0x169/0x550 mm/kasan/report.c:488
 kasan_report+0x143/0x180 mm/kasan/report.c:601
 kasan_check_range+0x282/0x290 mm/kasan/generic.c:189
 __asan_memcpy+0x29/0x70 mm/kasan/shadow.c:105
 memcpy_dir crypto/scatterwalk.c:23 [inline]
 scatterwalk_copychunks+0x1cc/0x460 crypto/scatterwalk.c:38
 skcipher_next_slow+0x39d/0x480 crypto/skcipher.c:276
 skcipher_walk_next+0x634/0xba0 crypto/skcipher.c:361
 chacha_simd_stream_xor+0x67f/0xd10 arch/x86/crypto/chacha_glue.c:192
 do_encrypt_sg fs/bcachefs/checksum.c:107 [inline]
 do_encrypt+0x4de/0x7b0 fs/bcachefs/checksum.c:127
 bset_encrypt fs/bcachefs/btree_io.h:120 [inline]
 bch2_btree_node_read_done+0x1dca/0x5ed0 fs/bcachefs/btree_io.c:1090
 btree_node_read_work+0x665/0x1300 fs/bcachefs/btree_io.c:1345
 bch2_btree_node_read+0x2637/0x2c80 fs/bcachefs/btree_io.c:1730
 __bch2_btree_root_read fs/bcachefs/btree_io.c:1769 [inline]
 bch2_btree_root_read+0x61e/0x970 fs/bcachefs/btree_io.c:1793
 read_btree_roots+0x22d/0x7b0 fs/bcachefs/recovery.c:472
 bch2_fs_recovery+0x2334/0x36e0 fs/bcachefs/recovery.c:800
 bch2_fs_start+0x356/0x5b0 fs/bcachefs/super.c:1030
 bch2_fs_open+0xa8d/0xdf0 fs/bcachefs/super.c:2105
 bch2_mount+0x71d/0x1320 fs/bcachefs/fs.c:1917
 legacy_get_tree+0xee/0x190 fs/fs_context.c:662
 vfs_get_tree+0x90/0x2a0 fs/super.c:1780
 do_new_mount+0x2be/0xb40 fs/namespace.c:3352
 do_mount fs/namespace.c:3692 [inline]
 __do_sys_mount fs/namespace.c:3898 [inline]
 __se_sys_mount+0x2d9/0x3c0 fs/namespace.c:3875
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fa185da797a
Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb a6 e8 5e 04 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 49 89 ca b8 a5 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:00007ffcd1a149e8 EFLAGS: 00000282 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007ffcd1a14a00 RCX: 00007fa185da797a
RDX: 000000002000f640 RSI: 000000002000f680 RDI: 00007ffcd1a14a00
RBP: 0000000000000004 R08: 00007ffcd1a14a40 R09: 000000000000f62b
R10: 0000000000010400 R11: 0000000000000282 R12: 0000000000010400
R13: 00007ffcd1a14a40 R14: 0000000000000003 R15: 0000000001000000
 </TASK>

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x49380
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffff7f(buddy)
raw: 00fff00000000000 ffffea0001249008 ffffea0001223008 0000000000000000
raw: 0000000000000000 0000000000000006 00000000ffffff7f 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as freed
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x500cc2(GFP_HIGHUSER|__GFP_ACCOUNT), pid 4945, tgid 4945 (sshd), ts 47548197350, free_ts 47548625509
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x1f3/0x230 mm/page_alloc.c:1468
 prep_new_page mm/page_alloc.c:1476 [inline]
 get_page_from_freelist+0x2ce2/0x2d90 mm/page_alloc.c:3438
 __alloc_pages_noprof+0x256/0x6c0 mm/page_alloc.c:4696
 alloc_pages_mpol_noprof+0x3e8/0x680 mm/mempolicy.c:2265
 pipe_write+0x657/0x1a40 fs/pipe.c:513
 new_sync_write fs/read_write.c:497 [inline]
 vfs_write+0xa72/0xc90 fs/read_write.c:590
 ksys_write+0x1a0/0x2c0 fs/read_write.c:643
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 4947 tgid 4947 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1088 [inline]
 free_unref_page+0xd22/0xea0 mm/page_alloc.c:2601
 __folio_put+0x3b9/0x620 mm/swap.c:129
 pipe_buf_release include/linux/pipe_fs_i.h:219 [inline]
 pipe_update_tail fs/pipe.c:224 [inline]
 pipe_read+0x6f2/0x13e0 fs/pipe.c:344
 new_sync_read fs/read_write.c:395 [inline]
 vfs_read+0x9c4/0xbd0 fs/read_write.c:476
 ksys_read+0x1a0/0x2c0 fs/read_write.c:619
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Memory state around the buggy address:
 ffff88804937ff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff88804937ff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff888049380000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                   ^
 ffff888049380080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff888049380100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================

Crashes (12):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/05/04 09:26 linux-next 9221b2819b8a 610f2a54 .config strace log report syz C [disk image] [vmlinux] [kernel image] [mounted in repro] ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in scatterwalk_copychunks
2024/06/10 06:09 upstream 83a7eefedc9b 82c05ab8 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs KASAN: use-after-free Read in scatterwalk_copychunks
2024/06/09 09:46 upstream 061d1af7b030 82c05ab8 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs KASAN: use-after-free Read in scatterwalk_copychunks
2024/05/24 15:11 upstream 8f6a15f095a6 8f98448e .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root KASAN: use-after-free Read in scatterwalk_copychunks
2024/05/13 05:37 linux-next 75fa778d74b7 9026e142 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in scatterwalk_copychunks
2024/05/04 08:49 linux-next 9221b2819b8a 610f2a54 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in scatterwalk_copychunks
2024/06/14 14:32 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci ac2193b4b460 a9616ff5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 KASAN: use-after-free Read in scatterwalk_copychunks
2024/06/14 14:32 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci ac2193b4b460 a9616ff5 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 KASAN: use-after-free Read in scatterwalk_copychunks
2024/06/09 06:31 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 8867bbd4a056 82c05ab8 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 KASAN: use-after-free Read in scatterwalk_copychunks
2024/06/05 08:08 upstream 32f88d65f01b e1e2c66e .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs KASAN: slab-use-after-free Read in scatterwalk_copychunks
2024/05/29 13:28 upstream e0cce98fe279 34889ee3 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs KASAN: slab-use-after-free Read in scatterwalk_copychunks
2024/05/22 22:09 linux-next 124cfbcd6d18 4d098039 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root KASAN: slab-use-after-free Read in scatterwalk_copychunks
* Struck through repros no longer work on HEAD.