Skip to contentSkip to conversation

: Do xfrm_state_check_space before encapsulation

IPSEC Applied Herbert Xu 3 participants 3 messages Dec 19, 2007 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Herbert Xu

author maintainer
#1 lore raw
Quoted 5 lines · Kazunori MIYAZAWA
Dec 19 11:31:44 hawaii kernel: ip6_rcv_finish: head=f7505000(**)
Dec 19 11:31:44 hawaii kernel: ip6_rcv_finish: data=f7505020(**)
Dec 19 11:31:44 hawaii kernel: xfrm6_tunnel_output: head=f7505000
Dec 19 11:31:44 hawaii kernel: xfrm6_tunnel_output: data=f7505020

Sorry I introduced this bug when I moved the encapsulation output function to the top of the loop. Here's the fix.

[IPSEC]: Do xfrm_state_check_space before encapsulation

While merging the IPsec output path I moved the encapsulation output operation to the top of the loop so that it sits outside of the locked section. Unfortunately in doing so it now sits in front of the space check as well which could be a fatal error.

This patch rearranges the calls so that the space check happens as the thing on the output path.

This patch also fixes an incorrect goto should the encapsulation output fail.

Thanks to Kazunori MIYAZAWA for finding this bug.

net/xfrm/xfrm_output.c +6 -12
index 3c277a4..26fa0cb 100644
@@ -33,16 +33,6 @@ static int xfrm_state_check_space(struct xfrm_state *x, struct sk_buff *skb)
 	return 0;
 }
 
-static int xfrm_state_check(struct xfrm_state *x, struct sk_buff *skb)
-{
-	int err = xfrm_state_check_expire(x);
-	if (err < 0)
-		goto err;
-	err = xfrm_state_check_space(x, skb);
-err:
-	return err;
-}
-
 static int xfrm_output_one(struct sk_buff *skb, int err)
 {
 	struct dst_entry *dst = skb->dst;
@@ -52,12 +42,16 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
 		goto resume;
 
 	do {
+		err = xfrm_state_check_space(x, skb);
+		if (err)
+			goto error_nolock;
+
 		err = x->outer_mode->output(x, skb);
 		if (err)
-			goto error;
+			goto error_nolock;
 
 		spin_lock_bh(&x->lock);
-		err = xfrm_state_check(x, skb);
+		err = xfrm_state_check_expire(x);
 		if (err)
 			goto error;
 

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer Applied
#2 lore raw

From: Herbert Xu <[email protected]>
Date: Wed, 19 Dec 2007 14:12:10 +0800

Quoted 10 lines

[IPSEC]: Do xfrm_state_check_space before encapsulation

While merging the IPsec output path I moved the encapsulation output operation to the top of the loop so that it sits outside of the locked section. Unfortunately in doing so it now sits in front of the space check as well which could be a fatal error.

This patch rearranges the calls so that the space check happens as the thing on the output path.

Quoted 6 lines

This patch also fixes an incorrect goto should the encapsulation output fail.

Thanks to Kazunori MIYAZAWA for finding this bug.

Applied, thanks Herbert.

#3 lore raw

Re: (usagi-core 34069) Re: [IPSEC]: Do xfrm_state_check_space before encapsulation

Quoted 13 lines · David Miller

From: Herbert Xu <[email protected]>
Date: Wed, 19 Dec 2007 14:12:10 +0800

Quoted 10 lines

[IPSEC]: Do xfrm_state_check_space before encapsulation

While merging the IPsec output path I moved the encapsulation output operation to the top of the loop so that it sits outside of the locked section. Unfortunately in doing so it now sits in front of the space check as well which could be a fatal error.

This patch rearranges the calls so that the space check happens as the thing on the output path.

Quoted 10 lines
Quoted 6 lines

This patch also fixes an incorrect goto should the encapsulation output fail.

Thanks to Kazunori MIYAZAWA for finding this bug.

Applied, thanks Herbert.

Thank you for your quick response :-)

--
Kazunori Miyazawa