Commit c0bbbdc3 authored by Boris Sukholitko's avatar Boris Sukholitko Committed by David S. Miller

__netif_receive_skb_core: pass skb by reference

__netif_receive_skb_core may change the skb pointer passed into it (e.g.
in rx_handler). The original skb may be freed as a result of this
operation.

The callers of __netif_receive_skb_core may further process original skb
by using pt_prev pointer returned by __netif_receive_skb_core thus
leading to unpleasant effects.

The solution is to pass skb by reference into __netif_receive_skb_core.

v2: Added Fixes tag and comment regarding ppt_prev and skb invariant.

Fixes: 88eb1944 ("net: core: propagate SKB lists through packet_type lookup")
Signed-off-by: default avatarBoris Sukholitko <boris.sukholitko@broadcom.com>
Acked-by: default avatarEdward Cree <ecree@solarflare.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 88d7fcfa
...@@ -4988,11 +4988,12 @@ static inline int nf_ingress(struct sk_buff *skb, struct packet_type **pt_prev, ...@@ -4988,11 +4988,12 @@ static inline int nf_ingress(struct sk_buff *skb, struct packet_type **pt_prev,
return 0; return 0;
} }
static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc, static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc,
struct packet_type **ppt_prev) struct packet_type **ppt_prev)
{ {
struct packet_type *ptype, *pt_prev; struct packet_type *ptype, *pt_prev;
rx_handler_func_t *rx_handler; rx_handler_func_t *rx_handler;
struct sk_buff *skb = *pskb;
struct net_device *orig_dev; struct net_device *orig_dev;
bool deliver_exact = false; bool deliver_exact = false;
int ret = NET_RX_DROP; int ret = NET_RX_DROP;
...@@ -5023,8 +5024,10 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc, ...@@ -5023,8 +5024,10 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc,
ret2 = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), skb); ret2 = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), skb);
preempt_enable(); preempt_enable();
if (ret2 != XDP_PASS) if (ret2 != XDP_PASS) {
return NET_RX_DROP; ret = NET_RX_DROP;
goto out;
}
skb_reset_mac_len(skb); skb_reset_mac_len(skb);
} }
...@@ -5174,6 +5177,13 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc, ...@@ -5174,6 +5177,13 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc,
} }
out: out:
/* The invariant here is that if *ppt_prev is not NULL
* then skb should also be non-NULL.
*
* Apparently *ppt_prev assignment above holds this invariant due to
* skb dereferencing near it.
*/
*pskb = skb;
return ret; return ret;
} }
...@@ -5183,7 +5193,7 @@ static int __netif_receive_skb_one_core(struct sk_buff *skb, bool pfmemalloc) ...@@ -5183,7 +5193,7 @@ static int __netif_receive_skb_one_core(struct sk_buff *skb, bool pfmemalloc)
struct packet_type *pt_prev = NULL; struct packet_type *pt_prev = NULL;
int ret; int ret;
ret = __netif_receive_skb_core(skb, pfmemalloc, &pt_prev); ret = __netif_receive_skb_core(&skb, pfmemalloc, &pt_prev);
if (pt_prev) if (pt_prev)
ret = INDIRECT_CALL_INET(pt_prev->func, ipv6_rcv, ip_rcv, skb, ret = INDIRECT_CALL_INET(pt_prev->func, ipv6_rcv, ip_rcv, skb,
skb->dev, pt_prev, orig_dev); skb->dev, pt_prev, orig_dev);
...@@ -5261,7 +5271,7 @@ static void __netif_receive_skb_list_core(struct list_head *head, bool pfmemallo ...@@ -5261,7 +5271,7 @@ static void __netif_receive_skb_list_core(struct list_head *head, bool pfmemallo
struct packet_type *pt_prev = NULL; struct packet_type *pt_prev = NULL;
skb_list_del_init(skb); skb_list_del_init(skb);
__netif_receive_skb_core(skb, pfmemalloc, &pt_prev); __netif_receive_skb_core(&skb, pfmemalloc, &pt_prev);
if (!pt_prev) if (!pt_prev)
continue; continue;
if (pt_curr != pt_prev || od_curr != orig_dev) { if (pt_curr != pt_prev || od_curr != orig_dev) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment