Commit 1bf3751e authored by Johannes Berg's avatar Johannes Berg Committed by David S. Miller

ipv4: ip_check_defrag must not modify skb before unsharing

ip_check_defrag() might be called from af_packet within the
RX path where shared SKBs are used, so it must not modify
the input SKB before it has unshared it for defragmentation.
Use skb_copy_bits() to get the IP header and only pull in
everything later.

The same is true for the other caller in macvlan as it is
called from dev->rx_handler which can also get a shared SKB.
Reported-by: default avatarEric Leblond <eric@regit.org>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5e1f5420
...@@ -707,28 +707,27 @@ EXPORT_SYMBOL(ip_defrag); ...@@ -707,28 +707,27 @@ EXPORT_SYMBOL(ip_defrag);
struct sk_buff *ip_check_defrag(struct sk_buff *skb, u32 user) struct sk_buff *ip_check_defrag(struct sk_buff *skb, u32 user)
{ {
const struct iphdr *iph; struct iphdr iph;
u32 len; u32 len;
if (skb->protocol != htons(ETH_P_IP)) if (skb->protocol != htons(ETH_P_IP))
return skb; return skb;
if (!pskb_may_pull(skb, sizeof(struct iphdr))) if (!skb_copy_bits(skb, 0, &iph, sizeof(iph)))
return skb; return skb;
iph = ip_hdr(skb); if (iph.ihl < 5 || iph.version != 4)
if (iph->ihl < 5 || iph->version != 4)
return skb;
if (!pskb_may_pull(skb, iph->ihl*4))
return skb; return skb;
iph = ip_hdr(skb);
len = ntohs(iph->tot_len); len = ntohs(iph.tot_len);
if (skb->len < len || len < (iph->ihl * 4)) if (skb->len < len || len < (iph.ihl * 4))
return skb; return skb;
if (ip_is_fragment(ip_hdr(skb))) { if (ip_is_fragment(&iph)) {
skb = skb_share_check(skb, GFP_ATOMIC); skb = skb_share_check(skb, GFP_ATOMIC);
if (skb) { if (skb) {
if (!pskb_may_pull(skb, iph.ihl*4))
return skb;
if (pskb_trim_rcsum(skb, len)) if (pskb_trim_rcsum(skb, len))
return skb; return skb;
memset(IPCB(skb), 0, sizeof(struct inet_skb_parm)); memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
......
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