[syzbot] general protection fault in __blk_rq_map_sg

9 views
Skip to first unread message

syzbot

unread,
Feb 4, 2023, 1:44:48 PM2/4/23
to ax...@kernel.dk, linux...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 80bd9028feca Add linux-next specific files for 20230131
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=17126969480000
kernel config: https://syzkaller.appspot.com/x/.config?x=904dc2f450eaad4a
dashboard link: https://syzkaller.appspot.com/bug?extid=0bbf896c8341c8e137c2
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1534e75d480000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/924618188238/disk-80bd9028.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/7a03cf86e545/vmlinux-80bd9028.xz
kernel image: https://storage.googleapis.com/syzbot-assets/568e80043a41/bzImage-80bd9028.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+0bbf89...@syzkaller.appspotmail.com

general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
CPU: 1 PID: 5252 Comm: syz-executor.2 Not tainted 6.2.0-rc6-next-20230131-syzkaller-09515-g80bd9028feca #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/12/2023
RIP: 0010:sg_assign_page include/linux/scatterlist.h:109 [inline]
RIP: 0010:sg_set_page include/linux/scatterlist.h:139 [inline]
RIP: 0010:__blk_bvec_map_sg block/blk-merge.c:501 [inline]
RIP: 0010:__blk_bios_map_sg block/blk-merge.c:548 [inline]
RIP: 0010:__blk_rq_map_sg+0x36e/0xfd0 block/blk-merge.c:575
Code: 38 e8 36 5f 1a 00 48 89 c3 e8 9e 62 88 fd 48 8b 44 24 20 80 38 00 0f 85 fe 0b 00 00 48 8b 04 24 48 89 18 48 89 d8 48 c1 e8 03 <42> 80 3c 20 00 0f 85 f3 0b 00 00 4c 8b 74 24 30 31 ff 48 8b 2b 41
RSP: 0018:ffffc9000428edf8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff888019293a80 RSI: ffffffff83fc5382 RDI: 0000000000000007
RBP: ffff888021114bb8 R08: 0000000000000007 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: dffffc0000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000a00
FS: 00007f50df7a5700(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f50df784718 CR3: 0000000077767000 CR4: 00000000003506e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
scsi_alloc_sgtables+0x236/0xf70 drivers/scsi/scsi_lib.c:1048
sd_setup_read_write_cmnd drivers/scsi/sd.c:1136 [inline]
sd_init_command+0x67a/0x32a0 drivers/scsi/sd.c:1260
scsi_prepare_cmd drivers/scsi/scsi_lib.c:1603 [inline]
scsi_queue_rq+0x1e7b/0x3a40 drivers/scsi/scsi_lib.c:1737
blk_mq_dispatch_rq_list+0x710/0x23f0 block/blk-mq.c:2056
__blk_mq_do_dispatch_sched block/blk-mq-sched.c:173 [inline]
blk_mq_do_dispatch_sched+0x95e/0xc20 block/blk-mq-sched.c:187
__blk_mq_sched_dispatch_requests+0x26d/0x3e0 block/blk-mq-sched.c:313
blk_mq_sched_dispatch_requests+0x10a/0x190 block/blk-mq-sched.c:339
__blk_mq_run_hw_queue+0x2b7/0x480 block/blk-mq.c:2174
__blk_mq_delay_run_hw_queue+0x5f7/0x700 block/blk-mq.c:2250
blk_mq_run_hw_queue+0x3b5/0x560 block/blk-mq.c:2298
blk_mq_sched_insert_requests+0x1d9/0xb30 block/blk-mq-sched.c:493
blk_mq_dispatch_plug_list block/blk-mq.c:2758 [inline]
blk_mq_flush_plug_list+0x39c/0xe10 block/blk-mq.c:2800
__blk_flush_plug block/blk-core.c:1150 [inline]
blk_finish_plug block/blk-core.c:1174 [inline]
blk_finish_plug+0xbb/0x170 block/blk-core.c:1171
__iomap_dio_rw+0xf85/0x1d80 fs/iomap/direct-io.c:602
iomap_dio_rw+0x40/0xa0 fs/iomap/direct-io.c:682
ext4_dio_read_iter fs/ext4/file.c:94 [inline]
ext4_file_read_iter+0x4be/0x690 fs/ext4/file.c:145
call_read_iter include/linux/fs.h:1845 [inline]
generic_file_splice_read+0x182/0x4b0 fs/splice.c:309
do_splice_to+0x1b9/0x240 fs/splice.c:793
splice_direct_to_actor+0x2ab/0x8a0 fs/splice.c:865
do_splice_direct+0x1ab/0x280 fs/splice.c:974
do_sendfile+0xb19/0x12c0 fs/read_write.c:1255
__do_sys_sendfile64 fs/read_write.c:1323 [inline]
__se_sys_sendfile64 fs/read_write.c:1309 [inline]
__x64_sys_sendfile64+0x1d0/0x210 fs/read_write.c:1309
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f50dea8c0c9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 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:00007f50df7a5168 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
RAX: ffffffffffffffda RBX: 00007f50debabf80 RCX: 00007f50dea8c0c9
RDX: 0000000000000000 RSI: 0000000000000004 RDI: 0000000000000003
RBP: 00007f50deae7ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 000000000001ff01 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fffbb4e322f R14: 00007f50df7a5300 R15: 0000000000022000
</TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:sg_assign_page include/linux/scatterlist.h:109 [inline]
RIP: 0010:sg_set_page include/linux/scatterlist.h:139 [inline]
RIP: 0010:__blk_bvec_map_sg block/blk-merge.c:501 [inline]
RIP: 0010:__blk_bios_map_sg block/blk-merge.c:548 [inline]
RIP: 0010:__blk_rq_map_sg+0x36e/0xfd0 block/blk-merge.c:575
Code: 38 e8 36 5f 1a 00 48 89 c3 e8 9e 62 88 fd 48 8b 44 24 20 80 38 00 0f 85 fe 0b 00 00 48 8b 04 24 48 89 18 48 89 d8 48 c1 e8 03 <42> 80 3c 20 00 0f 85 f3 0b 00 00 4c 8b 74 24 30 31 ff 48 8b 2b 41
RSP: 0018:ffffc9000428edf8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff888019293a80 RSI: ffffffff83fc5382 RDI: 0000000000000007
RBP: ffff888021114bb8 R08: 0000000000000007 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: dffffc0000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000a00
FS: 00007f50df7a5700(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007ffdfee5f5d8 CR3: 0000000077767000 CR4: 00000000003506e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: 38 e8 cmp %ch,%al
2: 36 5f ss pop %rdi
4: 1a 00 sbb (%rax),%al
6: 48 89 c3 mov %rax,%rbx
9: e8 9e 62 88 fd callq 0xfd8862ac
e: 48 8b 44 24 20 mov 0x20(%rsp),%rax
13: 80 38 00 cmpb $0x0,(%rax)
16: 0f 85 fe 0b 00 00 jne 0xc1a
1c: 48 8b 04 24 mov (%rsp),%rax
20: 48 89 18 mov %rbx,(%rax)
23: 48 89 d8 mov %rbx,%rax
26: 48 c1 e8 03 shr $0x3,%rax
* 2a: 42 80 3c 20 00 cmpb $0x0,(%rax,%r12,1) <-- trapping instruction
2f: 0f 85 f3 0b 00 00 jne 0xc28
35: 4c 8b 74 24 30 mov 0x30(%rsp),%r14
3a: 31 ff xor %edi,%edi
3c: 48 8b 2b mov (%rbx),%rbp
3f: 41 rex.B


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches

syzbot

unread,
Feb 4, 2023, 6:12:42 PM2/4/23
to ax...@kernel.dk, linux...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
syzbot has found a reproducer for the following issue on:

HEAD commit: 4fafd96910ad Add linux-next specific files for 20230203
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=11d0585d480000
kernel config: https://syzkaller.appspot.com/x/.config?x=1d2fba7d42502ca4
dashboard link: https://syzkaller.appspot.com/bug?extid=0bbf896c8341c8e137c2
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=124dabab480000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=166cc203480000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/348cc2da441a/disk-4fafd969.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/e2dedc500f12/vmlinux-4fafd969.xz
kernel image: https://storage.googleapis.com/syzbot-assets/fae710d9ebd8/bzImage-4fafd969.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+0bbf89...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: slab-use-after-free in sg_assign_page include/linux/scatterlist.h:109 [inline]
BUG: KASAN: slab-use-after-free in sg_set_page include/linux/scatterlist.h:139 [inline]
BUG: KASAN: slab-use-after-free in __blk_bvec_map_sg block/blk-merge.c:501 [inline]
BUG: KASAN: slab-use-after-free in __blk_bios_map_sg block/blk-merge.c:548 [inline]
BUG: KASAN: slab-use-after-free in __blk_rq_map_sg+0xf74/0xfd0 block/blk-merge.c:575
Read of size 8 at addr ffff888078d1c640 by task syz-executor635/5472

CPU: 0 PID: 5472 Comm: syz-executor635 Not tainted 6.2.0-rc6-next-20230203-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/12/2023
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
print_address_description.constprop.0+0x2c/0x3c0 mm/kasan/report.c:319
print_report mm/kasan/report.c:430 [inline]
kasan_report+0x11c/0x130 mm/kasan/report.c:536
sg_assign_page include/linux/scatterlist.h:109 [inline]
sg_set_page include/linux/scatterlist.h:139 [inline]
__blk_bvec_map_sg block/blk-merge.c:501 [inline]
__blk_bios_map_sg block/blk-merge.c:548 [inline]
__blk_rq_map_sg+0xf74/0xfd0 block/blk-merge.c:575
RIP: 0033:0x7f3aac0c4e09
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 71 15 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 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:00007f3aac076318 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
RAX: ffffffffffffffda RBX: 00007f3aac14e428 RCX: 00007f3aac0c4e09
RDX: 0000000000000000 RSI: 0000000000000004 RDI: 0000000000000003
RBP: 00007f3aac14e420 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000010000 R11: 0000000000000246 R12: 00007f3aac11b1a4
R13: 00007ffe79ef5f4f R14: 00007f3aac076400 R15: 0000000000022000
</TASK>

Allocated by task 5438:
kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
kasan_set_track+0x25/0x30 mm/kasan/common.c:52
__kasan_slab_alloc+0x7f/0x90 mm/kasan/common.c:328
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook mm/slab.h:769 [inline]
slab_alloc_node mm/slub.c:3452 [inline]
slab_alloc mm/slub.c:3460 [inline]
__kmem_cache_alloc_lru mm/slub.c:3467 [inline]
kmem_cache_alloc+0x175/0x320 mm/slub.c:3476
mempool_alloc+0x158/0x360 mm/mempool.c:398
__sg_alloc_table+0x248/0x380 lib/scatterlist.c:318
sg_alloc_table_chained+0x9f/0x1f0 lib/sg_pool.c:133
scsi_alloc_sgtables+0x1cd/0xf70 drivers/scsi/scsi_lib.c:1040
sd_setup_read_write_cmnd drivers/scsi/sd.c:1136 [inline]
sd_init_command+0x67a/0x32a0 drivers/scsi/sd.c:1260
scsi_prepare_cmd drivers/scsi/scsi_lib.c:1603 [inline]
scsi_queue_rq+0x1e7b/0x3a40 drivers/scsi/scsi_lib.c:1737
blk_mq_dispatch_rq_list+0x710/0x23f0 block/blk-mq.c:2056
__blk_mq_do_dispatch_sched block/blk-mq-sched.c:173 [inline]
blk_mq_do_dispatch_sched+0x95e/0xc20 block/blk-mq-sched.c:187
__blk_mq_sched_dispatch_requests+0x26d/0x3e0 block/blk-mq-sched.c:313
blk_mq_sched_dispatch_requests+0x10a/0x190 block/blk-mq-sched.c:339
__blk_mq_run_hw_queue+0x2b7/0x480 block/blk-mq.c:2174
__blk_mq_delay_run_hw_queue+0x5f7/0x700 block/blk-mq.c:2250
blk_mq_run_hw_queue+0x3b5/0x560 block/blk-mq.c:2298
blk_mq_sched_insert_requests+0x1d9/0xb30 block/blk-mq-sched.c:493
blk_mq_dispatch_plug_list block/blk-mq.c:2758 [inline]
blk_mq_flush_plug_list+0x39c/0xe10 block/blk-mq.c:2800
__blk_flush_plug block/blk-core.c:1150 [inline]
blk_finish_plug block/blk-core.c:1174 [inline]
blk_finish_plug+0xbb/0x170 block/blk-core.c:1171
ext4_do_writepages+0x1fbf/0x30e0 fs/ext4/inode.c:2927
ext4_writepages+0x27c/0x5e0 fs/ext4/inode.c:2964
do_writepages+0x1a8/0x640 mm/page-writeback.c:2551
filemap_fdatawrite_wbc mm/filemap.c:388 [inline]
filemap_fdatawrite_wbc+0x147/0x1b0 mm/filemap.c:378
__filemap_fdatawrite_range+0xb8/0xf0 mm/filemap.c:421
filemap_write_and_wait_range mm/filemap.c:676 [inline]
filemap_write_and_wait_range+0xa1/0x120 mm/filemap.c:667
__iomap_dio_rw+0x5ea/0x1d80 fs/iomap/direct-io.c:565
iomap_dio_rw+0x40/0xa0 fs/iomap/direct-io.c:682
ext4_dio_read_iter fs/ext4/file.c:94 [inline]
ext4_file_read_iter+0x4be/0x690 fs/ext4/file.c:145
call_read_iter include/linux/fs.h:1845 [inline]
generic_file_splice_read+0x182/0x4b0 fs/splice.c:309
do_splice_to+0x1b9/0x240 fs/splice.c:793
splice_direct_to_actor+0x2ab/0x8a0 fs/splice.c:865
do_splice_direct+0x1ab/0x280 fs/splice.c:974
do_sendfile+0xb19/0x12c0 fs/read_write.c:1255
__do_sys_sendfile64 fs/read_write.c:1323 [inline]
__se_sys_sendfile64 fs/read_write.c:1309 [inline]
__x64_sys_sendfile64+0x1d0/0x210 fs/read_write.c:1309
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 0:
kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
kasan_set_track+0x25/0x30 mm/kasan/common.c:52
kasan_save_free_info+0x2e/0x40 mm/kasan/generic.c:521
____kasan_slab_free mm/kasan/common.c:236 [inline]
____kasan_slab_free+0x160/0x1c0 mm/kasan/common.c:200
kasan_slab_free include/linux/kasan.h:162 [inline]
slab_free_hook mm/slub.c:1781 [inline]
slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1807
slab_free mm/slub.c:3787 [inline]
kmem_cache_free+0xec/0x4e0 mm/slub.c:3809
mempool_free+0xe7/0x3b0 mm/mempool.c:507
__sg_free_table+0x122/0x1a0 lib/scatterlist.c:227
sg_free_table_chained+0x8d/0xa0 lib/sg_pool.c:93
scsi_free_sgtables drivers/scsi/scsi_lib.c:489 [inline]
scsi_mq_uninit_cmd drivers/scsi/scsi_lib.c:499 [inline]
scsi_end_request+0x70b/0xa20 drivers/scsi/scsi_lib.c:564
scsi_io_completion+0x177/0x1f80 drivers/scsi/scsi_lib.c:975
scsi_complete+0x126/0x3b0 drivers/scsi/scsi_lib.c:1439
blk_complete_reqs+0xad/0xe0 block/blk-mq.c:1131
__do_softirq+0x2e3/0xae3 kernel/softirq.c:571

The buggy address belongs to the object at ffff888078d1c640
which belongs to the cache sgpool-8 of size 256
The buggy address is located 0 bytes inside of
freed 256-byte region [ffff888078d1c640, ffff888078d1c740)

The buggy address belongs to the physical page:
page:ffffea0001e34700 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x78d1c
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffff8881451b3500 dead000000000122 0000000000000000
raw: 0000000000000000 00000000800c000c 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 0x92820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_NOMEMALLOC), pid 5400, tgid 5396 (syz-executor635), ts 61781478648, free_ts 51720251001
prep_new_page mm/page_alloc.c:2552 [inline]
get_page_from_freelist+0x11bb/0x2d50 mm/page_alloc.c:4328
__alloc_pages+0x1cb/0x5c0 mm/page_alloc.c:5594
alloc_pages+0x1aa/0x270 mm/mempolicy.c:2283
alloc_slab_page mm/slub.c:1851 [inline]
allocate_slab+0x28e/0x380 mm/slub.c:1998
new_slab mm/slub.c:2051 [inline]
___slab_alloc+0xa91/0x1400 mm/slub.c:3193
__slab_alloc.constprop.0+0x56/0xa0 mm/slub.c:3292
__slab_alloc_node mm/slub.c:3345 [inline]
slab_alloc_node mm/slub.c:3442 [inline]
slab_alloc mm/slub.c:3460 [inline]
__kmem_cache_alloc_lru mm/slub.c:3467 [inline]
kmem_cache_alloc+0x30a/0x320 mm/slub.c:3476
mempool_alloc+0x158/0x360 mm/mempool.c:398
__sg_alloc_table+0x248/0x380 lib/scatterlist.c:318
sg_alloc_table_chained+0x9f/0x1f0 lib/sg_pool.c:133
scsi_alloc_sgtables+0x1cd/0xf70 drivers/scsi/scsi_lib.c:1040
sd_setup_read_write_cmnd drivers/scsi/sd.c:1136 [inline]
sd_init_command+0x67a/0x32a0 drivers/scsi/sd.c:1260
scsi_prepare_cmd drivers/scsi/scsi_lib.c:1603 [inline]
scsi_queue_rq+0x1e7b/0x3a40 drivers/scsi/scsi_lib.c:1737
blk_mq_dispatch_rq_list+0x710/0x23f0 block/blk-mq.c:2056
__blk_mq_do_dispatch_sched block/blk-mq-sched.c:173 [inline]
blk_mq_do_dispatch_sched+0x95e/0xc20 block/blk-mq-sched.c:187
__blk_mq_sched_dispatch_requests+0x26d/0x3e0 block/blk-mq-sched.c:313
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1453 [inline]
free_pcp_prepare+0x4d0/0x910 mm/page_alloc.c:1503
free_unref_page_prepare mm/page_alloc.c:3390 [inline]
free_unref_page+0x1d/0x490 mm/page_alloc.c:3485
__unfreeze_partials+0x17c/0x1a0 mm/slub.c:2637
qlink_free mm/kasan/quarantine.c:168 [inline]
qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:187
kasan_quarantine_reduce+0x195/0x220 mm/kasan/quarantine.c:294
__kasan_slab_alloc+0x63/0x90 mm/kasan/common.c:305
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook mm/slab.h:769 [inline]
slab_alloc_node mm/slub.c:3452 [inline]
slab_alloc mm/slub.c:3460 [inline]
__kmem_cache_alloc_lru mm/slub.c:3467 [inline]
kmem_cache_alloc+0x175/0x320 mm/slub.c:3476
vm_area_dup+0x21/0x1f0 kernel/fork.c:466
__split_vma+0x199/0x810 mm/mmap.c:2172
do_vmi_align_munmap+0x34a/0xf60 mm/mmap.c:2320
do_vmi_munmap+0x26e/0x2c0 mm/mmap.c:2452
mmap_region+0x1ee/0x2690 mm/mmap.c:2500
do_mmap+0x831/0xf60 mm/mmap.c:1364
vm_mmap_pgoff+0x1af/0x280 mm/util.c:542
ksys_mmap_pgoff+0x41f/0x5a0 mm/mmap.c:1410
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80

Memory state around the buggy address:
ffff888078d1c500: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888078d1c580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888078d1c600: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
^
ffff888078d1c680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888078d1c700: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================

Hillf Danton

unread,
Feb 5, 2023, 7:34:13 AM2/5/23
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On 04 Feb 2023 15:12:40 -0800
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: 4fafd96910ad Add linux-next specific files for 20230203
> git tree: linux-next
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=166cc203480000

Init sgl before allocating table.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 4fafd96910ad

--- x/drivers/scsi/scsi_lib.c
+++ y/drivers/scsi/scsi_lib.c
@@ -1037,6 +1037,7 @@ blk_status_t scsi_alloc_sgtables(struct
/*
* If sg table allocation fails, requeue request later.
*/
+ cmd->sdb.table.sgl = NULL;
if (unlikely(sg_alloc_table_chained(&cmd->sdb.table, nr_segs,
cmd->sdb.table.sgl, SCSI_INLINE_SG_CNT)))
return BLK_STS_RESOURCE;
--

syzbot

unread,
Feb 5, 2023, 8:11:23 AM2/5/23
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-out-of-bounds Read in sg_next

==================================================================
BUG: KASAN: slab-out-of-bounds in __sg_flags include/linux/scatterlist.h:79 [inline]
BUG: KASAN: slab-out-of-bounds in sg_is_chain include/linux/scatterlist.h:89 [inline]
BUG: KASAN: slab-out-of-bounds in sg_next+0xaf/0xc0 lib/scatterlist.c:29
Read of size 8 at addr ffff88801733b380 by task syz-executor.3/5840

CPU: 1 PID: 5840 Comm: syz-executor.3 Not tainted 6.2.0-rc6-next-20230203-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/12/2023
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
print_address_description.constprop.0+0x2c/0x3c0 mm/kasan/report.c:319
print_report mm/kasan/report.c:430 [inline]
kasan_report+0x11c/0x130 mm/kasan/report.c:536
__sg_flags include/linux/scatterlist.h:79 [inline]
sg_is_chain include/linux/scatterlist.h:89 [inline]
sg_next+0xaf/0xc0 lib/scatterlist.c:29
blk_next_sg block/blk-merge.c:459 [inline]
__blk_bvec_map_sg block/blk-merge.c:500 [inline]
__blk_bios_map_sg block/blk-merge.c:548 [inline]
__blk_rq_map_sg+0x34a/0xfd0 block/blk-merge.c:575
scsi_alloc_sgtables+0x23c/0xf70 drivers/scsi/scsi_lib.c:1049
sd_setup_read_write_cmnd drivers/scsi/sd.c:1136 [inline]
sd_init_command+0x67a/0x32a0 drivers/scsi/sd.c:1260
scsi_prepare_cmd drivers/scsi/scsi_lib.c:1604 [inline]
scsi_queue_rq+0x1e7b/0x3a40 drivers/scsi/scsi_lib.c:1738
RIP: 0033:0x7f453ec8c0c9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 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:00007f453f980168 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
RAX: ffffffffffffffda RBX: 00007f453edac050 RCX: 00007f453ec8c0c9
RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000000000000005
RBP: 00007f453ece7ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000010000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffda01936ef R14: 00007f453f980300 R15: 0000000000022000
</TASK>

Allocated by task 5840:
kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
kasan_set_track+0x25/0x30 mm/kasan/common.c:52
__kasan_slab_alloc+0x7f/0x90 mm/kasan/common.c:328
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook mm/slab.h:769 [inline]
slab_alloc_node mm/slub.c:3452 [inline]
slab_alloc mm/slub.c:3460 [inline]
__kmem_cache_alloc_lru mm/slub.c:3467 [inline]
kmem_cache_alloc+0x175/0x320 mm/slub.c:3476
mempool_alloc+0x158/0x360 mm/mempool.c:398
__sg_alloc_table+0x248/0x380 lib/scatterlist.c:318
sg_alloc_table_chained+0x9f/0x1f0 lib/sg_pool.c:133
scsi_alloc_sgtables+0x1d3/0xf70 drivers/scsi/scsi_lib.c:1041
sd_setup_read_write_cmnd drivers/scsi/sd.c:1136 [inline]
sd_init_command+0x67a/0x32a0 drivers/scsi/sd.c:1260
scsi_prepare_cmd drivers/scsi/scsi_lib.c:1604 [inline]
scsi_queue_rq+0x1e7b/0x3a40 drivers/scsi/scsi_lib.c:1738
The buggy address belongs to the object at ffff88801733b280
which belongs to the cache sgpool-8 of size 256
The buggy address is located 0 bytes to the right of
allocated 256-byte region [ffff88801733b280, ffff88801733b380)

The buggy address belongs to the physical page:
page:ffffea00005ccec0 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1733b
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffff88814526f500 dead000000000122 0000000000000000
raw: 0000000000000000 00000000800c000c 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 0x192820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_NOMEMALLOC|__GFP_HARDWALL), pid 5839, tgid 5837 (syz-executor.3), ts 93322224247, free_ts 93320303745
prep_new_page mm/page_alloc.c:2552 [inline]
get_page_from_freelist+0x11bb/0x2d50 mm/page_alloc.c:4328
__alloc_pages+0x1cb/0x5c0 mm/page_alloc.c:5594
alloc_pages+0x1aa/0x270 mm/mempolicy.c:2283
alloc_slab_page mm/slub.c:1851 [inline]
allocate_slab+0x28e/0x380 mm/slub.c:1998
new_slab mm/slub.c:2051 [inline]
___slab_alloc+0xa91/0x1400 mm/slub.c:3193
__slab_alloc.constprop.0+0x56/0xa0 mm/slub.c:3292
__slab_alloc_node mm/slub.c:3345 [inline]
slab_alloc_node mm/slub.c:3442 [inline]
slab_alloc mm/slub.c:3460 [inline]
__kmem_cache_alloc_lru mm/slub.c:3467 [inline]
kmem_cache_alloc+0x30a/0x320 mm/slub.c:3476
mempool_alloc+0x158/0x360 mm/mempool.c:398
__sg_alloc_table+0x248/0x380 lib/scatterlist.c:318
sg_alloc_table_chained+0x9f/0x1f0 lib/sg_pool.c:133
scsi_alloc_sgtables+0x1d3/0xf70 drivers/scsi/scsi_lib.c:1041
sd_setup_read_write_cmnd drivers/scsi/sd.c:1136 [inline]
sd_init_command+0x67a/0x32a0 drivers/scsi/sd.c:1260
scsi_prepare_cmd drivers/scsi/scsi_lib.c:1604 [inline]
scsi_queue_rq+0x1e7b/0x3a40 drivers/scsi/scsi_lib.c:1738
blk_mq_dispatch_rq_list+0x710/0x23f0 block/blk-mq.c:2056
__blk_mq_do_dispatch_sched block/blk-mq-sched.c:173 [inline]
blk_mq_do_dispatch_sched+0x95e/0xc20 block/blk-mq-sched.c:187
__blk_mq_sched_dispatch_requests+0x26d/0x3e0 block/blk-mq-sched.c:313
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1453 [inline]
free_pcp_prepare+0x4d0/0x910 mm/page_alloc.c:1503
free_unref_page_prepare mm/page_alloc.c:3390 [inline]
free_unref_page+0x1d/0x490 mm/page_alloc.c:3485
__folio_put_small mm/swap.c:106 [inline]
__folio_put+0xc5/0x140 mm/swap.c:129
folio_put include/linux/mm.h:1304 [inline]
put_page include/linux/mm.h:1373 [inline]
generic_pipe_buf_release+0x23d/0x2b0 fs/pipe.c:210
pipe_buf_release include/linux/pipe_fs_i.h:183 [inline]
iov_iter_revert.part.0+0x402/0x730 lib/iov_iter.c:935
iov_iter_revert+0x4c/0x60 lib/iov_iter.c:919
__iomap_dio_rw+0x16cb/0x1d80 fs/iomap/direct-io.c:610
iomap_dio_rw+0x40/0xa0 fs/iomap/direct-io.c:682
ext4_dio_read_iter fs/ext4/file.c:94 [inline]
ext4_file_read_iter+0x4be/0x690 fs/ext4/file.c:145
call_read_iter include/linux/fs.h:1845 [inline]
generic_file_splice_read+0x182/0x4b0 fs/splice.c:309
do_splice_to+0x1b9/0x240 fs/splice.c:793
splice_direct_to_actor+0x2ab/0x8a0 fs/splice.c:865
do_splice_direct+0x1ab/0x280 fs/splice.c:974
do_sendfile+0xb19/0x12c0 fs/read_write.c:1255
__do_sys_sendfile64 fs/read_write.c:1323 [inline]
__se_sys_sendfile64 fs/read_write.c:1309 [inline]
__x64_sys_sendfile64+0x1d0/0x210 fs/read_write.c:1309
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80

Memory state around the buggy address:
ffff88801733b280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff88801733b300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff88801733b380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
^
ffff88801733b400: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88801733b480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================


Tested on:

commit: 4fafd969 Add linux-next specific files for 20230203
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
console output: https://syzkaller.appspot.com/x/log.txt?x=166ef3ad480000
kernel config: https://syzkaller.appspot.com/x/.config?x=1d2fba7d42502ca4
dashboard link: https://syzkaller.appspot.com/bug?extid=0bbf896c8341c8e137c2
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=173f904b480000

Hillf Danton

unread,
Feb 5, 2023, 9:17:38 AM2/5/23
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On 04 Feb 2023 15:12:40 -0800
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: 4fafd96910ad Add linux-next specific files for 20230203
> git tree: linux-next
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=166cc203480000

Init sgl before allocating table.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 4fafd96910ad

--- x/drivers/scsi/scsi_lib.c
+++ y/drivers/scsi/scsi_lib.c
@@ -1037,6 +1037,7 @@ blk_status_t scsi_alloc_sgtables(struct
/*
* If sg table allocation fails, requeue request later.
*/
+ cmd->sdb.table.sgl = NULL;
if (unlikely(sg_alloc_table_chained(&cmd->sdb.table, nr_segs,
cmd->sdb.table.sgl, SCSI_INLINE_SG_CNT)))
return BLK_STS_RESOURCE;
--- x/block/blk-merge.c
+++ y/block/blk-merge.c
@@ -455,7 +455,6 @@ static inline struct scatterlist *blk_ne
* or the driver would be buggy, so force clear the termination bit
* to avoid doing a full sg_init_table() in drivers for each command.
*/
- sg_unmark_end(*sg);
return sg_next(*sg);
}

--

syzbot

unread,
Feb 5, 2023, 9:44:19 AM2/5/23
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
general protection fault in do_exit

general protection fault, probably for non-canonical address 0xdffffc000000000e: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000070-0x0000000000000077]
CPU: 1 PID: 5774 Comm: syz-executor.4 Not tainted 6.2.0-rc6-next-20230203-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/12/2023
RIP: 0010:find_child_reaper kernel/exit.c:585 [inline]
RIP: 0010:forget_original_parent kernel/exit.c:693 [inline]
RIP: 0010:exit_notify kernel/exit.c:730 [inline]
RIP: 0010:do_exit+0xbd7/0x2b60 kernel/exit.c:889
Code: 85 89 12 00 00 e8 79 fa 36 00 48 89 df e8 21 1c 07 00 48 8d 78 70 48 89 c5 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 62 1b 00 00 48 8b 45 70 48 39 c3 48 89 04 24 0f
RSP: 0018:ffffc90005d9fc00 EFLAGS: 00010002
RAX: dffffc0000000000 RBX: ffff88801901d7c0 RCX: 0000000000000000
RDX: 000000000000000e RSI: ffffffff81548cf9 RDI: 0000000000000070
RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000003
R10: fffff52000bb3f72 R11: 0000000000000000 R12: 0000000000000001
R13: ffff88807ef04028 R14: 0000000000000000 R15: 0000000000000001
FS: 0000000000000000(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fe617f4e718 CR3: 000000002923b000 CR4: 00000000003506e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
do_group_exit+0xd4/0x2a0 kernel/exit.c:1019
get_signal+0x2321/0x25b0 kernel/signal.c:2859
arch_do_signal_or_restart+0x79/0x5c0 arch/x86/kernel/signal.c:306
exit_to_user_mode_loop kernel/entry/common.c:168 [inline]
exit_to_user_mode_prepare+0x11f/0x240 kernel/entry/common.c:204
__syscall_exit_to_user_mode_work kernel/entry/common.c:286 [inline]
syscall_exit_to_user_mode+0x1d/0x50 kernel/entry/common.c:297
do_syscall_64+0x46/0xb0 arch/x86/entry/common.c:86
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fe61728c0c9
Code: Unable to access opcode bytes at 0x7fe61728c09f.
RSP: 002b:00007fe617f6f218 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca
RAX: 0000000000000001 RBX: 00007fe6173abf88 RCX: 00007fe61728c0c9
RDX: 00000000000f4240 RSI: 0000000000000081 RDI: 00007fe6173abf8c
RBP: 00007fe6173abf80 R08: 00007ffe35fc5080 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007fe6173abf8c
R13: 00007ffe35e051ff R14: 00007fe617f6f300 R15: 0000000000022000
</TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:find_child_reaper kernel/exit.c:585 [inline]
RIP: 0010:forget_original_parent kernel/exit.c:693 [inline]
RIP: 0010:exit_notify kernel/exit.c:730 [inline]
RIP: 0010:do_exit+0xbd7/0x2b60 kernel/exit.c:889
Code: 85 89 12 00 00 e8 79 fa 36 00 48 89 df e8 21 1c 07 00 48 8d 78 70 48 89 c5 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 62 1b 00 00 48 8b 45 70 48 39 c3 48 89 04 24 0f
RSP: 0018:ffffc90005d9fc00 EFLAGS: 00010002
RAX: dffffc0000000000 RBX: ffff88801901d7c0 RCX: 0000000000000000
RDX: 000000000000000e RSI: ffffffff81548cf9 RDI: 0000000000000070
RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000003
R10: fffff52000bb3f72 R11: 0000000000000000 R12: 0000000000000001
R13: ffff88807ef04028 R14: 0000000000000000 R15: 0000000000000001
FS: 0000000000000000(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fe617f4e718 CR3: 000000002923b000 CR4: 00000000003506e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: 85 89 12 00 00 e8 test %ecx,-0x17ffffee(%rcx)
6: 79 fa jns 0x2
8: 36 00 48 89 add %cl,%ss:-0x77(%rax)
c: df e8 fucomip %st(0),%st
e: 21 1c 07 and %ebx,(%rdi,%rax,1)
11: 00 48 8d add %cl,-0x73(%rax)
14: 78 70 js 0x86
16: 48 89 c5 mov %rax,%rbp
19: 48 b8 00 00 00 00 00 movabs $0xdffffc0000000000,%rax
20: fc ff df
23: 48 89 fa mov %rdi,%rdx
26: 48 c1 ea 03 shr $0x3,%rdx
* 2a: 80 3c 02 00 cmpb $0x0,(%rdx,%rax,1) <-- trapping instruction
2e: 0f 85 62 1b 00 00 jne 0x1b96
34: 48 8b 45 70 mov 0x70(%rbp),%rax
38: 48 39 c3 cmp %rax,%rbx
3b: 48 89 04 24 mov %rax,(%rsp)
3f: 0f .byte 0xf


Tested on:

commit: 4fafd969 Add linux-next specific files for 20230203
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
console output: https://syzkaller.appspot.com/x/log.txt?x=12b901bb480000
kernel config: https://syzkaller.appspot.com/x/.config?x=1d2fba7d42502ca4
dashboard link: https://syzkaller.appspot.com/bug?extid=0bbf896c8341c8e137c2
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=14d1b8f5480000

syzbot

unread,
Jul 25, 2023, 10:06:45 PM7/25/23
to syzkall...@googlegroups.com
Auto-closing this bug as obsolete.
No recent activity, existing reproducers are no longer triggering the issue.
Reply all
Reply to author
Forward
0 new messages