Skip to content

Commit

Permalink
r8152: Set memory to all 0xFFs on failed reg reads
Browse files Browse the repository at this point in the history
get_registers() blindly copies the memory written to by the
usb_control_msg() call even if the underlying urb failed.

This could lead to junk register values being read by the driver, since
some indirect callers of get_registers() ignore the return values. One
example is:
  ocp_read_dword() ignores the return value of generic_ocp_read(), which
  calls get_registers().

So, emulate PCI "Master Abort" behavior by setting the buffer to all
0xFFs when usb_control_msg() fails.

This patch is copied from the r8152 driver (v2.12.0) published by
Realtek (www.realtek.com).

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Acked-by: Hayes Wang <hayeswang@realtek.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Prashant Malani authored and David S. Miller committed Aug 26, 2019
1 parent 7177895 commit f53a7ad
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/net/usb/r8152.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,11 @@ int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
ret = usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0),
RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
value, index, tmp, size, 500);
if (ret < 0)
memset(data, 0xff, size);
else
memcpy(data, tmp, size);

memcpy(data, tmp, size);
kfree(tmp);

return ret;
Expand Down

0 comments on commit f53a7ad

Please sign in to comment.