Skip to content

Commit eb996ed

Browse files
Colin Ian Kingdavem330
authored andcommitted
netvsc: fix dereference before null check errors
ndev is being checked to see if it is a null pointer however before the null check ndev is being dereferenced; hence there is a potential null pointer dereference bug that needs fixing. Fix this by only dereferencing ndev after the null check. Detected by CoverityScan, CID#1420760, CID#140761 ("Dereference before null check") Signed-off-by: Colin Ian King <[email protected]> Reviewed-by: Haiyang Zhang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 86573f6 commit eb996ed

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/net/hyperv/netvsc_drv.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ static int netvsc_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
11351135
{
11361136
struct net_device_context *ndc = netdev_priv(dev);
11371137
struct netvsc_device *ndev = rcu_dereference(ndc->nvdev);
1138-
struct rndis_device *rndis_dev = ndev->extension;
1138+
struct rndis_device *rndis_dev;
11391139
int i;
11401140

11411141
if (!ndev)
@@ -1144,6 +1144,7 @@ static int netvsc_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
11441144
if (hfunc)
11451145
*hfunc = ETH_RSS_HASH_TOP; /* Toeplitz */
11461146

1147+
rndis_dev = ndev->extension;
11471148
if (indir) {
11481149
for (i = 0; i < ITAB_NUM; i++)
11491150
indir[i] = rndis_dev->ind_table[i];
@@ -1160,7 +1161,7 @@ static int netvsc_set_rxfh(struct net_device *dev, const u32 *indir,
11601161
{
11611162
struct net_device_context *ndc = netdev_priv(dev);
11621163
struct netvsc_device *ndev = rtnl_dereference(ndc->nvdev);
1163-
struct rndis_device *rndis_dev = ndev->extension;
1164+
struct rndis_device *rndis_dev;
11641165
int i;
11651166

11661167
if (!ndev)
@@ -1169,6 +1170,7 @@ static int netvsc_set_rxfh(struct net_device *dev, const u32 *indir,
11691170
if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
11701171
return -EOPNOTSUPP;
11711172

1173+
rndis_dev = ndev->extension;
11721174
if (indir) {
11731175
for (i = 0; i < ITAB_NUM; i++)
11741176
if (indir[i] >= dev->num_rx_queues)

0 commit comments

Comments
 (0)