linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [syzbot] [mm?] general protection fault in vsscanf (2)
@ 2024-12-16  3:40 syzbot
  2024-12-16  4:27 ` [PATCH] mm: huge_memory: Handle strsep not finding delimiter Leo Stone
  0 siblings, 1 reply; 3+ messages in thread
From: syzbot @ 2024-12-16  3:40 UTC (permalink / raw)
  To: akpm, linux-kernel, linux-mm, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    f92f4749861b Merge tag 'clk-fixes-for-linus' of git://git...
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=116904f8580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=99a5586995ec03b2
dashboard link: https://syzkaller.appspot.com/bug?extid=8a3da2f1bbf59227c289
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=15758d44580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=156904f8580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/b85403132ddc/disk-f92f4749.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/20613d034287/vmlinux-f92f4749.xz
kernel image: https://storage.googleapis.com/syzbot-assets/d1ea80bf7e4e/bzImage-f92f4749.xz

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

Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN PTI
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
CPU: 0 UID: 0 PID: 5823 Comm: syz-executor234 Not tainted 6.13.0-rc2-syzkaller-00031-gf92f4749861b #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
RIP: 0010:vsscanf+0x1a4/0x2a30 lib/vsprintf.c:3466
Code: db 74 5e e8 1e da 82 f6 49 8d 5d 01 48 89 e9 48 ba 00 00 00 00 00 fc ff df 48 c1 e9 03 48 89 5c 24 70 49 89 dc 41 0f b6 45 00 <0f> b6 14 11 48 89 e9 83 e1 07 38 ca 7f 08 84 d2 0f 85 1e 19 00 00
RSP: 0018:ffffc90003cc7668 EFLAGS: 00010246
RAX: 0000000000000030 RBX: ffffffff8b5c7801 RCX: 0000000000000000
RDX: dffffc0000000000 RSI: ffffffff8b1663d2 RDI: 0000000000000001
RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000030 R11: 00000000000a2001 R12: ffffffff8b5c7801
R13: ffffffff8b5c7800 R14: dffffc0000000000 R15: ffffc90003cc7eb0
FS:  0000555573fa8380(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000020000080 CR3: 0000000073a06000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 sscanf+0xc8/0x100 lib/vsprintf.c:3722
 split_huge_pages_write+0xa16/0x1f60 mm/huge_memory.c:4178
 full_proxy_write+0xfb/0x1b0 fs/debugfs/file.c:356
 vfs_write+0x24c/0x1150 fs/read_write.c:677
 ksys_write+0x12b/0x250 fs/read_write.c:731
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f9a505582e9
Code: 48 83 c4 28 c3 e8 37 17 00 00 0f 1f 80 00 00 00 00 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:00007ffdae2774c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007ffdae277698 RCX: 00007f9a505582e9
RDX: 0000000000000004 RSI: 0000000020000040 RDI: 0000000000000003
RBP: 00007f9a505cb610 R08: 0000000000000000 R09: 00007ffdae277698
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007ffdae277688 R14: 0000000000000001 R15: 0000000000000001
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:vsscanf+0x1a4/0x2a30 lib/vsprintf.c:3466
Code: db 74 5e e8 1e da 82 f6 49 8d 5d 01 48 89 e9 48 ba 00 00 00 00 00 fc ff df 48 c1 e9 03 48 89 5c 24 70 49 89 dc 41 0f b6 45 00 <0f> b6 14 11 48 89 e9 83 e1 07 38 ca 7f 08 84 d2 0f 85 1e 19 00 00
RSP: 0018:ffffc90003cc7668 EFLAGS: 00010246
RAX: 0000000000000030 RBX: ffffffff8b5c7801 RCX: 0000000000000000
RDX: dffffc0000000000 RSI: ffffffff8b1663d2 RDI: 0000000000000001
RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000030 R11: 00000000000a2001 R12: ffffffff8b5c7801
R13: ffffffff8b5c7800 R14: dffffc0000000000 R15: ffffc90003cc7eb0
FS:  0000555573fa8380(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000020000080 CR3: 0000000073a06000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess), 1 bytes skipped:
   0:	74 5e                	je     0x60
   2:	e8 1e da 82 f6       	call   0xf682da25
   7:	49 8d 5d 01          	lea    0x1(%r13),%rbx
   b:	48 89 e9             	mov    %rbp,%rcx
   e:	48 ba 00 00 00 00 00 	movabs $0xdffffc0000000000,%rdx
  15:	fc ff df
  18:	48 c1 e9 03          	shr    $0x3,%rcx
  1c:	48 89 5c 24 70       	mov    %rbx,0x70(%rsp)
  21:	49 89 dc             	mov    %rbx,%r12
  24:	41 0f b6 45 00       	movzbl 0x0(%r13),%eax
* 29:	0f b6 14 11          	movzbl (%rcx,%rdx,1),%edx <-- trapping instruction
  2d:	48 89 e9             	mov    %rbp,%rcx
  30:	83 e1 07             	and    $0x7,%ecx
  33:	38 ca                	cmp    %cl,%dl
  35:	7f 08                	jg     0x3f
  37:	84 d2                	test   %dl,%dl
  39:	0f 85 1e 19 00 00    	jne    0x195d


---
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 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 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] 3+ messages in thread

* [PATCH] mm: huge_memory: Handle strsep not finding delimiter
  2024-12-16  3:40 [syzbot] [mm?] general protection fault in vsscanf (2) syzbot
@ 2024-12-16  4:27 ` Leo Stone
  2024-12-16  5:52   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Leo Stone @ 2024-12-16  4:27 UTC (permalink / raw)
  To: syzbot+8a3da2f1bbf59227c289
  Cc: Leo Stone, akpm, linux-kernel, linux-mm, syzkaller-bugs

