BUG: unable to handle kernel NULL pointer dereference in udpv6_sendmsg

From: Wei Chen
Date: Mon Nov 21 2022 - 09:13:38 EST


Dear Linux Developer,

Recently when using our tool to fuzz kernel, the following crash was triggered.

HEAD commit: 147307c69ba
git tree: upstream
compiler: clang 12.0.0
console output:
https://drive.google.com/file/d/1bYT7pFbYHlDqcmYuvw_x7kvX9_cNEscg/view?usp=share_link
kernel config: https://drive.google.com/file/d/1NAf4S43d9VOKD52xbrqw-PUP1Mbj8z-S/view?usp=share_link
Syz reproducer:
https://drive.google.com/file/d/17GPbM4-sjSZMdakHzuLiksNE4xGUG3pU/view?usp=share_link

Unfortunately, if we transform the syz reproducer to C reproducer with
syz-prog2c, the crash would not happen. Please consider to use
syz-execprog and syz-executor to reproduce the crash.

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: Wei Chen <harperchen1110@xxxxxxxxx>

BUG: kernel NULL pointer dereference, address: 000000000000004e
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
PGD 129e71067 P4D 129e71067 PUD 107f78067 PMD 0
Oops: 0000 [#1] PREEMPT SMP
CPU: 0 PID: 3472 Comm: syz-executor.0 Not tainted 6.1.0-rc5-next-20221118 #2
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
rel-1.13.0-48-gd9c812dda519-prebuilt.qemu.org 04/01/2014
RIP: 0010:udpv6_sendmsg+0x4f3/0x16a0 net/ipv6/udp.c:1440
Code: b7 6f 02 31 ff 89 ee e8 ab 10 14 fd 85 ed 0f 84 41 03 00 00 66
89 ac 24 64 01 00 00 48 8b 6c 24 10 48 8d 7d 4e e8 9d 71 27 fd <0f> b7
6d 4e 83 e5 02 31 ff 89 ee e8 7d 10 14 fd 66 85 ed 0f 85 cb
RSP: 0018:ffffc90002a1b710 EFLAGS: 00010246
RAX: ffff888128fbca48 RBX: 0000000000000000 RCX: ffffffff8413a4c3
RDX: 00000000000008cd RSI: 0000000000000000 RDI: 000000000000004e
RBP: 0000000000000000 R08: 000000000000004f R09: 0000000000000000
R10: 0001ffffffffffff R11: ffff888128fbc000 R12: ffff88810117dee0
R13: ffff88810117db00 R14: 00000000ffff02ff R15: ffff8881280fd088
FS: 00007ffb0eb4e700(0000) GS:ffff88813bc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000000000000004e CR3: 0000000129c82000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
do_udp_sendmsg net/rxrpc/output.c:27 [inline]
rxrpc_send_data_packet+0x962/0x1690 net/rxrpc/output.c:485
rxrpc_queue_packet+0x5eb/0x6f0 net/rxrpc/sendmsg.c:264
rxrpc_send_data+0x8ca/0xcb0 net/rxrpc/sendmsg.c:411
rxrpc_do_sendmsg+0xb48/0xbe0 net/rxrpc/sendmsg.c:733
rxrpc_sendmsg+0x3d7/0x4c0 net/rxrpc/af_rxrpc.c:561
sock_sendmsg_nosec net/socket.c:714 [inline]
sock_sendmsg net/socket.c:734 [inline]
____sys_sendmsg+0x38f/0x500 net/socket.c:2476
___sys_sendmsg net/socket.c:2530 [inline]
__sys_sendmsg+0x197/0x230 net/socket.c:2559
__do_sys_sendmsg net/socket.c:2568 [inline]
__se_sys_sendmsg net/socket.c:2566 [inline]
__x64_sys_sendmsg+0x42/0x50 net/socket.c:2566
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x4697f9
Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 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 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffb0eb4dc48 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 000000000077bf80 RCX: 00000000004697f9
RDX: 0000000000000000 RSI: 00000000200036c0 RDI: 0000000000000003
RBP: 00000000004d29e9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000077bf80
R13: 0000000000000000 R14: 000000000077bf80 R15: 00007ffd80eca0a0
</TASK>
Modules linked in:
CR2: 000000000000004e
---[ end trace 0000000000000000 ]---
RIP: 0010:udpv6_sendmsg+0x4f3/0x16a0 net/ipv6/udp.c:1440
Code: b7 6f 02 31 ff 89 ee e8 ab 10 14 fd 85 ed 0f 84 41 03 00 00 66
89 ac 24 64 01 00 00 48 8b 6c 24 10 48 8d 7d 4e e8 9d 71 27 fd <0f> b7
6d 4e 83 e5 02 31 ff 89 ee e8 7d 10 14 fd 66 85 ed 0f 85 cb
RSP: 0018:ffffc90002a1b710 EFLAGS: 00010246
RAX: ffff888128fbca48 RBX: 0000000000000000 RCX: ffffffff8413a4c3
RDX: 00000000000008cd RSI: 0000000000000000 RDI: 000000000000004e
RBP: 0000000000000000 R08: 000000000000004f R09: 0000000000000000
R10: 0001ffffffffffff R11: ffff888128fbc000 R12: ffff88810117dee0
R13: ffff88810117db00 R14: 00000000ffff02ff R15: ffff8881280fd088
FS: 00007ffb0eb4e700(0000) GS:ffff88813bc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000000000000004e CR3: 0000000129c82000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: b7 6f mov $0x6f,%bh
2: 02 31 add (%rcx),%dh
4: ff 89 ee e8 ab 10 decl 0x10abe8ee(%rcx)
a: 14 fd adc $0xfd,%al
c: 85 ed test %ebp,%ebp
e: 0f 84 41 03 00 00 je 0x355
14: 66 89 ac 24 64 01 00 mov %bp,0x164(%rsp)
1b: 00
1c: 48 8b 6c 24 10 mov 0x10(%rsp),%rbp
21: 48 8d 7d 4e lea 0x4e(%rbp),%rdi
25: e8 9d 71 27 fd callq 0xfd2771c7
* 2a: 0f b7 6d 4e movzwl 0x4e(%rbp),%ebp <-- trapping instruction
2e: 83 e5 02 and $0x2,%ebp
31: 31 ff xor %edi,%edi
33: 89 ee mov %ebp,%esi
35: e8 7d 10 14 fd callq 0xfd1410b7
3a: 66 85 ed test %bp,%bp
3d: 0f .byte 0xf
3e: 85 cb test %ecx,%ebx

Best,
Wei