general protection fault in __cpuhp_state_remove_instance
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: 330517c63aa9 Merge tag 'char-misc-7.4-rc1' of git://git.ke.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=13561459580000 kernel config: https://syzkaller.appspot.com/x/.config?x=b03c85f3988bfcd5 dashboard link: https://syzkaller.appspot.com/bug?extid=08318698e045b4b85f51 compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1062d695580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15236fcd580000
Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/d900f083ada3/non_bootable_disk-330517c6.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/ecb230491807/vmlinux-330517c6.xz
kernel image: https://storage.googleapis.com/syzbot-assets/ace3132a7acc/bzImage-330517c6.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
md: array md0 already has disks!
md/raid:md0: not clean -- starting background reconstructionraid456_cpu_up_prepare: failed memory allocation for cpu0
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] CPU: 1 UID: 0 PID: 6024 Comm: syz.0.22 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 RIP: 0010:__hlist_del include/linux/list.h:1045 [inline] RIP: 0010:hlist_del include/linux/list.h:1059 [inline] RIP: 0010:__cpuhp_state_remove_instance+0x227/0x5f0 kernel/cpu.c:2573 Code: 00 fc ff df 48 89 fa 48 c1 ea 03 80 3c 02 00 0f 85 78 03 00 00 48 b8 00 00 00 00 00 fc ff df 4c 8b 65 08 4c 89 e2 48 c1 ea 03 <80> 3c 02 00 0f 85 4c 03 00 00 49 89 1c 24 48 85 db 74 28 e8 51 1f RSP: 0018:ffffc90003c7f890 EFLAGS: 00010246 RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffffffff81c9fb54 RDI: ffff8880287a8440 RBP: ffff8880287a8438 R08: 0000000000000007 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 R13: ffffffffffffffff R14: 0000000000000004 R15: 0000000000000003 FS: 00007fcd283f56c0(0000) GS:ffff8880d45b4000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000001b30324228 CR3: 0000000037605000 CR4: 0000000000352ef0 Call Trace: <TASK> cpuhp_state_remove_instance include/linux/cpuhotplug.h:480 [inline] raid5_free_percpu drivers/md/raid5.c:7541 [inline] free_conf+0x238/0x710 drivers/md/raid5.c:7554 setup_conf+0xd80/0x2a20 drivers/md/raid5.c:7885 raid5_run+0x1260/0x1670 drivers/md/raid5.c:8129 md_run+0xc2f/0x2510 drivers/md/md.c:6779 do_md_run+0x36/0x660 drivers/md/md.c:6880 md_ioctl+0x27e6/0x36c0 drivers/md/md.c:8515 blkdev_ioctl+0x5ad/0x6f0 block/ioctl.c:798 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl fs/ioctl.c:583 [inline] __x64_sys_ioctl+0x18e/0x210 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline] do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fcd2759f559 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 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 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fcd283f5028 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 00007fcd27825fa0 RCX: 00007fcd2759f559 RDX: 0000000000000000 RSI: 00000000400c0930 RDI: 0000000000000003 RBP: 00007fcd27636b20 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fcd27826038 R14: 00007fcd27825fa0 R15: 00007ffd1d32f288 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:__hlist_del include/linux/list.h:1045 [inline] RIP: 0010:hlist_del include/linux/list.h:1059 [inline] RIP: 0010:__cpuhp_state_remove_instance+0x227/0x5f0 kernel/cpu.c:2573 Code: 00 fc ff df 48 89 fa 48 c1 ea 03 80 3c 02 00 0f 85 78 03 00 00 48 b8 00 00 00 00 00 fc ff df 4c 8b 65 08 4c 89 e2 48 c1 ea 03 <80> 3c 02 00 0f 85 4c 03 00 00 49 89 1c 24 48 85 db 74 28 e8 51 1f RSP: 0018:ffffc90003c7f890 EFLAGS: 00010246 RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffffffff81c9fb54 RDI: ffff8880287a8440 RBP: ffff8880287a8438 R08: 0000000000000007 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 R13: ffffffffffffffff R14: 0000000000000004 R15: 0000000000000003 FS: 00007fcd283f56c0(0000) GS:ffff8880d44b4000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fcd283d3ff8 CR3: 0000000037605000 CR4: 0000000000352ef0 ---------------- Code disassembly (best guess): 0: 00 fc add %bh,%ah 2: ff lcall (bad) 3: df 48 89 fisttps -0x77(%rax) 6: fa cli 7: 48 c1 ea 03 shr $0x3,%rdx b: 80 3c 02 00 cmpb $0x0,(%rdx,%rax,1) f: 0f 85 78 03 00 00 jne 0x38d 15: 48 b8 00 00 00 00 00 movabs $0xdffffc0000000000,%rax 1c: fc ff df 1f: 4c 8b 65 08 mov 0x8(%rbp),%r12 23: 4c 89 e2 mov %r12,%rdx 26: 48 c1 ea 03 shr $0x3,%rdx * 2a: 80 3c 02 00 cmpb $0x0,(%rdx,%rax,1) <-- trapping instruction 2e: 0f 85 4c 03 00 00 jne 0x380 34: 49 89 1c 24 mov %rbx,(%r12) 38: 48 85 db test %rbx,%rbx 3b: 74 28 je 0x65 3d: e8 .byte 0xe8 3e: 51 push %rcx 3f: 1f (bad)
---
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 [email protected].
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
PATCH 1/1 md/raid5: Cancel remove instance if adding it fails
The failure of raid456_cpu_up_prepare() to allocate memory causes cpuhp_state_add_instance() to fail; consequently, the corresponding instance is not initialized, potentially hitting [1].
Additionally, there is another null-ptr-deref issue: conf->mddev is assigned too late, meaning that any error-handling exit occurring before this assignment, which jumps to the abort label, potentially hitting [2].
[1]
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] Call Trace: cpuhp_state_remove_instance include/linux/cpuhotplug.h:480 [inline] raid5_free_percpu drivers/md/raid5.c:7541 [inline] free_conf+0x238/0x710 drivers/md/raid5.c:7554 setup_conf+0xd80/0x2a20 drivers/md/raid5.c:7885 raid5_run+0x1260/0x1670 drivers/md/raid5.c:8129
[2]
BUG: KASAN: null-ptr-deref in free_conf+0xfd/0x7e0 Read of size 8 at addr 0000000000000028 by task rp0/9459 Call Trace: free_conf+0xfd/0x7e0 setup_conf.cold+0x6e/0x4a1 raid5_run+0x1260/0x1670
Add a check before removing an instance, if the instance was not successfully added, skip the removal process. Move the assignment of conf->mddev after the memory allocation for conf.
--- drivers/md/raid5.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/md/raid5.c +3 -2
@@ -7538,7 +7538,8 @@ static void raid5_free_percpu(struct r5conf *conf)if (!conf->percpu)return ; -cpuhp_state_remove_instance (CPUHP_MD_RAID5_PREPARE , &conf->node); +if (!hlist_unhashed (&conf->node)) +cpuhp_state_remove_instance (CPUHP_MD_RAID5_PREPARE , &conf->node);free_percpu (conf->percpu); }
@@ -7675,6 +7676,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)if (conf ==NULL ) goto abort; + conf->mddev = mddev;#if PAGE_SIZE !=DEFAULT_STRIPE_SIZE conf->stripe_size =DEFAULT_STRIPE_SIZE ; conf->stripe_shift =ilog2 (DEFAULT_STRIPE_SIZE ) -9 ;
@@ -7743,7 +7745,6 @@ static struct r5conf *setup_conf(struct mddev *mddev) ret =bioset_init (&conf->bio_split,BIO_POOL_SIZE ,0 ,0 );if (ret) goto abort; - conf->mddev = mddev; ret = -ENOMEM ; conf->stripe_hashtbl =kzalloc (PAGE_SIZE ,GFP_KERNEL );
Signature · 1 line
2.43.0
yu kuai
maintainerRe: [PATCH] md/raid5: Cancel remove instance if adding it fails
Hi,
Quoted 29 lines · Edward Adam Davis
The failure of
raid456_cpu_up_prepare()to allocate memory causescpuhp_state_add_instance()to fail; consequently, the corresponding instance is not initialized, potentially hitting [1].Additionally, there is another null-ptr-deref issue:
conf->mddevis assigned too late, meaning that any error-handling exit occurring before this assignment, which jumps to the abort label, potentially hitting [2].[1]
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] Call Trace: cpuhp_state_remove_instance include/linux/cpuhotplug.h:480 [inline] raid5_free_percpu drivers/md/raid5.c:7541 [inline] free_conf+0x238/0x710 drivers/md/raid5.c:7554 setup_conf+0xd80/0x2a20 drivers/md/raid5.c:7885 raid5_run+0x1260/0x1670 drivers/md/raid5.c:8129[2]
BUG: KASAN: null-ptr-deref in free_conf+0xfd/0x7e0 Read of size 8 at addr 0000000000000028 by task rp0/9459 Call Trace: free_conf+0xfd/0x7e0 setup_conf.cold+0x6e/0x4a1 raid5_run+0x1260/0x1670Add a check before removing an instance, if the instance was not successfully added, skip the removal process. Move the assignment of
conf->mddevafter the memory allocation for conf.
Quoted 7 lines
Fixes 29c6d1bbd7a2 ("md/raid5: Convert to hotplug state machine")Reported-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- drivers/md/raid5.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Looks like this problem is already fixed
https://patch.msgid.link/[email protected]
https://patch.msgid.link/[email protected]
Quoted 31 lines
drivers/md/raid5.c +3
-2@@ -7538,7 +7538,8 @@ static void raid5_free_percpu(struct r5conf *conf)if (!conf->percpu)return ; -cpuhp_state_remove_instance (CPUHP_MD_RAID5_PREPARE , &conf->node); +if (!hlist_unhashed (&conf->node)) +cpuhp_state_remove_instance (CPUHP_MD_RAID5_PREPARE , &conf->node);free_percpu (conf->percpu); }@@ -7675,6 +7676,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)if (conf ==NULL ) goto abort; + conf->mddev = mddev;#if PAGE_SIZE !=DEFAULT_STRIPE_SIZE conf->stripe_size =DEFAULT_STRIPE_SIZE ; conf->stripe_shift =ilog2 (DEFAULT_STRIPE_SIZE ) -9 ;@@ -7743,7 +7745,6 @@ static struct r5conf *setup_conf(struct mddev *mddev) ret =bioset_init (&conf->bio_split,BIO_POOL_SIZE ,0 ,0 );if (ret) goto abort; - conf->mddev = mddev; ret = -ENOMEM ; conf->stripe_hashtbl =kzalloc (PAGE_SIZE ,GFP_KERNEL );
Signature · 2 lines
Thanks, Kuai