Skip to content

Commit 5516d3f

Browse files
mkubecekJiri Slaby
authored andcommitted
xfrm: prevent ipcomp scratch buffer race condition
commit 12e3594 upstream. In ipcomp_compress(), sortirq is enabled too early, allowing the per-cpu scratch buffer to be rewritten by ipcomp_decompress() (called on the same CPU in softirq context) between populating the buffer and copying the compressed data to the skb. v2: as pointed out by Steffen Klassert, if we also move the local_bh_disable() before reading the per-cpu pointers, we can get rid of get_cpu()/put_cpu(). v3: removed ipcomp_decompress part (as explained by Herbert Xu, it cannot be called from process context), get rid of cpu variable (thanks to Eric Dumazet) Signed-off-by: Michal Kubecek <mkubecek@suse.cz> Reviewed-by: Eric Dumazet <edumazet@google.com> Acked-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
1 parent 03cb0a7 commit 5516d3f

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

‎net/xfrm/xfrm_ipcomp.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
141141
const int plen = skb->len;
142142
int dlen = IPCOMP_SCRATCH_SIZE;
143143
u8 *start = skb->data;
144-
const int cpu = get_cpu();
145-
u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu);
146-
struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
144+
struct crypto_comp *tfm;
145+
u8 *scratch;
147146
int err;
148147

149148
local_bh_disable();
149+
scratch = *this_cpu_ptr(ipcomp_scratches);
150+
tfm = *this_cpu_ptr(ipcd->tfms);
150151
err = crypto_comp_compress(tfm, start, plen, scratch, &dlen);
151-
local_bh_enable();
152152
if (err)
153153
goto out;
154154

@@ -158,13 +158,13 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
158158
}
159159

160160
memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
161-
put_cpu();
161+
local_bh_enable();
162162

163163
pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
164164
return 0;
165165

166166
out:
167-
put_cpu();
167+
local_bh_enable();
168168
return err;
169169
}
170170

0 commit comments

Comments
 (0)