netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH ipsec] xfrm: prevent ipcomp scratch buffer race condition
@ 2013-10-14 16:03 Michal Kubecek
  2013-10-15  8:33 ` Steffen Klassert
  2013-10-16 12:32 ` [PATCH ipsec] " Herbert Xu
  0 siblings, 2 replies; 19+ messages in thread
From: Michal Kubecek @ 2013-10-14 16:03 UTC (permalink / raw)
  To: Steffen Klassert; +Cc: Herbert Xu, David S. Miller, netdev

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.

Add similar protection into ipcomp_decompress() as it can be
called from process context as well (even if such scenario seems
a bit artificial).

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 net/xfrm/xfrm_ipcomp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index 2906d52..96946fb 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -48,9 +48,11 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
 	const int cpu = get_cpu();
 	u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu);
 	struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
-	int err = crypto_comp_decompress(tfm, start, plen, scratch, &dlen);
+	int err;
 	int len;
 
+	local_bh_disable();
+	err = crypto_comp_decompress(tfm, start, plen, scratch, &dlen);
 	if (err)
 		goto out;
 
@@ -103,6 +105,7 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
 	err = 0;
 
 out:
+	local_bh_enable();
 	put_cpu();
 	return err;
 }
@@ -148,7 +151,6 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
 
 	local_bh_disable();
 	err = crypto_comp_compress(tfm, start, plen, scratch, &dlen);
-	local_bh_enable();
 	if (err)
 		goto out;
 
@@ -158,12 +160,14 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
 	}
 
 	memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
+	local_bh_enable();
 	put_cpu();
 
 	pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
 	return 0;
 
 out:
+	local_bh_enable();
 	put_cpu();
 	return err;
 }
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2013-10-21 14:48 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-14 16:03 [PATCH ipsec] xfrm: prevent ipcomp scratch buffer race condition Michal Kubecek
2013-10-15  8:33 ` Steffen Klassert
2013-10-15  8:59   ` Fan Du
2013-10-15  9:46     ` Steffen Klassert
2013-10-15 20:55   ` Michal Kubecek
2013-10-15 21:40   ` [PATCH ipsec v2] " Michal Kubecek
2013-10-15 22:44     ` Eric Dumazet
2013-10-16 12:32 ` [PATCH ipsec] " Herbert Xu
2013-10-17  9:55   ` Steffen Klassert
2013-10-17 13:07     ` [PATCH ipsec v3] " Michal Kubecek
2013-10-17 13:38       ` Eric Dumazet
2013-10-17 13:39         ` Herbert Xu
2013-10-18  9:25       ` Steffen Klassert
2013-10-18 10:54         ` [PATCH ipsec-next] xfrm: use vmalloc_node() for percpu scratches Eric Dumazet
2013-10-18 12:46           ` Herbert Xu
2013-10-21 14:48           ` Steffen Klassert
2013-10-17 11:01   ` [PATCH ipsec] xfrm: prevent ipcomp scratch buffer race condition Michal Kubecek
2013-10-17 11:04     ` Herbert Xu
2013-10-17 13:13       ` Michal Kubecek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).