Skip to contentSkip to conversation

xfrm: count esp/ah header to lifetime

PATCH Applied [email protected] 2 participants 4 messages Feb 1, 2013 – Feb 4, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xfrm: count esp/ah header to lifetime

From: Li RongQing <[email protected]>

rfc4301 4.4.2 says:

(a) If byte count is used, then the implementation SHOULD count the number of bytes to which the IPsec cryptographic algorithm is applied. For ESP, this is the encryption algorithm (including Null encryption) and for AH, this is the authentication algorithm. This includes pad bytes, etc.

---
 net/xfrm/xfrm_input.c  |    4 +++-
 net/xfrm/xfrm_output.c |    8 +++++---
 2 files changed, 8 insertions(+), 4 deletions(-)
net/xfrm/xfrm_input.c +3 -1
index ab2bb42..da156e9 100644
@@ -114,6 +114,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 	unsigned int family;
 	int decaps = 0;
 	int async = 0;
+	int skb_len = 0;
 
 	/* A negative encap_type indicates async resumption. */
 	if (encap_type < 0) {
@@ -192,6 +193,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 		skb_dst_force(skb);
 
+		skb_len = skb->len;
 		nexthdr = x->type->input(x, skb);
 
 		if (nexthdr == -EINPROGRESS)
@@ -219,7 +221,7 @@ resume:
 
 		x->repl->advance(x, seq);
 
-		x->curlft.bytes += skb->len;
+		x->curlft.bytes += skb_len;
 		x->curlft.packets++;
 
 		spin_unlock(&x->lock);
net/xfrm/xfrm_output.c +5 -3
index 3670526..2c5aa8d 100644
@@ -79,9 +79,6 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
 			goto error;
 		}
 
-		x->curlft.bytes += skb->len;
-		x->curlft.packets++;
-
 		spin_unlock_bh(&x->lock);
 
 		skb_dst_force(skb);
@@ -90,6 +87,11 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
 		if (err == -EINPROGRESS)
 			goto out_exit;
 
+		spin_lock_bh(&x->lock);
+		x->curlft.bytes += skb->len;
+		x->curlft.packets++;
+		spin_unlock_bh(&x->lock);
+
 resume:
 		if (err) {
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEPROTOERROR);
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/2 xfrm: fix a unbalanced lock

From: Li RongQing <[email protected]>

---
 net/xfrm/xfrm_output.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_output.c +1 -1
index 2c5aa8d..e894ac6 100644
@@ -64,7 +64,7 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
 
 		if (unlikely(x->km.state != XFRM_STATE_VALID)) {
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEINVALID);
-			goto error_nolock;
+			goto error;
 		}
 
 		err = xfrm_state_check_expire(x);
Signature · 1 line
1.7.10.4
maintainer
#3 lore raw
In reply to [email protected]
Quoted 37 lines · On Fri, Feb 01, 2013 at 01:17:15PM +0800, [email protected] wrote:

From: Li RongQing <[email protected]>

rfc4301 4.4.2 says:

(a) If byte count is used, then the implementation SHOULD count the number of bytes to which the IPsec cryptographic algorithm is applied. For ESP, this is the encryption algorithm (including Null encryption) and for AH, this is the authentication algorithm. This includes pad bytes, etc.

---
 net/xfrm/xfrm_input.c  |    4 +++-
 net/xfrm/xfrm_output.c |    8 +++++---
 2 files changed, 8 insertions(+), 4 deletions(-)
net/xfrm/xfrm_input.c +2 -0
index ab2bb42..da156e9 100644
@@ -114,6 +114,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 	unsigned int family;
 	int decaps = 0;
 	int async = 0;
+	int skb_len = 0;
 
 	/* A negative encap_type indicates async resumption. */
 	if (encap_type < 0) {
@@ -192,6 +193,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 		skb_dst_force(skb);
 
+		skb_len = skb->len;
 		nexthdr = x->type->input(x, skb);
 
 		if (nexthdr == -EINPROGRESS)

net/xfrm/xfrm_input.c resume: · line 224

Quoted 5 lines
net/xfrm/xfrm_input.c +1 -1
@@ -219,7 +221,7 @@ resume:
 
 		x->repl->advance(x, seq);
 
-		x->curlft.bytes += skb->len;
+		x->curlft.bytes += skb_len;

Using a stack variable does not work with asynchronous ciphers. We would not count the lifebytes at all in this case.

Quoted 18 lines
net/xfrm/xfrm_input.c +0 -0
 		x->curlft.packets++;
 
 		spin_unlock(&x->lock);
net/xfrm/xfrm_output.c +0 -3
index 3670526..2c5aa8d 100644
@@ -79,9 +79,6 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
 			goto error;
 		}
 
-		x->curlft.bytes += skb->len;
-		x->curlft.packets++;
-
 		spin_unlock_bh(&x->lock);
 
 		skb_dst_force(skb);

net/xfrm/xfrm_output.c static int xfrm_output_one(struct sk_buff *skb, int err) · line 94

Quoted 8 lines
net/xfrm/xfrm_output.c +5 -0
@@ -90,6 +87,11 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
 		if (err == -EINPROGRESS)
 			goto out_exit;
 
+		spin_lock_bh(&x->lock);
+		x->curlft.bytes += skb->len;
+		x->curlft.packets++;
+		spin_unlock_bh(&x->lock);
+

This is certainly not the right place to do this. It is after the exit on asynchronous crypto and before the resume from asynchronous crypto, so again we would not count the lifebytes.

Quoted 5 lines
net/xfrm/xfrm_output.c +0 -0
 resume:
 		if (err) {
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEPROTOERROR);
Signature · 1 line
1.7.10.4