usb: rtl8150: Initialize buffers to fix KMSAN uninit-value in rtl8150_open
Subsystems (5)
PATCH 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.
--- drivers/net/usb/rtl8150.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/net/usb/rtl8150.c +14 -7
@@ -719,14 +719,15 @@ static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,static void set_carrier (struct net_device *netdev) { -rtl8150_t *dev =netdev_priv (netdev); -short tmp; +rtl8150_t *dev =netdev_priv (netdev); +short tmp; -get_registers (dev,CSCR ,2 , &tmp); -if (tmp &CSCR_LINK_STATUS ) -netif_carrier_on (netdev); -else -netif_carrier_off (netdev); +/* Only use tmp if get_registers() succeeds */ +if (!get_registers (dev,CSCR ,2 , &tmp) && + (tmp &CSCR_LINK_STATUS )) +netif_carrier_on (netdev); +else +netif_carrier_off (netdev); }static int rtl8150_open (struct net_device *netdev)
@@ -741,6 +742,10 @@ static int rtl8150_open(struct net_device *netdev)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 ))) {
@@ -749,6 +754,7 @@ static int rtl8150_open(struct net_device *netdev)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);
@@ -759,6 +765,7 @@ static int rtl8150_open(struct net_device *netdev)usb_kill_urb (dev->rx_urb);return res; } +enable_net_traffic (dev);set_carrier (netdev);netif_start_queue (netdev);
Signature · 1 line
2.43.0
syzbot
syzbotI see the command but can't find the corresponding bug. The email is sent to [email protected] address but the HASH does not correspond to any known bug. Please double check the…
Quoted 67 lines
KMSAN reported an uninitialized value use in
rtl8150_open(). Initializerx_skb->dataandintr_buffbefore submitting URBs to ensure memory is in a defined state.Reported-by [email protected]Signed-off-by Dharanitharan R <[email protected]>--- drivers/net/usb/rtl8150.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)drivers/net/usb/rtl8150.c +14
-7@@ -719,14 +719,15 @@ static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,static void set_carrier (struct net_device *netdev) { -rtl8150_t *dev =netdev_priv (netdev); -short tmp; +rtl8150_t *dev =netdev_priv (netdev); +short tmp; -get_registers (dev,CSCR ,2 , &tmp); -if (tmp &CSCR_LINK_STATUS ) -netif_carrier_on (netdev); -else -netif_carrier_off (netdev); +/* Only use tmp if get_registers() succeeds */ +if (!get_registers (dev,CSCR ,2 , &tmp) && + (tmp &CSCR_LINK_STATUS )) +netif_carrier_on (netdev); +else +netif_carrier_off (netdev); }static int rtl8150_open (struct net_device *netdev)@@ -741,6 +742,10 @@ static int rtl8150_open(struct net_device *netdev)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 ))) {@@ -749,6 +754,7 @@ static int rtl8150_open(struct net_device *netdev)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);@@ -759,6 +765,7 @@ static int rtl8150_open(struct net_device *netdev)usb_kill_urb (dev->rx_urb);return res; } +enable_net_traffic (dev);set_carrier (netdev);netif_start_queue (netdev);Signature · 1 line
2.43.0
I see the command but can't find the corresponding bug. The email is sent to [email protected] address but the HASH does not correspond to any known bug. Please double check the address.
Quoted 15 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.Reported-by [email protected]Signed-off-by Dharanitharan R <[email protected]>--- drivers/net/usb/rtl8150.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)drivers/net/usb/rtl8150.c +0
-0
drivers/net/usb/rtl8150.c static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb, · line 723
Quoted 7 lines
drivers/net/usb/rtl8150.c +2
-2@@ -719,14 +719,15 @@ static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,static void set_carrier (struct net_device *netdev) { -rtl8150_t *dev =netdev_priv (netdev); -short tmp; +rtl8150_t *dev =netdev_priv (netdev); +short tmp;
You are messing up the whitespace here.
Did you not read your own patch and notice this problem? checkpatch probably also complained.
Andrew
---
pw-bot: cr
syzbot
syzbotI see the command but can't find the corresponding bug. The email is sent to [email protected] address but the HASH does not correspond to any known bug. Please double check the…
Quoted 26 lines · Dharanitharan R
Quoted 15 lines
KMSAN reported an uninitialized value use in
rtl8150_open(). Initializerx_skb->dataandintr_buffbefore submitting URBs to ensure memory is in a defined state.Reported-by [email protected]Signed-off-by Dharanitharan R <[email protected]>--- drivers/net/usb/rtl8150.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)drivers/net/usb/rtl8150.c +0
-0drivers/net/usb/rtl8150.c static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb, · line 723
Quoted 7 lines
drivers/net/usb/rtl8150.c +2
-2@@ -719,14 +719,15 @@ static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,static void set_carrier (struct net_device *netdev) { -rtl8150_t *dev =netdev_priv (netdev); -short tmp; +rtl8150_t *dev =netdev_priv (netdev); +short tmp;You are messing up the whitespace here.
Quoted 7 lines
Did you not read your own patch and notice this problem? checkpatch probably also complained.
Andrew
---
pw-bot: cr
I see the command but can't find the corresponding bug. The email is sent to [email protected] address but the HASH does not correspond to any known bug. Please double check the address.