Skip to content

Commit d668769

Browse files
pskrgagkuba-moo
authored andcommitted
net: mcs7830: handle usb read errors properly
Syzbot reported uninit value in mcs7830_bind(). The problem was in missing validation check for bytes read via usbnet_read_cmd(). usbnet_read_cmd() internally calls usb_control_msg(), that returns number of bytes read. Code should validate that requested number of bytes was actually read. So, this patch adds missing size validation check inside mcs7830_get_reg() to prevent uninit value bugs Reported-and-tested-by: syzbot+003c0a286b9af5412510@syzkaller.appspotmail.com Fixes: 2a36d70 ("USB: driver for mcs7830 (aka DeLOCK) USB ethernet adapter") Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20220106225716.7425-1-paskripkin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 6f022c2 commit d668769

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

drivers/net/usb/mcs7830.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,16 @@ static const char driver_name[] = "MOSCHIP usb-ethernet driver";
108108

109109
static int mcs7830_get_reg(struct usbnet *dev, u16 index, u16 size, void *data)
110110
{
111-
return usbnet_read_cmd(dev, MCS7830_RD_BREQ, MCS7830_RD_BMREQ,
112-
0x0000, index, data, size);
111+
int ret;
112+
113+
ret = usbnet_read_cmd(dev, MCS7830_RD_BREQ, MCS7830_RD_BMREQ,
114+
0x0000, index, data, size);
115+
if (ret < 0)
116+
return ret;
117+
else if (ret < size)
118+
return -ENODATA;
119+
120+
return ret;
113121
}
114122

115123
static int mcs7830_set_reg(struct usbnet *dev, u16 index, u16 size, const void *data)

0 commit comments

Comments
 (0)