* [syzbot] [hfs?] kernel BUG in hfsplus_show_options
@ 2023-07-18 10:57 syzbot
2023-07-19 1:27 ` syzbot
0 siblings, 1 reply; 8+ messages in thread
From: syzbot @ 2023-07-18 10:57 UTC (permalink / raw)
To: linux-fsdevel, linux-kernel, syzkaller-bugs
Hello,
syzbot found the following issue on:
HEAD commit: aeba456828b4 Add linux-next specific files for 20230718
git tree: linux-next
console+strace: https://syzkaller.appspot.com/x/log.txt?x=111d6a62a80000
kernel config: https://syzkaller.appspot.com/x/.config?x=e7ec534f91cfce6c
dashboard link: https://syzkaller.appspot.com/bug?extid=98d3ceb7e01269e7bf4f
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15ecf646a80000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1476f30aa80000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/94f67a948e1d/disk-aeba4568.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/9818a252eddd/vmlinux-aeba4568.xz
kernel image: https://storage.googleapis.com/syzbot-assets/fbf9befe9bc9/bzImage-aeba4568.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/d8265d21ad1c/mount_0.gz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+98d3ceb7e01269e7bf4f@syzkaller.appspotmail.com
memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=5032 'syz-executor324'
loop0: detected capacity change from 0 to 1024
detected buffer overflow in strnlen
------------[ cut here ]------------
kernel BUG at lib/string_helpers.c:1031!
invalid opcode: 0000 [#1] PREEMPT SMP KASAN
CPU: 0 PID: 5032 Comm: syz-executor324 Not tainted 6.5.0-rc2-next-20230718-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/03/2023
RIP: 0010:fortify_panic+0x1c/0x20 lib/string_helpers.c:1031
Code: ba fd eb d7 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 53 48 89 fb e8 23 de 65 fd 48 89 de 48 c7 c7 00 2c c8 8a e8 e4 28 49 fd <0f> 0b 66 90 f3 0f 1e fa 41 55 41 54 55 53 48 89 fb e8 fe dd 65 fd
RSP: 0018:ffffc90003a1f7b8 EFLAGS: 00010282
RAX: 0000000000000023 RBX: ffffffff8a873580 RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffffffff816aad20 RDI: 0000000000000005
RBP: ffff888019f16cb8 R08: 0000000000000005 R09: 0000000000000000
R10: 0000000080000000 R11: 0000000000000001 R12: 1ffff92000743efa
R13: 0000000000000004 R14: ffff888078fa69c0 R15: ffffc90003a1f7f0
FS: 0000555556e72380(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000456b30 CR3: 0000000079883000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
strnlen include/linux/fortify-string.h:181 [inline]
strscpy include/linux/fortify-string.h:324 [inline]
hfsplus_show_options+0x658/0x740 fs/hfsplus/options.c:226
show_mountinfo+0x671/0x990 fs/proc_namespace.c:191
seq_read_iter+0xaf0/0x1280 fs/seq_file.c:272
call_read_iter include/linux/fs.h:1911 [inline]
copy_splice_read+0x418/0x8f0 fs/splice.c:366
vfs_splice_read fs/splice.c:993 [inline]
vfs_splice_read+0x2c8/0x3b0 fs/splice.c:962
splice_direct_to_actor+0x2a5/0xa30 fs/splice.c:1069
do_splice_direct+0x1af/0x280 fs/splice.c:1194
do_sendfile+0xb88/0x1390 fs/read_write.c:1254
__do_sys_sendfile64 fs/read_write.c:1322 [inline]
__se_sys_sendfile64 fs/read_write.c:1308 [inline]
__x64_sys_sendfile64+0x1d6/0x220 fs/read_write.c:1308
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f4339573a79
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 61 17 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:00007ffff9271428 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
RAX: ffffffffffffffda RBX: 00007ffff9271430 RCX: 00007f4339573a79
RDX: 0000000000000000 RSI: 0000000000000005 RDI: 0000000000000004
RBP: 00007f43395e7610 R08: 0000000000000000 R09: 65732f636f72702f
R10: 0800000080004105 R11: 0000000000000246 R12: 0000000000000001
R13: 00007ffff9271668 R14: 0000000000000001 R15: 0000000000000001
</TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:fortify_panic+0x1c/0x20 lib/string_helpers.c:1031
Code: ba fd eb d7 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 53 48 89 fb e8 23 de 65 fd 48 89 de 48 c7 c7 00 2c c8 8a e8 e4 28 49 fd <0f> 0b 66 90 f3 0f 1e fa 41 55 41 54 55 53 48 89 fb e8 fe dd 65 fd
RSP: 0018:ffffc90003a1f7b8 EFLAGS: 00010282
RAX: 0000000000000023 RBX: ffffffff8a873580 RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffffffff816aad20 RDI: 0000000000000005
RBP: ffff888019f16cb8 R08: 0000000000000005 R09: 0000000000000000
R10: 0000000080000000 R11: 0000000000000001 R12: 1ffff92000743efa
R13: 0000000000000004 R14: ffff888078fa69c0 R15: ffffc90003a1f7f0
FS: 0000555556e72380(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000456b30 CR3: 0000000079883000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
---
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 bug is already fixed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
If you want to change bug's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the bug is a duplicate of another bug, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [syzbot] [hfs?] kernel BUG in hfsplus_show_options
2023-07-18 10:57 [syzbot] [hfs?] kernel BUG in hfsplus_show_options syzbot
@ 2023-07-19 1:27 ` syzbot
2023-07-19 4:18 ` Kees Cook
0 siblings, 1 reply; 8+ messages in thread
From: syzbot @ 2023-07-19 1:27 UTC (permalink / raw)
To: andriy.shevchenko, keescook, linux-fsdevel, linux-kernel,
syzkaller-bugs
syzbot has bisected this issue to:
commit c30417b20f4993e49406f3f6d986355c6e943aa2
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Mon Jul 17 09:33:32 2023 +0000
seq_file: Replace strncpy()+nul by strscpy()
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=17488c1aa80000
start commit: aeba456828b4 Add linux-next specific files for 20230718
git tree: linux-next
final oops: https://syzkaller.appspot.com/x/report.txt?x=14c88c1aa80000
console output: https://syzkaller.appspot.com/x/log.txt?x=10c88c1aa80000
kernel config: https://syzkaller.appspot.com/x/.config?x=e7ec534f91cfce6c
dashboard link: https://syzkaller.appspot.com/bug?extid=98d3ceb7e01269e7bf4f
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15ecf646a80000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1476f30aa80000
Reported-by: syzbot+98d3ceb7e01269e7bf4f@syzkaller.appspotmail.com
Fixes: c30417b20f49 ("seq_file: Replace strncpy()+nul by strscpy()")
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [syzbot] [hfs?] kernel BUG in hfsplus_show_options
2023-07-19 1:27 ` syzbot
@ 2023-07-19 4:18 ` Kees Cook
2023-07-24 22:48 ` [PATCH] fortify: strnlen: Call fortify_panic() only if the number of bytes read is greater than maxlen sel4
0 siblings, 1 reply; 8+ messages in thread
From: Kees Cook @ 2023-07-19 4:18 UTC (permalink / raw)
To: syzbot, andriy.shevchenko, keescook, linux-fsdevel, linux-kernel,
syzkaller-bugs
On July 18, 2023 6:27:23 PM PDT, syzbot <syzbot+98d3ceb7e01269e7bf4f@syzkaller.appspotmail.com> wrote:
>syzbot has bisected this issue to:
>
>commit c30417b20f4993e49406f3f6d986355c6e943aa2
>Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>Date: Mon Jul 17 09:33:32 2023 +0000
>
> seq_file: Replace strncpy()+nul by strscpy()
Uh... Wat. Is this a bug in strscpy fortification? It's copying out of a (recast) be32... It shouldn't expect to find a NUL because it hit the max copy size already...
Looking...
-Kees
>
>bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=17488c1aa80000
>start commit: aeba456828b4 Add linux-next specific files for 20230718
>git tree: linux-next
>final oops: https://syzkaller.appspot.com/x/report.txt?x=14c88c1aa80000
>console output: https://syzkaller.appspot.com/x/log.txt?x=10c88c1aa80000
>kernel config: https://syzkaller.appspot.com/x/.config?x=e7ec534f91cfce6c
>dashboard link: https://syzkaller.appspot.com/bug?extid=98d3ceb7e01269e7bf4f
>syz repro: https://syzkaller.appspot.com/x/repro.syz?x=15ecf646a80000
>C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1476f30aa80000
>
>Reported-by: syzbot+98d3ceb7e01269e7bf4f@syzkaller.appspotmail.com
>Fixes: c30417b20f49 ("seq_file: Replace strncpy()+nul by strscpy()")
>
>For information about bisection process see: https://goo.gl/tpsmEJ#bisection
--
Kees Cook
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH] fortify: strnlen: Call fortify_panic() only if the number of bytes read is greater than maxlen
2023-07-19 4:18 ` Kees Cook
@ 2023-07-24 22:48 ` sel4
2023-07-24 23:44 ` Kees Cook
0 siblings, 1 reply; 8+ messages in thread
From: sel4 @ 2023-07-24 22:48 UTC (permalink / raw)
To: kees
Cc: keescook, Brandon Luo, syzbot+98d3ceb7e01269e7bf4f,
syzbot+155274e882dcbf9885df, linux-hardening, linux-kernel
From: Brandon Luo <sel4@tilde.club>
If the number of bytes read is p_size and p_size is less than maxlen,
fortify_panic() will be called incorrectly. Only panic if the number of
bytes read is greater than the minimum of p_size and maxlen since that is
the argument to __real_strnlen().
Reported-by: syzbot+98d3ceb7e01269e7bf4f@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/000000000000d8352e0600c0c804@google.com/
Reported-by: syzbot+155274e882dcbf9885df@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/000000000000de4c2c0600c02b28@google.com/
Signed-off-by: Brandon Luo <sel4@tilde.club>
---
include/linux/fortify-string.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h
index da51a83b2829..cde637f735fe 100644
--- a/include/linux/fortify-string.h
+++ b/include/linux/fortify-string.h
@@ -176,8 +176,9 @@ __FORTIFY_INLINE __kernel_size_t strnlen(const char * const POS p, __kernel_size
}
/* Do not check characters beyond the end of p. */
- ret = __real_strnlen(p, maxlen < p_size ? maxlen : p_size);
- if (p_size <= ret && maxlen != ret)
+ maxlen = (maxlen < p_size) ? maxlen : p_size;
+ ret = __real_strnlen(p, maxlen);
+ if (maxlen < ret)
fortify_panic(__func__);
return ret;
}
--
2.41.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] fortify: strnlen: Call fortify_panic() only if the number of bytes read is greater than maxlen
2023-07-24 22:48 ` [PATCH] fortify: strnlen: Call fortify_panic() only if the number of bytes read is greater than maxlen sel4
@ 2023-07-24 23:44 ` Kees Cook
0 siblings, 0 replies; 8+ messages in thread
From: Kees Cook @ 2023-07-24 23:44 UTC (permalink / raw)
To: sel4
Cc: keescook, Brandon Luo, syzbot+98d3ceb7e01269e7bf4f,
syzbot+155274e882dcbf9885df, linux-hardening, linux-kernel
On July 24, 2023 3:48:57 PM PDT, sel4@tilde.club wrote:
>From: Brandon Luo <sel4@tilde.club>
>
>If the number of bytes read is p_size and p_size is less than maxlen,
>fortify_panic() will be called incorrectly. Only panic if the number of
>bytes read is greater than the minimum of p_size and maxlen since that is
> the argument to __real_strnlen().
>
>Reported-by: syzbot+98d3ceb7e01269e7bf4f@syzkaller.appspotmail.com
>Closes: https://lore.kernel.org/all/000000000000d8352e0600c0c804@google.com/
>
>Reported-by: syzbot+155274e882dcbf9885df@syzkaller.appspotmail.com
>Closes: https://lore.kernel.org/all/000000000000de4c2c0600c02b28@google.com/
Thanks for looking at these, but strnlen is working correctly. The problem was hfs's overread of a cast be32 when used with strscpy. See:
https://lore.kernel.org/lkml/202307182147.A5B81B67D@keescook/
-Kees
>
>Signed-off-by: Brandon Luo <sel4@tilde.club>
>---
> include/linux/fortify-string.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
>diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h
>index da51a83b2829..cde637f735fe 100644
>--- a/include/linux/fortify-string.h
>+++ b/include/linux/fortify-string.h
>@@ -176,8 +176,9 @@ __FORTIFY_INLINE __kernel_size_t strnlen(const char * const POS p, __kernel_size
> }
>
> /* Do not check characters beyond the end of p. */
>- ret = __real_strnlen(p, maxlen < p_size ? maxlen : p_size);
>- if (p_size <= ret && maxlen != ret)
>+ maxlen = (maxlen < p_size) ? maxlen : p_size;
>+ ret = __real_strnlen(p, maxlen);
>+ if (maxlen < ret)
> fortify_panic(__func__);
> return ret;
> }
--
Kees Cook
^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <566ffabfcc5a7de71205ec4e97245ca2@disroot.org>]
[parent not found: <e5c7184e93d32d44196e3ac23d88f1fa@disroot.org>]
[parent not found: <1fa2f7f07ebff31ddc24bbbd9ec47cc9@disroot.org>]
end of thread, other threads:[~2023-07-24 23:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-18 10:57 [syzbot] [hfs?] kernel BUG in hfsplus_show_options syzbot
2023-07-19 1:27 ` syzbot
2023-07-19 4:18 ` Kees Cook
2023-07-24 22:48 ` [PATCH] fortify: strnlen: Call fortify_panic() only if the number of bytes read is greater than maxlen sel4
2023-07-24 23:44 ` Kees Cook
[not found] <566ffabfcc5a7de71205ec4e97245ca2@disroot.org>
2023-07-19 23:17 ` [syzbot] [hfs?] kernel BUG in hfsplus_show_options syzbot
[not found] <e5c7184e93d32d44196e3ac23d88f1fa@disroot.org>
2023-07-19 23:26 ` syzbot
[not found] <1fa2f7f07ebff31ddc24bbbd9ec47cc9@disroot.org>
2023-07-19 23:52 ` syzbot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox