dm-unstripe: terminate the status string for STATUSTYPE_INFO
PATCH 1/1 dm-unstripe: terminate the status string for STATUSTYPE_INFO
unstripe_status() writes nothing to the result buffer for STATUSTYPE_INFO. retrieve_status() then runs strlen() on that buffer, which still holds whatever the caller passed in the ioctl payload. If the payload contains no NUL byte, strlen() runs past the end of the kernel copy of the ioctl buffer:
BUG: KASAN: slab-out-of-bounds in strlen+0x8f/0xa0 lib/string.c:402 Read of size 1 at addr ffff888109690566 by task syz.1.18/1420 CPU: 0 UID: 0 PID: 1420 Comm: syz.1.18 Not tainted 7.4.0-rc1-next-20261104-alt-syz-box-drivers_md_bcache #1 PREEMPT(lazy) Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0xc2/0x120 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0xce/0x640 mm/kasan/report.c:482 kasan_report+0xdc/0x110 mm/kasan/report.c:595 strlen+0x8f/0xa0 lib/string.c:402 __fortify_strlen include/linux/fortify-string.h:218 [inline] retrieve_status+0x483/0x8c0 drivers/md/dm-ioctl.c:1442 dev_wait+0x1ba/0x210 drivers/md/dm-ioctl.c:1496 ctl_ioctl+0x4d2/0xd70 drivers/md/dm-ioctl.c:2221 dm_ctl_ioctl+0x1e/0x30 drivers/md/dm-ioctl.c:2243 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+0x18a/0x210 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline] do_syscall_64+0x112/0x630 arch/x86/entry/syscall_64.c:89 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x00007f6a853ea829 </TASK>
retrieve_status() then also reports a data_size past the end of the payload, and ctl_ioctl() copies the bytes behind it back to userspace. The same happens with DM_TABLE_STATUS.
Other targets emit at least an empty string here; do the same as for STATUSTYPE_IMA.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Fixes 18a5bf270532 ("dm: add unstriped target")
Signed-off-by Vasiliy Kovalev <[email protected]>
--- drivers/md/dm-unstripe.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/dm-unstripe.c +1 -0
@@ -150,6 +150,7 @@ static void unstripe_status(struct dm_target *ti, status_type_t type,switch (type) {case STATUSTYPE_INFO : + *result ='\0' ;break ;case STATUSTYPE_TABLE :
Signature · 1 line
2.50.1