netpoll: accept NULL np argument in netpoll_send_skb()
authorEric Dumazet <edumazet@google.com>
Thu, 7 May 2020 16:32:21 +0000 (09:32 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 8 May 2020 01:11:07 +0000 (18:11 -0700)
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 <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/macvlan.c
include/linux/if_team.h
include/net/bonding.h
net/8021q/vlan_dev.c
net/bridge/br_private.h
net/core/netpoll.c
net/dsa/slave.c

index 34eb073cdd744fd00e59b0ab46f465721e5b71c3..9a419d5102ce5319424e5b62291e35ca11660069 100644 (file)
@@ -542,12 +542,11 @@ xmit_world:
 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,
index ec7e4bd07f825539c21c74e87bd2f675a72fac9a..537dc2b8c8798594848c39a176a5969227b7230e 100644 (file)
@@ -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,
index 0b696da5c1157b8f5b84fc79babc404840fd67fd..f211983cd52a81804f0ad555eaaa876ad927b40b 100644 (file)
@@ -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,
index 319220b2341ddbda5471ba2dba88a44ca874a75a..f00bb57f0f600b2366eb8ac06da0f1f6d8590099 100644 (file)
@@ -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,
index 78d3a951180ddab3b0c2ee4f042ccfe71958275d..4dc21e8f7e33bc20d980a2c143a96a2bfdee4bb5 100644 (file)
@@ -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);
index 40d2753aa47dd0b83a10a97bb4bacccbc1aaf085..093e90e52bc25411806fe2f3d04ca27cab47ec32 100644 (file)
@@ -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);
index dfb4282fc339d7ca17fbefd83723cd9663e2ee3c..61b0de52040aa3da120b490c0e161d2dc209942f 100644 (file)
@@ -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,