split_huge_pages_write does not handle the case where strsep finds no
delimiter in the given string and sets the input buffer to NULL,
which allows this reproducer to trigger a protection fault.

Reported-by: syzbot+8a3da2f1bbf59227c289@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=8a3da2f1bbf59227c289
Signed-off-by: Leo Stone <leocstone@gmail.com>
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index ee335d96fc39..361319f749f0 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -4168,7 +4168,7 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf,
 		size_t input_len = strlen(input_buf);
 
 		tok = strsep(&buf, ",");
-		if (tok) {
+		if (tok && buf) {
 			strscpy(file_path, tok);
 		} else {
 			ret = -EINVAL;
-- 
2.43.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: huge_memory: Handle strsep not finding delimiter
  2024-12-16  4:27 ` [PATCH] mm: huge_memory: Handle strsep not finding delimiter Leo Stone
@ 2024-12-16  5:52   ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2024-12-16  5:52 UTC (permalink / raw)
  To: Leo Stone
  Cc: syzbot+8a3da2f1bbf59227c289, linux-kernel, linux-mm, syzkaller-bugs

On Sun, 15 Dec 2024 20:27:51 -0800 Leo Stone <leocstone@gmail.com> wrote:

> split_huge_pages_write does not handle the case where strsep finds no
> delimiter in the given string and sets the input buffer to NULL,
> which allows this reproducer to trigger a protection fault.
> 
> ...
>
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -4168,7 +4168,7 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf,
>  		size_t input_len = strlen(input_buf);
>  
>  		tok = strsep(&buf, ",");
> -		if (tok) {
> +		if (tok && buf) {
>  			strscpy(file_path, tok);
>  		} else {
>  			ret = -EINVAL;

lgtm, thanks.

The duplicated `buf' made review of this unnecessarily annoying, so...


From: Andrew Morton <akpm@linux-foundation.org>
Subject: mm/huge_memory.c: rename shadowed local
Date: Sun Dec 15 09:44:47 PM PST 2024

split_huge_pages_write() has a lccal `buf' which shadows incoming arg
`buf'.  Reviewer confusion resulted.

Cc: Leo Stone <leocstone@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/huge_memory.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

--- a/mm/huge_memory.c~mm-huge_memoryc-rename-shadowed-local
+++ a/mm/huge_memory.c
@@ -4169,20 +4169,21 @@ static ssize_t split_huge_pages_write(st
 
 	if (input_buf[0] == '/') {
 		char *tok;
-		char *buf = input_buf;
+		char *tok_buf = input_buf;
 		char file_path[MAX_INPUT_BUF_SZ];
 		pgoff_t off_start = 0, off_end = 0;
 		size_t input_len = strlen(input_buf);
 
-		tok = strsep(&buf, ",");
-		if (tok && buf) {
+		tok = strsep(&tok_buf, ",");
+		if (tok && tok_buf) {
 			strscpy(file_path, tok);
 		} else {
 			ret = -EINVAL;
 			goto out;
 		}
 
-		ret = sscanf(buf, "0x%lx,0x%lx,%d", &off_start, &off_end, &new_order);
+		ret = sscanf(tok_buf, "0x%lx,0x%lx,%d", &off_start,
+			    &off_end, &new_order);
 		if (ret != 2 && ret != 3) {
 			ret = -EINVAL;
 			goto out;
_



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-16  5:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-16  3:40 [syzbot] [mm?] general protection fault in vsscanf (2) syzbot
2024-12-16  4:27 ` [PATCH] mm: huge_memory: Handle strsep not finding delimiter Leo Stone
2024-12-16  5:52   ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox