KASAN: null-ptr-deref Read in dm_kcopyd_client_destroy
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: 4169c9c90532 powerpc/irq: Fix build with CONFIG_PROC_FS=n git tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git console output: https://syzkaller.appspot.com/x/log.txt?x=126fa38e580000 kernel config: https://syzkaller.appspot.com/x/.config?x=e397d1e24d3cb03 dashboard link: https://syzkaller.appspot.com/bug?extid=a2626a25eb2595e3ec3c compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=166fa38e580000
IMPORTANT: if you fix the issue, please add the following tag to the commit:
workqueue: Failed to create a rescuer kthread for wq "kcopyd": -EINTR
==================================================================
BUG: KASAN: null-ptr-deref in instrument_atomic_read include/linux/instrumented.h:82 [inline] BUG: KASAN: null-ptr-deref in atomic_read include/linux/atomic/atomic-instrumented.h:32 [inline] BUG: KASAN: null-ptr-deref in dm_kcopyd_client_destroy+0xae/0x480 drivers/md/dm-kcopyd.c:980 Read of size 4 at addr 0000000000000174 by task syz.2.19/6560 CPU: 0 UID: 0 PID: 6560 Comm: syz.2.19 Not tainted syzkaller #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/15/2026 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 kasan_report+0x117/0x150 mm/kasan/report.c:595 check_region_inline mm/kasan/generic.c:-1 [inline] kasan_check_range+0x264/0x2c0 mm/kasan/generic.c:200 instrument_atomic_read include/linux/instrumented.h:82 [inline] atomic_read include/linux/atomic/atomic-instrumented.h:32 [inline] dm_kcopyd_client_destroy+0xae/0x480 drivers/md/dm-kcopyd.c:980 __destroy+0x172/0x2f0 drivers/md/dm-cache-target.c:1973 cache_create drivers/md/dm-cache-target.c:2604 [inline] cache_ctr+0x1674/0x2bf0 drivers/md/dm-cache-target.c:2649 dm_table_add_target+0x58d/0xc70 drivers/md/dm-table.c:749 populate_table drivers/md/dm-ioctl.c:1602 [inline] table_load+0x325/0x8a0 drivers/md/dm-ioctl.c:1645 ctl_ioctl drivers/md/dm-ioctl.c:2221 [inline] dm_ctl_ioctl+0x9ec/0xe10 drivers/md/dm-ioctl.c:2243 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline] do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fb5b039f559 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:00007fb5b11ce028 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 00007fb5b0626180 RCX: 00007fb5b039f559 RDX: 0000200000000280 RSI: 00000000c138fd09 RDI: 0000000000000004 RBP: 00007fb5b0436b20 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fb5b0626218 R14: 00007fb5b0626180 R15: 00007fff197480a8 </TASK> ==================================================================
---
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
From: Edward Aadm Davis <[email protected]>
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 4169c9c90532
drivers/md/dm-cache-target.c +1 -0
@@ -2544,6 +2544,7 @@ static int cache_create(struct cache_args *ca, struct cache **result)if (IS_ERR (cache->copier)) { *error ="could not create kcopyd client" ; r =PTR_ERR (cache->copier); + cache->copier =NULL ; goto bad; }
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 4169c9c9 powerpc/irq: Fix build with CONFIG_PROC_FS=n git tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git console output: https://syzkaller.appspot.com/x/log.txt?x=108a238e580000 kernel config: https://syzkaller.appspot.com/x/.config?x=e397d1e24d3cb03 dashboard link: https://syzkaller.appspot.com/bug?extid=a2626a25eb2595e3ec3c compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8 patch: https://syzkaller.appspot.com/x/patch.diff?x=10aa6195580000
Note: testing is done by a robot and is best-effort only.
PATCH 1/1 dm: reject kcopyd client destory if it setup failed
In reply to syzbotThe value of cache->copier is -EINTR when failed to create a rescuer kthread for wq kcopyd, in cache_create(), the code jumps directly to __destroy(cache), it merely performs a simple check to see whether copier is NULL, potentially hitting:
BUG: KASAN: null-ptr-deref in dm_kcopyd_client_destroy+0xae/0x480 drivers/md/dm-kcopyd.c:980 Read of size 4 at addr 0000000000000174 by task syz.2.19/6560 Call Trace: dm_kcopyd_client_destroy+0xae/0x480 drivers/md/dm-kcopyd.c:980 __destroy+0x172/0x2f0 drivers/md/dm-cache-target.c:1973 cache_create drivers/md/dm-cache-target.c:2604 [inline] cache_ctr+0x1674/0x2bf0 drivers/md/dm-cache-target.c:2649 dm_table_add_target+0x58d/0xc70 drivers/md/dm-table.c:749 populate_table drivers/md/dm-ioctl.c:1602 [inline] table_load+0x325/0x8a0 drivers/md/dm-ioctl.c:1645 ctl_ioctl drivers/md/dm-ioctl.c:2221 [inline]
Set copier to NULL to avoid destroying a invalid kcopy client.
--- drivers/md/dm-cache-target.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/dm-cache-target.c +1 -0
@@ -2544,6 +2544,7 @@ static int cache_create(struct cache_args *ca, struct cache **result)if (IS_ERR (cache->copier)) { *error ="could not create kcopyd client" ; r =PTR_ERR (cache->copier); + cache->copier =NULL ; goto bad; }
Signature · 1 line
2.43.0
Re: [PATCH] dm: reject kcopyd client destroy if it setup failed
Hi Edward,
I reproduced this bug using the syzkaller repro on a kernel built from the reported commit.
Effectively, in "drivers/md/dm-cache-target.c", if the execution path ends up in a bad_* goto, *kc (which is cache->copier in cache_create) will be freed and the function will return an error pointer, but cache->copier will be dereferenced later in dm_kcopyd_client_destroy, causing the bug.
With your change the reproducer loops on "could not create kcopyd client", which means the null ptr deref is gone.
I suggest removing (or trimming) the call trace in the commit description (is already available in the syzbot report linked in the patch) to keep it cleaner.
With that small change in the commit description you can add my:
Thanks,
Nehuen Lian Bova