mirror of https://gitee.com/openkylin/linux.git
net: Fix usage of pskb_trim_rcsum
In certain cases, pskb_trim_rcsum() may change skb pointers. Reinitialize header pointers afterwards to avoid potential use-after-frees. Add a note in the documentation of pskb_trim_rcsum(). Found by KASAN. Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
e40e2a2e78
commit
6c57f04580
|
@ -445,6 +445,7 @@ static int pppoe_rcv(struct sk_buff *skb, struct net_device *dev,
|
||||||
if (pskb_trim_rcsum(skb, len))
|
if (pskb_trim_rcsum(skb, len))
|
||||||
goto drop;
|
goto drop;
|
||||||
|
|
||||||
|
ph = pppoe_hdr(skb);
|
||||||
pn = pppoe_pernet(dev_net(dev));
|
pn = pppoe_pernet(dev_net(dev));
|
||||||
|
|
||||||
/* Note that get_item does a sock_hold(), so sk_pppox(po)
|
/* Note that get_item does a sock_hold(), so sk_pppox(po)
|
||||||
|
|
|
@ -3218,6 +3218,7 @@ int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned int len);
|
||||||
*
|
*
|
||||||
* This is exactly the same as pskb_trim except that it ensures the
|
* This is exactly the same as pskb_trim except that it ensures the
|
||||||
* checksum of received packets are still valid after the operation.
|
* checksum of received packets are still valid after the operation.
|
||||||
|
* It can change skb pointers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len)
|
static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len)
|
||||||
|
|
|
@ -131,6 +131,7 @@ int br_validate_ipv6(struct net *net, struct sk_buff *skb)
|
||||||
IPSTATS_MIB_INDISCARDS);
|
IPSTATS_MIB_INDISCARDS);
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
|
hdr = ipv6_hdr(skb);
|
||||||
}
|
}
|
||||||
if (hdr->nexthdr == NEXTHDR_HOP && br_nf_check_hbh_len(skb))
|
if (hdr->nexthdr == NEXTHDR_HOP && br_nf_check_hbh_len(skb))
|
||||||
goto drop;
|
goto drop;
|
||||||
|
|
|
@ -229,6 +229,7 @@ static bool reject6_br_csum_ok(struct sk_buff *skb, int hook)
|
||||||
pskb_trim_rcsum(skb, ntohs(ip6h->payload_len) + sizeof(*ip6h)))
|
pskb_trim_rcsum(skb, ntohs(ip6h->payload_len) + sizeof(*ip6h)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
ip6h = ipv6_hdr(skb);
|
||||||
thoff = ipv6_skip_exthdr(skb, ((u8*)(ip6h+1) - skb->data), &proto, &fo);
|
thoff = ipv6_skip_exthdr(skb, ((u8*)(ip6h+1) - skb->data), &proto, &fo);
|
||||||
if (thoff < 0 || thoff >= skb->len || (fo & htons(~0x7)) != 0)
|
if (thoff < 0 || thoff >= skb->len || (fo & htons(~0x7)) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -488,6 +488,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iph = ip_hdr(skb);
|
||||||
skb->transport_header = skb->network_header + iph->ihl*4;
|
skb->transport_header = skb->network_header + iph->ihl*4;
|
||||||
|
|
||||||
/* Remove any debris in the socket control block */
|
/* Remove any debris in the socket control block */
|
||||||
|
|
Loading…
Reference in New Issue