Skip to content

Commit 9ad0452

Browse files
qasim-ijazkuba-moo
authored andcommitted
net: ch9200: fix uninitialised access during mii_nway_restart
In mii_nway_restart() the code attempts to call mii->mdio_read which is ch9200_mdio_read(). ch9200_mdio_read() utilises a local buffer called "buff", which is initialised with control_read(). However "buff" is conditionally initialised inside control_read(): if (err == size) { memcpy(data, buf, size); } If the condition of "err == size" is not met, then "buff" remains uninitialised. Once this happens the uninitialised "buff" is accessed and returned during ch9200_mdio_read(): return (buff[0] | buff[1] << 8); The problem stems from the fact that ch9200_mdio_read() ignores the return value of control_read(), leading to uinit-access of "buff". To fix this we should check the return value of control_read() and return early on error. Reported-by: syzbot <[email protected]> Closes: https://syzkaller.appspot.com/bug?extid=3361c2d6f78a3e0892f9 Tested-by: syzbot <[email protected]> Fixes: 4a476bd ("usbnet: New driver for QinHeng CH9200 devices") Cc: [email protected] Signed-off-by: Qasim Ijaz <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8542d6f commit 9ad0452

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/net/usb/ch9200.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,18 @@ static int ch9200_mdio_read(struct net_device *netdev, int phy_id, int loc)
178178
{
179179
struct usbnet *dev = netdev_priv(netdev);
180180
unsigned char buff[2];
181+
int ret;
181182

182183
netdev_dbg(netdev, "%s phy_id:%02x loc:%02x\n",
183184
__func__, phy_id, loc);
184185

185186
if (phy_id != 0)
186187
return -ENODEV;
187188

188-
control_read(dev, REQUEST_READ, 0, loc * 2, buff, 0x02,
189-
CONTROL_TIMEOUT_MS);
189+
ret = control_read(dev, REQUEST_READ, 0, loc * 2, buff, 0x02,
190+
CONTROL_TIMEOUT_MS);
191+
if (ret < 0)
192+
return ret;
190193

191194
return (buff[0] | buff[1] << 8);
192195
}

0 commit comments

Comments
 (0)