Re: [syzbot] [usb?] KMSAN: kernel-usb-infoleak in usbtmc_write
From: Edward Adam Davis
Date: Fri Sep 06 2024 - 08:44:13 EST
Clear the buffer that has not been set, after copying data from user space.
#syz test
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 6bd9fe565385..faf8c5508997 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -1591,6 +1591,10 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
goto exit;
}
+ if (aligned < buflen)
+ memset(&buffer[USBTMC_HEADER_SIZE + transfersize], 0,
+ aligned - USBTMC_HEADER_SIZE - transfersize);
+
dev_dbg(&data->intf->dev, "%s(size:%u align:%u)\n", __func__,
(unsigned int)transfersize, (unsigned int)aligned);