Skip to content

Commit

Permalink
vlan/macvlan: fix NULL pointer dereferences in ethtool handlers
Browse files Browse the repository at this point in the history
Check whether the underlying device provides a set of ethtool ops before
checking for individual handlers to avoid NULL pointer dereferences.

Reported-by: Art van Breemen <ard@telegraafnet.nl>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Patrick McHardy authored and David S. Miller committed Apr 17, 2009
1 parent 75a241f commit 7816a0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions drivers/net/macvlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ static u32 macvlan_ethtool_get_rx_csum(struct net_device *dev)
const struct macvlan_dev *vlan = netdev_priv(dev);
struct net_device *lowerdev = vlan->lowerdev;

if (lowerdev->ethtool_ops->get_rx_csum == NULL)
if (lowerdev->ethtool_ops == NULL ||
lowerdev->ethtool_ops->get_rx_csum == NULL)
return 0;
return lowerdev->ethtool_ops->get_rx_csum(lowerdev);
}
Expand All @@ -387,7 +388,8 @@ static int macvlan_ethtool_get_settings(struct net_device *dev,
const struct macvlan_dev *vlan = netdev_priv(dev);
struct net_device *lowerdev = vlan->lowerdev;

if (!lowerdev->ethtool_ops->get_settings)
if (!lowerdev->ethtool_ops ||
!lowerdev->ethtool_ops->get_settings)
return -EOPNOTSUPP;

return lowerdev->ethtool_ops->get_settings(lowerdev, cmd);
Expand All @@ -398,7 +400,8 @@ static u32 macvlan_ethtool_get_flags(struct net_device *dev)
const struct macvlan_dev *vlan = netdev_priv(dev);
struct net_device *lowerdev = vlan->lowerdev;

if (!lowerdev->ethtool_ops->get_flags)
if (!lowerdev->ethtool_ops ||
!lowerdev->ethtool_ops->get_flags)
return 0;
return lowerdev->ethtool_ops->get_flags(lowerdev);
}
Expand Down
3 changes: 2 additions & 1 deletion net/8021q/vlan_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ static int vlan_ethtool_get_settings(struct net_device *dev,
const struct vlan_dev_info *vlan = vlan_dev_info(dev);
struct net_device *real_dev = vlan->real_dev;

if (!real_dev->ethtool_ops->get_settings)
if (!real_dev->ethtool_ops ||
!real_dev->ethtool_ops->get_settings)
return -EOPNOTSUPP;

return real_dev->ethtool_ops->get_settings(real_dev, cmd);
Expand Down

0 comments on commit 7816a0a

Please sign in to comment.