Skip to content

Commit 6c57f04

Browse files
rosslagerwalldavem330
authored andcommitted
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>
1 parent e40e2a2 commit 6c57f04

File tree

5 files changed

+5
-0
lines changed

5 files changed

+5
-0
lines changed

drivers/net/ppp/pppoe.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ static int pppoe_rcv(struct sk_buff *skb, struct net_device *dev,
445445
if (pskb_trim_rcsum(skb, len))
446446
goto drop;
447447

448+
ph = pppoe_hdr(skb);
448449
pn = pppoe_pernet(dev_net(dev));
449450

450451
/* Note that get_item does a sock_hold(), so sk_pppox(po)

include/linux/skbuff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,6 +3218,7 @@ int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned int len);
32183218
*
32193219
* This is exactly the same as pskb_trim except that it ensures the
32203220
* checksum of received packets are still valid after the operation.
3221+
* It can change skb pointers.
32213222
*/
32223223

32233224
static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len)

net/bridge/br_netfilter_ipv6.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ int br_validate_ipv6(struct net *net, struct sk_buff *skb)
131131
IPSTATS_MIB_INDISCARDS);
132132
goto drop;
133133
}
134+
hdr = ipv6_hdr(skb);
134135
}
135136
if (hdr->nexthdr == NEXTHDR_HOP && br_nf_check_hbh_len(skb))
136137
goto drop;

net/bridge/netfilter/nft_reject_bridge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ static bool reject6_br_csum_ok(struct sk_buff *skb, int hook)
229229
pskb_trim_rcsum(skb, ntohs(ip6h->payload_len) + sizeof(*ip6h)))
230230
return false;
231231

232+
ip6h = ipv6_hdr(skb);
232233
thoff = ipv6_skip_exthdr(skb, ((u8*)(ip6h+1) - skb->data), &proto, &fo);
233234
if (thoff < 0 || thoff >= skb->len || (fo & htons(~0x7)) != 0)
234235
return false;

net/ipv4/ip_input.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)
488488
goto drop;
489489
}
490490

491+
iph = ip_hdr(skb);
491492
skb->transport_header = skb->network_header + iph->ihl*4;
492493

493494
/* Remove any debris in the socket control block */

0 commit comments

Comments
 (0)