2022-10-30 10:42:16

by Wei Chen

[permalink] [raw]
Subject: BUG: unable to handle kernel NULL pointer dereference in tipc_crypto_key_distr

Dear Linux Developer,

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

HEAD commit: 64570fbc14f8 Linux 5.15-rc5
git tree: upstream
compiler: gcc 8.0.1
console output:
https://drive.google.com/file/d/1ZxNXcUkiJiTK6MzVIWCqDpq70QW2-t-b/view?usp=share_link
kernel config: https://drive.google.com/file/d/1uDOeEYgJDcLiSOrx9W8v2bqZ6uOA_55t/view?usp=share_link

Unfortunately, I don't have any reproducer for this crash yet.

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: Wei Chen <[email protected]>

RBP: 0000000000000045 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000119bfac
R13: 0000000000000000 R14: 000000000119bfa0 R15: 00007fffcffa6fe0
BUG: kernel NULL pointer dereference, address: 0000000000000020
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
PGD 2763b067 P4D 2763b067 PUD 27636067 PMD 0
Oops: 0000 [#1] PREEMPT SMP
CPU: 0 PID: 12346 Comm: syz-executor.0 Not tainted 5.15.0-rc5 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
rel-1.13.0-48-gd9c812dda519-prebuilt.qemu.org 04/01/2014
RIP: 0010:tipc_crypto_key_distr+0x121/0x6a0
Code: 00 48 8b 13 88 85 60 ff ff ff 41 0f b7 44 24 48 48 89 95 68 ff
ff ff 66 89 85 5c ff ff ff 49 8b 44 24 40 48 89 85 50 ff ff ff <8b> 40
20 83 c0 24 0f b7 c0 83 c0 28 89 c7 89 85 64 ff ff ff e8 96
RSP: 0018:ffffc9000d48f8e0 EFLAGS: 00010212
RAX: 0000000000000000 RBX: ffff888010979a00 RCX: 0000000000040000
RDX: ffff8880163e0000 RSI: 0000000000000a20 RDI: 0000000000000002
RBP: ffffc9000d48f998 R08: ffffffff847c7f3d R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000001 R12: ffff88803189eb00
R13: 0000000000000001 R14: 0000000000000000 R15: 00000000ffffff82
FS: 00007f54fc3f7700(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000020 CR3: 0000000027638000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
tipc_nl_node_set_key+0x760/0x930
genl_family_rcv_msg_doit.isra.16+0x141/0x190
genl_rcv_msg+0x172/0x2c0
netlink_rcv_skb+0x87/0x1d0
genl_rcv+0x24/0x40
netlink_unicast+0x2b8/0x3d0
netlink_sendmsg+0x350/0x680
sock_sendmsg+0x52/0x70
____sys_sendmsg+0x35f/0x390
___sys_sendmsg+0x95/0xd0
__sys_sendmsg+0x87/0x100
do_syscall_64+0x34/0xb0
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x4692c9
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:00007f54fc3f6c38 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00007f54fc3f6c80 RCX: 00000000004692c9
RDX: 0000000000000000 RSI: 00000000200007c0 RDI: 0000000000000003
RBP: 0000000000000045 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000119bfac
R13: 0000000000000000 R14: 000000000119bfa0 R15: 00007fffcffa6fe0
Modules linked in:
CR2: 0000000000000020
---[ end trace c7813f5e0b2eeeab ]---
RIP: 0010:tipc_crypto_key_distr+0x121/0x6a0
Code: 00 48 8b 13 88 85 60 ff ff ff 41 0f b7 44 24 48 48 89 95 68 ff
ff ff 66 89 85 5c ff ff ff 49 8b 44 24 40 48 89 85 50 ff ff ff <8b> 40
20 83 c0 24 0f b7 c0 83 c0 28 89 c7 89 85 64 ff ff ff e8 96
RSP: 0018:ffffc9000d48f8e0 EFLAGS: 00010212
RAX: 0000000000000000 RBX: ffff888010979a00 RCX: 0000000000040000
RDX: ffff8880163e0000 RSI: 0000000000000a20 RDI: 0000000000000002
RBP: ffffc9000d48f998 R08: ffffffff847c7f3d R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000001 R12: ffff88803189eb00
R13: 0000000000000001 R14: 0000000000000000 R15: 00000000ffffff82
FS: 00007f54fc3f7700(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000020 CR3: 0000000027638000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: 00 48 8b add %cl,-0x75(%rax)
3: 13 88 85 60 ff ff adc -0x9f7b(%rax),%ecx
9: ff 41 0f incl 0xf(%rcx)
c: b7 44 mov $0x44,%bh
e: 24 48 and $0x48,%al
10: 48 89 95 68 ff ff ff mov %rdx,-0x98(%rbp)
17: 66 89 85 5c ff ff ff mov %ax,-0xa4(%rbp)
1e: 49 8b 44 24 40 mov 0x40(%r12),%rax
23: 48 89 85 50 ff ff ff mov %rax,-0xb0(%rbp)
* 2a: 8b 40 20 mov 0x20(%rax),%eax <-- trapping instruction
2d: 83 c0 24 add $0x24,%eax
30: 0f b7 c0 movzwl %ax,%eax
33: 83 c0 28 add $0x28,%eax
36: 89 c7 mov %eax,%edi
38: 89 85 64 ff ff ff mov %eax,-0x9c(%rbp)
3e: e8 .byte 0xe8
3f: 96 xchg %eax,%esi

Best,
We


2022-11-04 17:48:24

by Xin Long

[permalink] [raw]
Subject: Re: BUG: unable to handle kernel NULL pointer dereference in tipc_crypto_key_distr

On Sun, Oct 30, 2022 at 6:32 AM Wei Chen <[email protected]> wrote:
>
> Dear Linux Developer,
>
> Recently when using our tool to fuzz kernel, the following crash was triggered:
>
> HEAD commit: 64570fbc14f8 Linux 5.15-rc5
> git tree: upstream
> compiler: gcc 8.0.1
> console output:
> https://drive.google.com/file/d/1ZxNXcUkiJiTK6MzVIWCqDpq70QW2-t-b/view?usp=share_link
> kernel config: https://drive.google.com/file/d/1uDOeEYgJDcLiSOrx9W8v2bqZ6uOA_55t/view?usp=share_link
>
> Unfortunately, I don't have any reproducer for this crash yet.
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: Wei Chen <[email protected]>
>
> RBP: 0000000000000045 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 000000000119bfac
> R13: 0000000000000000 R14: 000000000119bfa0 R15: 00007fffcffa6fe0
> BUG: kernel NULL pointer dereference, address: 0000000000000020
> #PF: supervisor read access in kernel mode
> #PF: error_code(0x0000) - not-present page
> PGD 2763b067 P4D 2763b067 PUD 27636067 PMD 0
> Oops: 0000 [#1] PREEMPT SMP
> CPU: 0 PID: 12346 Comm: syz-executor.0 Not tainted 5.15.0-rc5 #1
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
> rel-1.13.0-48-gd9c812dda519-prebuilt.qemu.org 04/01/2014
> RIP: 0010:tipc_crypto_key_distr+0x121/0x6a0
> Code: 00 48 8b 13 88 85 60 ff ff ff 41 0f b7 44 24 48 48 89 95 68 ff
> ff ff 66 89 85 5c ff ff ff 49 8b 44 24 40 48 89 85 50 ff ff ff <8b> 40
> 20 83 c0 24 0f b7 c0 83 c0 28 89 c7 89 85 64 ff ff ff e8 96
> RSP: 0018:ffffc9000d48f8e0 EFLAGS: 00010212
> RAX: 0000000000000000 RBX: ffff888010979a00 RCX: 0000000000040000
> RDX: ffff8880163e0000 RSI: 0000000000000a20 RDI: 0000000000000002
> RBP: ffffc9000d48f998 R08: ffffffff847c7f3d R09: 0000000000000000
> R10: 0000000000000001 R11: 0000000000000001 R12: ffff88803189eb00
> R13: 0000000000000001 R14: 0000000000000000 R15: 00000000ffffff82
> FS: 00007f54fc3f7700(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000000000000020 CR3: 0000000027638000 CR4: 00000000003526f0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
> tipc_nl_node_set_key+0x760/0x930
Please check if this fix is in your kernel:

commit 3e6db079751afd527bf3db32314ae938dc571916
Author: Tadeusz Struk <[email protected]>
Date: Mon Nov 15 08:01:43 2021 -0800

tipc: check for null after calling kmemdup

Thanks.
> genl_family_rcv_msg_doit.isra.16+0x141/0x190
> genl_rcv_msg+0x172/0x2c0
> netlink_rcv_skb+0x87/0x1d0
> genl_rcv+0x24/0x40
> netlink_unicast+0x2b8/0x3d0
> netlink_sendmsg+0x350/0x680
> sock_sendmsg+0x52/0x70
> ____sys_sendmsg+0x35f/0x390
> ___sys_sendmsg+0x95/0xd0
> __sys_sendmsg+0x87/0x100
> do_syscall_64+0x34/0xb0
> entry_SYSCALL_64_after_hwframe+0x44/0xae
> RIP: 0033:0x4692c9
> 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:00007f54fc3f6c38 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
> RAX: ffffffffffffffda RBX: 00007f54fc3f6c80 RCX: 00000000004692c9
> RDX: 0000000000000000 RSI: 00000000200007c0 RDI: 0000000000000003
> RBP: 0000000000000045 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 000000000119bfac
> R13: 0000000000000000 R14: 000000000119bfa0 R15: 00007fffcffa6fe0
> Modules linked in:
> CR2: 0000000000000020
> ---[ end trace c7813f5e0b2eeeab ]---
> RIP: 0010:tipc_crypto_key_distr+0x121/0x6a0
> Code: 00 48 8b 13 88 85 60 ff ff ff 41 0f b7 44 24 48 48 89 95 68 ff
> ff ff 66 89 85 5c ff ff ff 49 8b 44 24 40 48 89 85 50 ff ff ff <8b> 40
> 20 83 c0 24 0f b7 c0 83 c0 28 89 c7 89 85 64 ff ff ff e8 96
> RSP: 0018:ffffc9000d48f8e0 EFLAGS: 00010212
> RAX: 0000000000000000 RBX: ffff888010979a00 RCX: 0000000000040000
> RDX: ffff8880163e0000 RSI: 0000000000000a20 RDI: 0000000000000002
> RBP: ffffc9000d48f998 R08: ffffffff847c7f3d R09: 0000000000000000
> R10: 0000000000000001 R11: 0000000000000001 R12: ffff88803189eb00
> R13: 0000000000000001 R14: 0000000000000000 R15: 00000000ffffff82
> FS: 00007f54fc3f7700(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000000000000020 CR3: 0000000027638000 CR4: 00000000003526f0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> ----------------
> Code disassembly (best guess):
> 0: 00 48 8b add %cl,-0x75(%rax)
> 3: 13 88 85 60 ff ff adc -0x9f7b(%rax),%ecx
> 9: ff 41 0f incl 0xf(%rcx)
> c: b7 44 mov $0x44,%bh
> e: 24 48 and $0x48,%al
> 10: 48 89 95 68 ff ff ff mov %rdx,-0x98(%rbp)
> 17: 66 89 85 5c ff ff ff mov %ax,-0xa4(%rbp)
> 1e: 49 8b 44 24 40 mov 0x40(%r12),%rax
> 23: 48 89 85 50 ff ff ff mov %rax,-0xb0(%rbp)
> * 2a: 8b 40 20 mov 0x20(%rax),%eax <-- trapping instruction
> 2d: 83 c0 24 add $0x24,%eax
> 30: 0f b7 c0 movzwl %ax,%eax
> 33: 83 c0 28 add $0x28,%eax
> 36: 89 c7 mov %eax,%edi
> 38: 89 85 64 ff ff ff mov %eax,-0x9c(%rbp)
> 3e: e8 .byte 0xe8
> 3f: 96 xchg %eax,%esi
>
> Best,
> We