* [syzbot] [erofs?] general protection fault in z_erofs_gbuf_growsize
@ 2024-08-20 7:57 syzbot
2024-08-20 8:42 ` [PATCH] erofs: fix out-of-bound access when z_erofs_gbuf_growsize() partially fails Gao Xiang
2024-08-20 8:56 ` [PATCH RESEND] " Gao Xiang
0 siblings, 2 replies; 7+ messages in thread
From: syzbot @ 2024-08-20 7:57 UTC (permalink / raw)
To: chao, dhavale, huyue2, jefflexu, linux-erofs, linux-kernel,
syzkaller-bugs, xiang
Hello,
syzbot found the following issue on:
HEAD commit: 1fb918967b56 Merge tag 'for-6.11-rc3-tag' of git://git.ker..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=110fcf5d980000
kernel config: https://syzkaller.appspot.com/x/.config?x=7229118d88b4a71b
dashboard link: https://syzkaller.appspot.com/bug?extid=242ee56aaa9585553766
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
Unfortunately, I don't have any reproducer for this issue yet.
Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/7bc7510fe41f/non_bootable_disk-1fb91896.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/cd6e8883313a/vmlinux-1fb91896.xz
kernel image: https://storage.googleapis.com/syzbot-assets/87b718d2d1df/bzImage-1fb91896.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+242ee56aaa9585553766@syzkaller.appspotmail.com
loop0: detected capacity change from 0 to 16
FAULT_INJECTION: forcing a failure.
name failslab, interval 1, probability 0, space 0, times 1
CPU: 0 UID: 0 PID: 5102 Comm: syz.0.0 Not tainted 6.11.0-rc3-syzkaller-00066-g1fb918967b56 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:93 [inline]
dump_stack_lvl+0x241/0x360 lib/dump_stack.c:119
fail_dump lib/fault-inject.c:52 [inline]
should_fail_ex+0x3b0/0x4e0 lib/fault-inject.c:153
should_failslab+0xac/0x100 mm/failslab.c:45
slab_pre_alloc_hook mm/slub.c:3941 [inline]
slab_alloc_node mm/slub.c:4017 [inline]
kmem_cache_alloc_node_noprof+0x71/0x320 mm/slub.c:4080
alloc_vmap_area+0x24f/0x2400 mm/vmalloc.c:1986
__get_vm_area_node+0x1a9/0x270 mm/vmalloc.c:3119
get_vm_area_caller mm/vmalloc.c:3170 [inline]
vmap+0x119/0x2b0 mm/vmalloc.c:3439
z_erofs_gbuf_growsize+0x262/0x520 fs/erofs/zutil.c:96
z_erofs_load_lz4_config fs/erofs/decompressor.c:58 [inline]
z_erofs_parse_cfgs+0x1e6/0x680 fs/erofs/decompressor.c:494
erofs_read_superblock fs/erofs/super.c:357 [inline]
erofs_fc_fill_super+0x1194/0x1730 fs/erofs/super.c:628
get_tree_bdev+0x3f7/0x570 fs/super.c:1635
vfs_get_tree+0x90/0x2a0 fs/super.c:1800
do_new_mount+0x2be/0xb40 fs/namespace.c:3472
do_mount fs/namespace.c:3812 [inline]
__do_sys_mount fs/namespace.c:4020 [inline]
__se_sys_mount+0x2d6/0x3c0 fs/namespace.c:3997
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fe726b7b0ba
Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb a6 e8 7e 1a 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fe727918e68 EFLAGS: 00000202 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007fe727918ef0 RCX: 00007fe726b7b0ba
RDX: 0000000020000180 RSI: 00000000200001c0 RDI: 00007fe727918eb0
RBP: 0000000020000180 R08: 00007fe727918ef0 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 00000000200001c0
R13: 00007fe727918eb0 R14: 0000000000000174 R15: 0000000020000240
</TASK>
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
CPU: 0 UID: 0 PID: 5102 Comm: syz.0.0 Not tainted 6.11.0-rc3-syzkaller-00066-g1fb918967b56 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
RIP: 0010:z_erofs_gbuf_growsize+0x45f/0x520 fs/erofs/zutil.c:114
Code: 57 dc 9e fd 48 8b 1b 48 85 db 74 44 43 80 3c 26 00 74 08 4c 89 ef e8 40 dc 9e fd 48 c1 e5 03 49 03 6d 00 48 89 e8 48 c1 e8 03 <42> 80 3c 20 00 74 08 48 89 ef e8 22 dc 9e fd 48 3b 5d 00 74 18 e8
RSP: 0018:ffffc90002e4f918 EFLAGS: 00010246
RAX: 0000000000000000 RBX: ffffea000117ce40 RCX: ffff888020388000
RDX: ffff888020388000 RSI: 0000000000000001 RDI: 0000000000000000
RBP: 0000000000000000 R08: ffffffff845bf21b R09: 1ffffffff26e5f27
R10: dffffc0000000000 R11: fffffbfff26e5f28 R12: dffffc0000000000
R13: ffff88803267dcc8 R14: 1ffff110064cfb99 R15: 0000000000000000
FS: 00007fe7279196c0(0000) GS:ffff888020800000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fc5da995ed8 CR3: 00000000369c6000 CR4: 0000000000350ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
z_erofs_load_lz4_config fs/erofs/decompressor.c:58 [inline]
z_erofs_parse_cfgs+0x1e6/0x680 fs/erofs/decompressor.c:494
erofs_read_superblock fs/erofs/super.c:357 [inline]
erofs_fc_fill_super+0x1194/0x1730 fs/erofs/super.c:628
get_tree_bdev+0x3f7/0x570 fs/super.c:1635
vfs_get_tree+0x90/0x2a0 fs/super.c:1800
do_new_mount+0x2be/0xb40 fs/namespace.c:3472
do_mount fs/namespace.c:3812 [inline]
__do_sys_mount fs/namespace.c:4020 [inline]
__se_sys_mount+0x2d6/0x3c0 fs/namespace.c:3997
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fe726b7b0ba
Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb a6 e8 7e 1a 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fe727918e68 EFLAGS: 00000202 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007fe727918ef0 RCX: 00007fe726b7b0ba
RDX: 0000000020000180 RSI: 00000000200001c0 RDI: 00007fe727918eb0
RBP: 0000000020000180 R08: 00007fe727918ef0 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 00000000200001c0
R13: 00007fe727918eb0 R14: 0000000000000174 R15: 0000000020000240
</TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:z_erofs_gbuf_growsize+0x45f/0x520 fs/erofs/zutil.c:114
Code: 57 dc 9e fd 48 8b 1b 48 85 db 74 44 43 80 3c 26 00 74 08 4c 89 ef e8 40 dc 9e fd 48 c1 e5 03 49 03 6d 00 48 89 e8 48 c1 e8 03 <42> 80 3c 20 00 74 08 48 89 ef e8 22 dc 9e fd 48 3b 5d 00 74 18 e8
RSP: 0018:ffffc90002e4f918 EFLAGS: 00010246
RAX: 0000000000000000 RBX: ffffea000117ce40 RCX: ffff888020388000
RDX: ffff888020388000 RSI: 0000000000000001 RDI: 0000000000000000
RBP: 0000000000000000 R08: ffffffff845bf21b R09: 1ffffffff26e5f27
R10: dffffc0000000000 R11: fffffbfff26e5f28 R12: dffffc0000000000
R13: ffff88803267dcc8 R14: 1ffff110064cfb99 R15: 0000000000000000
FS: 00007fe7279196c0(0000) GS:ffff888020800000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fc5da995ed8 CR3: 00000000369c6000 CR4: 0000000000350ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: 57 push %rdi
1: dc 9e fd 48 8b 1b fcompl 0x1b8b48fd(%rsi)
7: 48 85 db test %rbx,%rbx
a: 74 44 je 0x50
c: 43 80 3c 26 00 cmpb $0x0,(%r14,%r12,1)
11: 74 08 je 0x1b
13: 4c 89 ef mov %r13,%rdi
16: e8 40 dc 9e fd call 0xfd9edc5b
1b: 48 c1 e5 03 shl $0x3,%rbp
1f: 49 03 6d 00 add 0x0(%r13),%rbp
23: 48 89 e8 mov %rbp,%rax
26: 48 c1 e8 03 shr $0x3,%rax
* 2a: 42 80 3c 20 00 cmpb $0x0,(%rax,%r12,1) <-- trapping instruction
2f: 74 08 je 0x39
31: 48 89 ef mov %rbp,%rdi
34: e8 22 dc 9e fd call 0xfd9edc5b
39: 48 3b 5d 00 cmp 0x0(%rbp),%rbx
3d: 74 18 je 0x57
3f: e8 .byte 0xe8
---
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 syzkaller@googlegroups.com.
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] erofs: fix out-of-bound access when z_erofs_gbuf_growsize() partially fails
2024-08-20 7:57 [syzbot] [erofs?] general protection fault in z_erofs_gbuf_growsize syzbot
@ 2024-08-20 8:42 ` Gao Xiang
2024-08-20 9:25 ` Chunhai Guo
2024-08-20 8:56 ` [PATCH RESEND] " Gao Xiang
1 sibling, 1 reply; 7+ messages in thread
From: Gao Xiang @ 2024-08-20 8:42 UTC (permalink / raw)
To: linux-erofs; +Cc: LKML, Gao Xiang, stable, Chunhai Guo
If z_erofs_gbuf_growsize() partially fails on a global buffer due to
memory allocation failure or fault injection (as reported by syzbot [1]),
new pages need to be freed by comparing to the existing pages to avoid
memory leaks.
However, the old gbuf->pages[] array may not be large enough, which can
lead to null-ptr-deref or out-of-bound access.
Fix this by checking against gbuf->nrpages in advance.
Fixes: d6db47e571dc ("erofs: do not use pagepool in z_erofs_gbuf_growsize()")
Cc: <stable@vger.kernel.org> # 6.10+
Cc: Chunhai Guo <guochunhai@vivo.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
fs/erofs/zutil.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/erofs/zutil.c b/fs/erofs/zutil.c
index 9b53883e5caf..37afe2024840 100644
--- a/fs/erofs/zutil.c
+++ b/fs/erofs/zutil.c
@@ -111,7 +111,8 @@ int z_erofs_gbuf_growsize(unsigned int nrpages)
out:
if (i < z_erofs_gbuf_count && tmp_pages) {
for (j = 0; j < nrpages; ++j)
- if (tmp_pages[j] && tmp_pages[j] != gbuf->pages[j])
+ if (tmp_pages[j] && (j >= gbuf->nrpages ||
+ tmp_pages[j] != gbuf->pages[j]))
__free_page(tmp_pages[j]);
kfree(tmp_pages);
}
--
2.43.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH RESEND] erofs: fix out-of-bound access when z_erofs_gbuf_growsize() partially fails
2024-08-20 7:57 [syzbot] [erofs?] general protection fault in z_erofs_gbuf_growsize syzbot
2024-08-20 8:42 ` [PATCH] erofs: fix out-of-bound access when z_erofs_gbuf_growsize() partially fails Gao Xiang
@ 2024-08-20 8:56 ` Gao Xiang
2024-08-20 18:14 ` Sandeep Dhavale
1 sibling, 1 reply; 7+ messages in thread
From: Gao Xiang @ 2024-08-20 8:56 UTC (permalink / raw)
To: linux-erofs
Cc: LKML, Gao Xiang, syzbot+242ee56aaa9585553766, stable, Chunhai Guo
If z_erofs_gbuf_growsize() partially fails on a global buffer due to
memory allocation failure or fault injection (as reported by syzbot [1]),
new pages need to be freed by comparing to the existing pages to avoid
memory leaks.
However, the old gbuf->pages[] array may not be large enough, which can
lead to null-ptr-deref or out-of-bound access.
Fix this by checking against gbuf->nrpages in advance.
[1] https://lore.kernel.org/r/000000000000f7b96e062018c6e3@google.com
Reported-by: syzbot+242ee56aaa9585553766@syzkaller.appspotmail.com
Fixes: d6db47e571dc ("erofs: do not use pagepool in z_erofs_gbuf_growsize()")
Cc: <stable@vger.kernel.org> # 6.10+
Cc: Chunhai Guo <guochunhai@vivo.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
RESEND:
Add missing link and reported-by.
fs/erofs/zutil.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/erofs/zutil.c b/fs/erofs/zutil.c
index 9b53883e5caf..37afe2024840 100644
--- a/fs/erofs/zutil.c
+++ b/fs/erofs/zutil.c
@@ -111,7 +111,8 @@ int z_erofs_gbuf_growsize(unsigned int nrpages)
out:
if (i < z_erofs_gbuf_count && tmp_pages) {
for (j = 0; j < nrpages; ++j)
- if (tmp_pages[j] && tmp_pages[j] != gbuf->pages[j])
+ if (tmp_pages[j] && (j >= gbuf->nrpages ||
+ tmp_pages[j] != gbuf->pages[j]))
__free_page(tmp_pages[j]);
kfree(tmp_pages);
}
--
2.43.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] erofs: fix out-of-bound access when z_erofs_gbuf_growsize() partially fails
2024-08-20 8:42 ` [PATCH] erofs: fix out-of-bound access when z_erofs_gbuf_growsize() partially fails Gao Xiang
@ 2024-08-20 9:25 ` Chunhai Guo
2024-08-20 9:27 ` Gao Xiang
0 siblings, 1 reply; 7+ messages in thread
From: Chunhai Guo @ 2024-08-20 9:25 UTC (permalink / raw)
To: Gao Xiang, linux-erofs; +Cc: LKML, stable, Chunhai Guo
在 2024/8/20 16:42, Gao Xiang 写道:
> If z_erofs_gbuf_growsize() partially fails on a global buffer due to
> memory allocation failure or fault injection (as reported by syzbot [1]),
> new pages need to be freed by comparing to the existing pages to avoid
> memory leaks.
>
> However, the old gbuf->pages[] array may not be large enough, which can
> lead to null-ptr-deref or out-of-bound access.
>
> Fix this by checking against gbuf->nrpages in advance.
>
> Fixes: d6db47e571dc ("erofs: do not use pagepool in z_erofs_gbuf_growsize()")
> Cc: <stable@vger.kernel.org> # 6.10+
> Cc: Chunhai Guo <guochunhai@vivo.com>
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>
Reviewed-by: Chunhai Guo <guochunhai@vivo.com>
Thanks,
Chunhai Guo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] erofs: fix out-of-bound access when z_erofs_gbuf_growsize() partially fails
2024-08-20 9:25 ` Chunhai Guo
@ 2024-08-20 9:27 ` Gao Xiang
2024-08-20 9:31 ` Chunhai Guo
0 siblings, 1 reply; 7+ messages in thread
From: Gao Xiang @ 2024-08-20 9:27 UTC (permalink / raw)
To: Chunhai Guo, linux-erofs; +Cc: LKML, stable
Hi Chunhai,
On 2024/8/20 17:25, Chunhai Guo wrote:
> 在 2024/8/20 16:42, Gao Xiang 写道:
>> If z_erofs_gbuf_growsize() partially fails on a global buffer due to
>> memory allocation failure or fault injection (as reported by syzbot [1]),
>> new pages need to be freed by comparing to the existing pages to avoid
>> memory leaks.
>>
>> However, the old gbuf->pages[] array may not be large enough, which can
>> lead to null-ptr-deref or out-of-bound access.
>>
>> Fix this by checking against gbuf->nrpages in advance.
>>
>> Fixes: d6db47e571dc ("erofs: do not use pagepool in z_erofs_gbuf_growsize()")
>> Cc: <stable@vger.kernel.org> # 6.10+
>> Cc: Chunhai Guo <guochunhai@vivo.com>
>> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>>
> Reviewed-by: Chunhai Guo <guochunhai@vivo.com>
I've sent a patch to add links and reported-by.
I assume I can add your reviewed-by to that version too?
Thanks,
Gao Xiang
>
> Thanks,
>
> Chunhai Guo
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] erofs: fix out-of-bound access when z_erofs_gbuf_growsize() partially fails
2024-08-20 9:27 ` Gao Xiang
@ 2024-08-20 9:31 ` Chunhai Guo
0 siblings, 0 replies; 7+ messages in thread
From: Chunhai Guo @ 2024-08-20 9:31 UTC (permalink / raw)
To: Gao Xiang, Chunhai Guo, linux-erofs; +Cc: LKML, stable
在 2024/8/20 17:27, Gao Xiang 写道:
> Hi Chunhai,
>
> On 2024/8/20 17:25, Chunhai Guo wrote:
>> 在 2024/8/20 16:42, Gao Xiang 写道:
>>> If z_erofs_gbuf_growsize() partially fails on a global buffer due to
>>> memory allocation failure or fault injection (as reported by syzbot
>>> [1]),
>>> new pages need to be freed by comparing to the existing pages to avoid
>>> memory leaks.
>>>
>>> However, the old gbuf->pages[] array may not be large enough, which can
>>> lead to null-ptr-deref or out-of-bound access.
>>>
>>> Fix this by checking against gbuf->nrpages in advance.
>>>
>>> Fixes: d6db47e571dc ("erofs: do not use pagepool in
>>> z_erofs_gbuf_growsize()")
>>> Cc: <stable@vger.kernel.org> # 6.10+
>>> Cc: Chunhai Guo <guochunhai@vivo.com>
>>> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>>>
>> Reviewed-by: Chunhai Guo <guochunhai@vivo.com>
>
> I've sent a patch to add links and reported-by.
>
> I assume I can add your reviewed-by to that version too?
Yes. That is right.
Thanks,
>
> Thanks,
> Gao Xiang
>
>>
>> Thanks,
>>
>> Chunhai Guo
>>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RESEND] erofs: fix out-of-bound access when z_erofs_gbuf_growsize() partially fails
2024-08-20 8:56 ` [PATCH RESEND] " Gao Xiang
@ 2024-08-20 18:14 ` Sandeep Dhavale
0 siblings, 0 replies; 7+ messages in thread
From: Sandeep Dhavale @ 2024-08-20 18:14 UTC (permalink / raw)
To: Gao Xiang
Cc: linux-erofs, syzbot+242ee56aaa9585553766, LKML, stable,
Chunhai Guo, kernel-team
Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Thanks,
Sandeep.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-08-20 18:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-20 7:57 [syzbot] [erofs?] general protection fault in z_erofs_gbuf_growsize syzbot
2024-08-20 8:42 ` [PATCH] erofs: fix out-of-bound access when z_erofs_gbuf_growsize() partially fails Gao Xiang
2024-08-20 9:25 ` Chunhai Guo
2024-08-20 9:27 ` Gao Xiang
2024-08-20 9:31 ` Chunhai Guo
2024-08-20 8:56 ` [PATCH RESEND] " Gao Xiang
2024-08-20 18:14 ` Sandeep Dhavale
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®