Skip to content

Commit

Permalink
netpoll: accept NULL np argument in netpoll_send_skb()
Browse files Browse the repository at this point in the history
netpoll_send_skb() callers seem to leak skb if
the np pointer is NULL. While this should not happen, we
can make the code more robust.

Signed-off-by: Eric Dumazet <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed May 8, 2020
1 parent 1ddabdf commit f78ed22
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 24 deletions.
5 changes: 2 additions & 3 deletions drivers/net/macvlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,11 @@ static int macvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev)
static inline netdev_tx_t macvlan_netpoll_send_skb(struct macvlan_dev *vlan, struct sk_buff *skb)
{
#ifdef CONFIG_NET_POLL_CONTROLLER
if (vlan->netpoll)
netpoll_send_skb(vlan->netpoll, skb);
return netpoll_send_skb(vlan->netpoll, skb);
#else
BUG();
#endif
return NETDEV_TX_OK;
#endif
}

static netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
Expand Down
5 changes: 1 addition & 4 deletions include/linux/if_team.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ static inline bool team_port_dev_txable(const struct net_device *port_dev)
static inline void team_netpoll_send_skb(struct team_port *port,
struct sk_buff *skb)
{
struct netpoll *np = port->np;

if (np)
netpoll_send_skb(np, skb);
netpoll_send_skb(port->np, skb);
}
#else
static inline void team_netpoll_send_skb(struct team_port *port,
Expand Down
5 changes: 1 addition & 4 deletions include/net/bonding.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,7 @@ static inline unsigned long slave_last_rx(struct bonding *bond,
static inline void bond_netpoll_send_skb(const struct slave *slave,
struct sk_buff *skb)
{
struct netpoll *np = slave->np;

if (np)
netpoll_send_skb(np, skb);
netpoll_send_skb(slave->np, skb);
}
#else
static inline void bond_netpoll_send_skb(const struct slave *slave,
Expand Down
5 changes: 2 additions & 3 deletions net/8021q/vlan_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ static int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
static inline netdev_tx_t vlan_netpoll_send_skb(struct vlan_dev_priv *vlan, struct sk_buff *skb)
{
#ifdef CONFIG_NET_POLL_CONTROLLER
if (vlan->netpoll)
netpoll_send_skb(vlan->netpoll, skb);
return netpoll_send_skb(vlan->netpoll, skb);
#else
BUG();
#endif
return NETDEV_TX_OK;
#endif
}

static netdev_tx_t vlan_dev_hard_start_xmit(struct sk_buff *skb,
Expand Down
5 changes: 1 addition & 4 deletions net/bridge/br_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
struct sk_buff *skb)
{
struct netpoll *np = p->np;

if (np)
netpoll_send_skb(np, skb);
netpoll_send_skb(p->np, skb);
}

int br_netpoll_enable(struct net_bridge_port *p);
Expand Down
11 changes: 8 additions & 3 deletions net/core/netpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,14 @@ netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
unsigned long flags;
netdev_tx_t ret;

local_irq_save(flags);
ret = __netpoll_send_skb(np, skb);
local_irq_restore(flags);
if (unlikely(!np)) {
dev_kfree_skb_irq(skb);
ret = NET_XMIT_DROP;
} else {
local_irq_save(flags);
ret = __netpoll_send_skb(np, skb);
local_irq_restore(flags);
}
return ret;
}
EXPORT_SYMBOL(netpoll_send_skb);
Expand Down
5 changes: 2 additions & 3 deletions net/dsa/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,11 @@ static inline netdev_tx_t dsa_slave_netpoll_send_skb(struct net_device *dev,
#ifdef CONFIG_NET_POLL_CONTROLLER
struct dsa_slave_priv *p = netdev_priv(dev);

if (p->netpoll)
netpoll_send_skb(p->netpoll, skb);
return netpoll_send_skb(p->netpoll, skb);
#else
BUG();
#endif
return NETDEV_TX_OK;
#endif
}

static void dsa_skb_tx_timestamp(struct dsa_slave_priv *p,
Expand Down

0 comments on commit f78ed22

Please sign in to comment.