2023-02-12 17:00:35

by Dipanjan Das

[permalink] [raw]
Subject: BUG: unable to handle kernel paging request in n_tty_open

Hi,

We would like to report the following bug which has been found by our
modified version of syzkaller.

======================================================
description: BUG: unable to handle kernel paging request in n_tty_open
affected file: drivers/tty/tty_ldisc.c
kernel version: 6.2.0-rc5
kernel commit: 41c66f47061608dc1fd493eebce198f0e74cc2d7
git tree: kmsan
kernel config: https://syzkaller.appspot.com/text?tag=KernelConfig&x=a9a22da1efde3af6
crash reproducer: attached
======================================================
Crash log:
======================================================
RBP: 00007f7117670c30 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000000000d
R13: 00007f71165abf6c R14: 00007f71165abf60 R15: 00007f7117670d80
</TASK>
BUG: unable to handle page fault for address: ffffd10016bfa050
#PF: supervisor write access in kernel mode
#PF: error_code(0x0002) - not-present page
PGD 11410067 P4D 11410067 PUD 1157d067 PMD 31910067 PTE 0
Oops: 0002 [#1] PREEMPT SMP
CPU: 1 PID: 14496 Comm: syz-executor.4 Not tainted
6.2.0-rc5-00010-g41c66f470616 #8
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
1.13.0-1ubuntu1.1 04/01/2014
RIP: 0010:n_tty_open+0xa5/0x240 drivers/tty/n_tty.c:1883
Code: c8 48 c7 c7 c0 79 c0 8f e8 f8 0e ef fb 4d 8d 67 50 48 8b 18 8b
02 89 45 d0 4d 85 ed 0f 85 12 01 00 00 4c 89 e7 e8 0b 0f ef fb <48> 89
18 48 85 db 0f 85 0b 01 00 00 4d 8d a7 88 22 00 00 48 8b 45
RSP: 0018:ffff8880a72036a0 EFLAGS: 00010286
RAX: ffffd10016bfa050 RBX: 0000000000000000 RCX: ffffd10016bfa050
RDX: ffffd90016bfa050 RSI: 0000000000000001 RDI: ffffc90016bfa050
RBP: ffff8880a72036e0 R08: 0000000000000001 R09: ffff8880a6a03458
R10: 0000000000000001 R11: 0000000000000000 R12: ffffc90016bfa050
R13: 0000000000000000 R14: ffff88808b6c1000 R15: ffffc90016bfa000
FS: 00007f7117671700(0000) GS:ffff88813fc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffd10016bfa050 CR3: 00000000a7110000 CR4: 0000000000150ee0
Call Trace:
<TASK>
tty_ldisc_open drivers/tty/tty_ldisc.c:433 [inline]
tty_ldisc_setup+0xfc/0x4c0 drivers/tty/tty_ldisc.c:740
tty_init_dev+0x4b0/0xad0 drivers/tty/tty_io.c:1437
tty_open_by_driver drivers/tty/tty_io.c:2079 [inline]
tty_open+0x176f/0x20b0 drivers/tty/tty_io.c:2126
chrdev_open+0xa45/0xb80 fs/char_dev.c:414
do_dentry_open+0xf85/0x1970 fs/open.c:882
vfs_open+0x75/0xa0 fs/open.c:1013
do_open fs/namei.c:3557 [inline]
path_openat+0x4c4b/0x5a00 fs/namei.c:3714
do_filp_open+0x252/0x660 fs/namei.c:3741
do_sys_openat2+0x200/0x920 fs/open.c:1310
do_sys_open fs/open.c:1326 [inline]
__do_sys_openat fs/open.c:1342 [inline]
__se_sys_openat fs/open.c:1337 [inline]
__x64_sys_openat+0x285/0x310 fs/open.c:1337
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f711648d59d
Code: 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 f3 0f 1e fa 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:00007f7117670bd8 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007f71165abf60 RCX: 00007f711648d59d
RDX: 00000000000a6503 RSI: 0000000020000000 RDI: ffffffffffffff9c
RBP: 00007f7117670c30 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000000000d
R13: 00007f71165abf6c R14: 00007f71165abf60 R15: 00007f7117670d80
</TASK>
Modules linked in:
CR2: ffffd10016bfa050
---[ end trace 0000000000000000 ]---
RIP: 0010:n_tty_open+0xa5/0x240 drivers/tty/n_tty.c:1883
Code: c8 48 c7 c7 c0 79 c0 8f e8 f8 0e ef fb 4d 8d 67 50 48 8b 18 8b
02 89 45 d0 4d 85 ed 0f 85 12 01 00 00 4c 89 e7 e8 0b 0f ef fb <48> 89
18 48 85 db 0f 85 0b 01 00 00 4d 8d a7 88 22 00 00 48 8b 45
RSP: 0018:ffff8880a72036a0 EFLAGS: 00010286
RAX: ffffd10016bfa050 RBX: 0000000000000000 RCX: ffffd10016bfa050
RDX: ffffd90016bfa050 RSI: 0000000000000001 RDI: ffffc90016bfa050
RBP: ffff8880a72036e0 R08: 0000000000000001 R09: ffff8880a6a03458
R10: 0000000000000001 R11: 0000000000000000 R12: ffffc90016bfa050
R13: 0000000000000000 R14: ffff88808b6c1000 R15: ffffc90016bfa000
FS: 00007f7117671700(0000) GS:ffff88813fc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffd10016bfa050 CR3: 00000000a7110000 CR4: 0000000000150ee0
----------------
Code disassembly (best guess):
0: c8 48 c7 c7 enterq $0xc748,$0xc7
4: c0 79 c0 8f sarb $0x8f,-0x40(%rcx)
8: e8 f8 0e ef fb callq 0xfbef0f05
d: 4d 8d 67 50 lea 0x50(%r15),%r12
11: 48 8b 18 mov (%rax),%rbx
14: 8b 02 mov (%rdx),%eax
16: 89 45 d0 mov %eax,-0x30(%rbp)
19: 4d 85 ed test %r13,%r13
1c: 0f 85 12 01 00 00 jne 0x134
22: 4c 89 e7 mov %r12,%rdi
25: e8 0b 0f ef fb callq 0xfbef0f35
* 2a: 48 89 18 mov %rbx,(%rax) <-- trapping instruction
2d: 48 85 db test %rbx,%rbx
30: 0f 85 0b 01 00 00 jne 0x141
36: 4d 8d a7 88 22 00 00 lea 0x2288(%r15),%r12
3d: 48 rex.W
3e: 8b .byte 0x8b
3f: 45 rex.RB

--
Thanks and Regards,

Dipanjan


Attachments:
repro.c (3.73 kB)
repro.syz (81.00 B)
Download all attachments

2023-02-12 17:35:19

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: BUG: unable to handle kernel paging request in n_tty_open

On Sun, Feb 12, 2023 at 09:00:17AM -0800, Dipanjan Das wrote:
> Hi,
>
> We would like to report the following bug which has been found by our
> modified version of syzkaller.

Do you have a proposed patch for this issue as you seem to be able to
reproduce this?

Wait, this is a fake problem:

> memcpy((void*)0x20000000, "/dev/ttyS3\000", 11);
> inject_fault(13);

You are manually injecting faults. That's not a normal operation. If
you can reproduce this without fault injection, please let us know.

Or propose a patch to resolve this?

thanks,

greg k-h

2023-02-13 06:18:36

by Jiri Slaby

[permalink] [raw]
Subject: Re: BUG: unable to handle kernel paging request in n_tty_open

On 12. 02. 23, 18:00, Dipanjan Das wrote:
> Hi,
>
> We would like to report the following bug which has been found by our
> modified version of syzkaller.
>
> ======================================================
> description: BUG: unable to handle kernel paging request in n_tty_open
> affected file: drivers/tty/tty_ldisc.c
> kernel version: 6.2.0-rc5
> kernel commit: 41c66f47061608dc1fd493eebce198f0e74cc2d7
> git tree: kmsan
> kernel config: https://syzkaller.appspot.com/text?tag=KernelConfig&x=a9a22da1efde3af6
> crash reproducer: attached
> ======================================================
> Crash log:
> ======================================================
> RBP: 00007f7117670c30 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 000000000000000d
> R13: 00007f71165abf6c R14: 00007f71165abf60 R15: 00007f7117670d80
> </TASK>
> BUG: unable to handle page fault for address: ffffd10016bfa050
> #PF: supervisor write access in kernel mode
> #PF: error_code(0x0002) - not-present page
> PGD 11410067 P4D 11410067 PUD 1157d067 PMD 31910067 PTE 0
> Oops: 0002 [#1] PREEMPT SMP
> CPU: 1 PID: 14496 Comm: syz-executor.4 Not tainted
> 6.2.0-rc5-00010-g41c66f470616 #8
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
> 1.13.0-1ubuntu1.1 04/01/2014
> RIP: 0010:n_tty_open+0xa5/0x240 drivers/tty/n_tty.c:1883

ldata = vzalloc(sizeof(*ldata));
if (!ldata)
return -ENOMEM;

ldata->overrun_time = jiffies;

COuld you explain how this assignment can ever fail? ldata is either
allocated correctly (non-NULL) and the assignment cannot fail or not
(NULL) and the assignment cannot fail (as it doesn't happen).

thanks,
--
js
suse labs


2023-04-08 16:09:14

by Dipanjan Das

[permalink] [raw]
Subject: Re: BUG: unable to handle kernel paging request in n_tty_open

On Sun, Feb 12, 2023 at 10:18 PM Jiri Slaby <[email protected]> wrote:
> COuld you explain how this assignment can ever fail? ldata is either
> allocated correctly (non-NULL) and the assignment cannot fail or not
> (NULL) and the assignment cannot fail (as it doesn't happen).

Sorry for the late reply. We just reported our understanding of the
issue here: https://groups.google.com/u/1/g/syzkaller/c/BsxSggrhEMw

--
Thanks and Regards,

Dipanjan