Skip to content

Commit

Permalink
ipv4: ip_check_defrag should not assume that skb_network_offset is zero
Browse files Browse the repository at this point in the history
ip_check_defrag() may be used by af_packet to defragment outgoing packets.
skb_network_offset() of af_packet's outgoing packets is not zero.

Signed-off-by: Alexander Drozdov <al.drozdov@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Alexander Drozdov authored and David S. Miller committed Mar 6, 2015
1 parent 386668a commit 3e32e73
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions net/ipv4/ip_fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,27 +659,30 @@ EXPORT_SYMBOL(ip_defrag);
struct sk_buff *ip_check_defrag(struct sk_buff *skb, u32 user)
{
struct iphdr iph;
int netoff;
u32 len;

if (skb->protocol != htons(ETH_P_IP))
return skb;

if (skb_copy_bits(skb, 0, &iph, sizeof(iph)) < 0)
netoff = skb_network_offset(skb);

if (skb_copy_bits(skb, netoff, &iph, sizeof(iph)) < 0)
return skb;

if (iph.ihl < 5 || iph.version != 4)
return skb;

len = ntohs(iph.tot_len);
if (skb->len < len || len < (iph.ihl * 4))
if (skb->len < netoff + len || len < (iph.ihl * 4))
return skb;

if (ip_is_fragment(&iph)) {
skb = skb_share_check(skb, GFP_ATOMIC);
if (skb) {
if (!pskb_may_pull(skb, iph.ihl*4))
if (!pskb_may_pull(skb, netoff + iph.ihl * 4))
return skb;
if (pskb_trim_rcsum(skb, len))
if (pskb_trim_rcsum(skb, netoff + len))
return skb;
memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
if (ip_defrag(skb, user))
Expand Down

0 comments on commit 3e32e73

Please sign in to comment.