usb: rtl8150: Initialize buffers to fix KMSAN uninit-value in rtl8150_open
Subsystems (5)
PATCH v3 1/1 usb: rtl8150: Initialize buffers to fix KMSAN uninit-value in rtl8150_open
KMSAN reported an uninitialized value use in rtl8150_open(). Initialize rx_skb->data and intr_buff before submitting URBs to ensure memory is in a defined state.
Changes in v3:
- Fixed whitespace and indentation (checkpatch clean)
- Corrected syzbot tag
- Corrected syzbot hash and tag
--- drivers/net/usb/rtl8150.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)
drivers/net/usb/rtl8150.c +15 -19
@@ -735,33 +735,30 @@ static int rtl8150_open(struct net_device *netdev)rtl8150_t *dev =netdev_priv (netdev);int res; -if (dev->rx_skb ==NULL ) - dev->rx_skb =pull_skb (dev); -if (!dev->rx_skb) -return -ENOMEM ; -set_registers (dev,IDR ,6 , netdev->dev_addr);/* Fix: initialize memory before using it (KMSAN uninit-value) */ memset (dev->rx_skb->data,0 ,RTL8150_MTU );memset (dev->intr_buff,0 ,INTBUFSIZE ); -usb_fill_bulk_urb (dev->rx_urb, dev->udev,usb_rcvbulkpipe (dev->udev,1 ), - dev->rx_skb->data,RTL8150_MTU , read_bulk_callback, dev); -if ((res =usb_submit_urb (dev->rx_urb,GFP_KERNEL ))) { -if (res == -ENODEV ) -netif_device_detach (dev->netdev); +usb_fill_bulk_urb (dev->rx_urb, dev->udev, +usb_rcvbulkpipe (dev->udev,1 ), + dev->rx_skb->data,RTL8150_MTU , + read_bulk_callback, dev); + + res =usb_submit_urb (dev->rx_urb,GFP_KERNEL ); +if (res) {dev_warn (&netdev->dev,"rx_urb submit failed: %d\n" , res);return res; } -usb_fill_int_urb (dev->intr_urb, dev->udev,usb_rcvintpipe (dev->udev,3 ), - dev->intr_buff,INTBUFSIZE , intr_callback, - dev, dev->intr_interval); -if ((res =usb_submit_urb (dev->intr_urb,GFP_KERNEL ))) { -if (res == -ENODEV ) -netif_device_detach (dev->netdev); -dev_warn (&netdev->dev,"intr_urb submit failed: %d\n" , res); +usb_fill_int_urb (dev->intr_urb, dev->udev, +usb_rcvintpipe (dev->udev,3 ), + dev->intr_buff,INTBUFSIZE , + intr_callback, dev, dev->intr_interval); + + res =usb_submit_urb (dev->intr_urb,GFP_KERNEL ); +if (res) {usb_kill_urb (dev->rx_urb);return res; }
@@ -769,8 +766,7 @@ static int rtl8150_open(struct net_device *netdev)enable_net_traffic (dev);set_carrier (netdev);netif_start_queue (netdev); - -return res; +return 0 ; }static int rtl8150_close (struct net_device *netdev)
Signature · 1 line
2.43.0
drivers/net/usb/rtl8150.c static int rtl8150_open(struct net_device *netdev) · line 770
Quoted 12 lines · Dharanitharan R
KMSAN reported an uninitialized value use in
rtl8150_open(). Initializerx_skb->dataandintr_buffbefore submitting URBs to ensure memory is in a defined state.drivers/net/usb/rtl8150.c +1
-2@@ -769,8 +766,7 @@ static int rtl8150_open(struct net_device *netdev)enable_net_traffic (dev);set_carrier (netdev);netif_start_queue (netdev); - -return res; +return 0 ; }
While i agree that res is guaranteed to by 0, this change has nothing to do with fixing a KMSAN report. Please make it a separate patch in a patch series. A patch should do one thing, and the commit message should explain the "why?" of the change.
Please also take a read of:
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
The Subject line should indicate which tree this is for.
Andrew
drivers/net/usb/rtl8150.c static int rtl8150_open(struct net_device *netdev) · line 747
Quoted 9 lines
drivers/net/usb/rtl8150.c +4
-5-usb_fill_bulk_urb (dev->rx_urb, dev->udev,usb_rcvbulkpipe (dev->udev,1 ), - dev->rx_skb->data,RTL8150_MTU , read_bulk_callback, dev); -if ((res =usb_submit_urb (dev->rx_urb,GFP_KERNEL ))) { -if (res == -ENODEV ) -netif_device_detach (dev->netdev); +usb_fill_bulk_urb (dev->rx_urb, dev->udev, +usb_rcvbulkpipe (dev->udev,1 ), + dev->rx_skb->data,RTL8150_MTU , + read_bulk_callback, dev);
If im reading this correctly, the usb_fill_bulk_urb() is identical, you have just changed the wrapping. So this again has nothing to do with the issue you are trying to fix. Changes like this make it harder to see the real change which fixes the problem. And at the moment, i don't see the actual fix.
If you want to make changes like this, please do so in a patch of its own which only changes the wrapping, nothing else. That is then easy to review.
Lots of small changes, which hopefully are obviously correct, with good commit messages please.
Andrew
---
pw-bot: cr
Greg KH
maintainerQuoted 8 lines · Dharanitharan R
KMSAN reported an uninitialized value use in
rtl8150_open(). Initializerx_skb->dataandintr_buffbefore submitting URBs to ensure memory is in a defined state.Changes in v3:
- Fixed whitespace and indentation (checkpatch clean)
- Corrected syzbot tag
- Corrected syzbot hash and tag
Please follow the documentation for where to put this version information.
Quoted 11 lines
Reported-by [email protected]Signed-off-by Dharanitharan R <[email protected]>--- drivers/net/usb/rtl8150.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)drivers/net/usb/rtl8150.c +0
-0
drivers/net/usb/rtl8150.c static int rtl8150_open(struct net_device *netdev) · line 741
Quoted 7 lines
drivers/net/usb/rtl8150.c +0
-4@@ -735,33 +735,30 @@ static int rtl8150_open(struct net_device *netdev)rtl8150_t *dev =netdev_priv (netdev);int res; -if (dev->rx_skb ==NULL ) - dev->rx_skb =pull_skb (dev); -if (!dev->rx_skb) -return -ENOMEM ;
It looks like you are attempting to break existing situations?
Quoted 9 lines
drivers/net/usb/rtl8150.c +0
-3-set_registers (dev,IDR ,6 , netdev->dev_addr);/* Fix: initialize memory before using it (KMSAN uninit-value) */ memset (dev->rx_skb->data,0 ,RTL8150_MTU );memset (dev->intr_buff,0 ,INTBUFSIZE ); -usb_fill_bulk_urb (dev->rx_urb, dev->udev,usb_rcvbulkpipe (dev->udev,1 ), - dev->rx_skb->data,RTL8150_MTU , read_bulk_callback, dev);
drivers/net/usb/rtl8150.c static int rtl8150_open(struct net_device *netdev) · line 750
Quoted 10 lines
drivers/net/usb/rtl8150.c +7
-3-if ((res =usb_submit_urb (dev->rx_urb,GFP_KERNEL ))) { -if (res == -ENODEV ) -netif_device_detach (dev->netdev); +usb_fill_bulk_urb (dev->rx_urb, dev->udev, +usb_rcvbulkpipe (dev->udev,1 ), + dev->rx_skb->data,RTL8150_MTU , + read_bulk_callback, dev); + + res =usb_submit_urb (dev->rx_urb,GFP_KERNEL ); +if (res) {
Why did you break the -ENODEV situation?
How was this tested?
greg k-h