Skip to content

Commit 2614fa5

Browse files
herbertxdavem330
authored andcommitted
[IPCOMP]: Fetch nexthdr before ipch is destroyed
When I moved the nexthdr setting out of IPComp I accidently moved the reading of ipch->nexthdr after the decompression. Unfortunately this means that we'd be reading from a stale ipch pointer which doesn't work very well. This patch moves the reading up so that we get the correct nexthdr value. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 936f6f8 commit 2614fa5

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎net/ipv4/ipcomp.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
7474

7575
static int ipcomp_input(struct xfrm_state *x, struct sk_buff *skb)
7676
{
77+
int nexthdr;
7778
int err = -ENOMEM;
7879
struct ip_comp_hdr *ipch;
7980

@@ -84,13 +85,15 @@ static int ipcomp_input(struct xfrm_state *x, struct sk_buff *skb)
8485

8586
/* Remove ipcomp header and decompress original payload */
8687
ipch = (void *)skb->data;
88+
nexthdr = ipch->nexthdr;
89+
8790
skb->transport_header = skb->network_header + sizeof(*ipch);
8891
__skb_pull(skb, sizeof(*ipch));
8992
err = ipcomp_decompress(x, skb);
9093
if (err)
9194
goto out;
9295

93-
err = ipch->nexthdr;
96+
err = nexthdr;
9497

9598
out:
9699
return err;

‎net/ipv6/ipcomp6.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static LIST_HEAD(ipcomp6_tfms_list);
6464

6565
static int ipcomp6_input(struct xfrm_state *x, struct sk_buff *skb)
6666
{
67+
int nexthdr;
6768
int err = -ENOMEM;
6869
struct ip_comp_hdr *ipch;
6970
int plen, dlen;
@@ -79,6 +80,8 @@ static int ipcomp6_input(struct xfrm_state *x, struct sk_buff *skb)
7980

8081
/* Remove ipcomp header and decompress original payload */
8182
ipch = (void *)skb->data;
83+
nexthdr = ipch->nexthdr;
84+
8285
skb->transport_header = skb->network_header + sizeof(*ipch);
8386
__skb_pull(skb, sizeof(*ipch));
8487

@@ -108,7 +111,7 @@ static int ipcomp6_input(struct xfrm_state *x, struct sk_buff *skb)
108111
skb->truesize += dlen - plen;
109112
__skb_put(skb, dlen - plen);
110113
skb_copy_to_linear_data(skb, scratch, dlen);
111-
err = ipch->nexthdr;
114+
err = nexthdr;
112115

113116
out_put_cpu:
114117
put_cpu();

0 commit comments

Comments
 (0)