Skip to contentSkip to conversation

net: thunderx: nicvf_main: Fix potential NULL pointer dereference

PATCH Superseded Gustavo A. R. Silva 2 participants 3 messages Apr 3, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: thunderx: nicvf_main: Fix potential NULL pointer dereference

Add null check on kmalloc() return value in order to prevent a null pointer dereference.

Addresses-Coverity-ID: 1467429 ("Dereference null return value")

Fixes 37c3347eb247 ("net: thunderx: add ndo_set_rx_mode callback implementation for VF")
---
 drivers/net/ethernet/cavium/thunder/nicvf_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/cavium/thunder/nicvf_main.c +2 -0
index 1e9a31f..468321a 100644
@@ -1999,6 +1999,8 @@ static void nicvf_set_rx_mode(struct net_device *netdev)
 				struct xcast_addr *xaddr;
 
 				mc_list = kmalloc(sizeof(*mc_list), GFP_ATOMIC);
+				if (unlikely(!mc_list))
+					return;
 				INIT_LIST_HEAD(&mc_list->list);
 				netdev_hw_addr_list_for_each(ha, &netdev->mc) {
 					xaddr = kmalloc(sizeof(*xaddr),
Signature · 1 line
2.7.4
#1 lore raw
Quoted 16 lines · Gustavo A. R. Silva

Add null check on kmalloc() return value in order to prevent a null pointer dereference.

Addresses-Coverity-ID: 1467429 ("Dereference null return value")

Fixes 37c3347eb247 ("net: thunderx: add ndo_set_rx_mode callback implementation for VF")
---
 drivers/net/ethernet/cavium/thunder/nicvf_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/cavium/thunder/nicvf_main.c +0 -0
index 1e9a31f..468321a 100644

drivers/net/ethernet/cavium/thunder/nicvf_main.c static void nicvf_set_rx_mode(struct net_device *netdev) · line 2006

Quoted 8 lines
drivers/net/ethernet/cavium/thunder/nicvf_main.c +2 -0
@@ -1999,6 +1999,8 @@ static void nicvf_set_rx_mode(struct net_device *netdev)
 				struct xcast_addr *xaddr;
 
 				mc_list = kmalloc(sizeof(*mc_list), GFP_ATOMIC);
+				if (unlikely(!mc_list))
+					return;
 				INIT_LIST_HEAD(&mc_list->list);
 				netdev_hw_addr_list_for_each(ha, &netdev->mc) {
 					xaddr = kmalloc(sizeof(*xaddr),

What about the second kmalloc() right there ?

#2 lore raw
Quoted 20 lines · Eric Dumazet
Quoted 17 lines · Gustavo A. R. Silva

Add null check on kmalloc() return value in order to prevent a null pointer dereference.

Addresses-Coverity-ID: 1467429 ("Dereference null return value")

Fixes 37c3347eb247 ("net: thunderx: add ndo_set_rx_mode callback implementation for VF")
---
  drivers/net/ethernet/cavium/thunder/nicvf_main.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/net/ethernet/cavium/thunder/nicvf_main.c +0 -0
index 1e9a31f..468321a 100644
@@ -1999,6 +1999,8 @@ static void nicvf_set_rx_mode(struct net_device *netdev)
  				struct xcast_addr *xaddr;
 
Quoted 10 lines

drivers/net/ethernet/cavium/thunder/nicvf_main.c static void nicvf_set_rx_mode(struct net_device *netdev) · line 2006

Quoted 7 lines
drivers/net/ethernet/cavium/thunder/nicvf_main.c +2 -0
  				mc_list = kmalloc(sizeof(*mc_list), GFP_ATOMIC);
+				if (unlikely(!mc_list))
+					return;
  				INIT_LIST_HEAD(&mc_list->list);
  				netdev_hw_addr_list_for_each(ha, &netdev->mc) {
  					xaddr = kmalloc(sizeof(*xaddr),

What about the second kmalloc() right there ?

Oops. I thought I had it covered.

I'll send v2 with that change shortly.

Thanks for the feedback, Eric.
--
Gustavo