xfrm4_beet_input(): fix an if()
Subsystems (3)
PATCH 1/1 xfrm4_beet_input(): fix an if()
A bug every C programmer makes at some point in time...
---3125760a05c6e97097882a810dc1c5342296aae9
net/ipv4/xfrm4_mode_beet.c +1 -1
@@ -102,7 +102,7 @@ static int xfrm4_beet_input(struct xfrm_state *x, struct sk_buff *skb)XFRM_MODE_SKB_CB (skb)->protocol = ph->nexthdr; -if (!pskb_may_pull (skb, phlen)); +if (!pskb_may_pull (skb, phlen)) goto out;__skb_pull (skb, phlen); }
Quoted 3 lines · Adrian Bunk
A bug every C programmer makes at some point in time...
Signed-off-by Adrian Bunk <[email protected]>
Good catch!
Thanks,
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.txtA message that is not in the archive (sent off-list or not yet received): [email protected]
Herbert Xu
maintainerRe: xfrm_input() and ->seq oddities
Quoted 5 lines · Al Viro
What's going on with XFRM_SKB_CB(skb)->seq? Almost all usersexpect it to be u32 (feeding it to
htonl()), exceptxfrm_input(). That one expects__be32in there - check what it does to seq and you'll see. Moreover, it updates the sucker in a way that makes sense only for__be32.
My bad.
Quoted 2 lines
a) are we just missing
ntohl()andhtonl()in obvious places
inxfrm_input()?
It's semantically correct. However, my mistake that I'm mixing the input sequence number which is network endian with the output sequence number which is host endian (and 64-bit).
Quoted 1 line
b) WTF is it declared as 64bit, anyway?
For extended sequence numbers which we'll support soon (I hope).
[IPSEC]: Fix bogus usage of u64 on input sequence number
Al Viro spotted a bogus use of u64 on the input sequence number which is big-endian. This patch fixes it by giving the input sequence number its own member in the xfrm_skb_cb structure.
Thanks,
Signature · 5 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
--include/net/xfrm.h +4 -1
@@ -508,7 +508,10 @@ struct xfrm_skb_cb { } header;/* Sequence number for replay protection. */ -u64 seq; +union { +u64 output; +__be32 input; + } seq; };#define XFRM_SKB_CB (__skb) ((struct xfrm_skb_cb *)&((__skb)->cb[0]))
net/ipv4/ah4.c +1 -1
@@ -96,7 +96,7 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb) ah->reserved =0 ; ah->spi = x->id.spi; - ah->seq_no =htonl (XFRM_SKB_CB (skb)->seq); + ah->seq_no =htonl (XFRM_SKB_CB (skb)->seq.output);spin_lock_bh (&x->lock); err =ah_mac_digest (ahp, skb, ah->auth_data);
net/ipv4/esp4.c +3 -2
@@ -199,7 +199,7 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb) } esph->spi = x->id.spi; - esph->seq_no =htonl (XFRM_SKB_CB (skb)->seq); + esph->seq_no =htonl (XFRM_SKB_CB (skb)->seq.output);sg_init_table (sg, nfrags); skb_to_sgvec(skb, sg,
@@ -210,7 +210,8 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)aead_givcrypt_set_callback (req,0 , esp_output_done, skb);aead_givcrypt_set_crypt (req, sg, sg, clen, iv);aead_givcrypt_set_assoc (req, asg,sizeof (*esph)); -aead_givcrypt_set_giv (req, esph->enc_data,XFRM_SKB_CB (skb)->seq); +aead_givcrypt_set_giv (req, esph->enc_data, +XFRM_SKB_CB (skb)->seq.output);ESP_SKB_CB (skb)->tmp = tmp; err =crypto_aead_givencrypt (req);
net/ipv6/ah6.c +1 -1
@@ -283,7 +283,7 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb) ah->reserved =0 ; ah->spi = x->id.spi; - ah->seq_no =htonl (XFRM_SKB_CB (skb)->seq); + ah->seq_no =htonl (XFRM_SKB_CB (skb)->seq.output);spin_lock_bh (&x->lock); err =ah_mac_digest (ahp, skb, ah->auth_data);
net/ipv6/esp6.c +3 -2
@@ -188,7 +188,7 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb) *skb_mac_header (skb) =IPPROTO_ESP ; esph->spi = x->id.spi; - esph->seq_no =htonl (XFRM_SKB_CB (skb)->seq); + esph->seq_no =htonl (XFRM_SKB_CB (skb)->seq.output);sg_init_table (sg, nfrags); skb_to_sgvec(skb, sg,
@@ -199,7 +199,8 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)aead_givcrypt_set_callback (req,0 , esp_output_done, skb);aead_givcrypt_set_crypt (req, sg, sg, clen, iv);aead_givcrypt_set_assoc (req, asg,sizeof (*esph)); -aead_givcrypt_set_giv (req, esph->enc_data,XFRM_SKB_CB (skb)->seq); +aead_givcrypt_set_giv (req, esph->enc_data, +XFRM_SKB_CB (skb)->seq.output);ESP_SKB_CB (skb)->tmp = tmp; err =crypto_aead_givencrypt (req);
net/xfrm/xfrm_input.c +2 -2
@@ -109,7 +109,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)if (encap_type <0 ) { async =1 ; x =xfrm_input_state (skb); - seq =XFRM_SKB_CB (skb)->seq; + seq =XFRM_SKB_CB (skb)->seq.input; goto resume; }
@@ -175,7 +175,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)spin_unlock (&x->lock); -XFRM_SKB_CB (skb)->seq = seq; +XFRM_SKB_CB (skb)->seq.input = seq; nexthdr = x->type->input (x, skb);
net/xfrm/xfrm_output.c +1 -1
@@ -62,7 +62,7 @@ static int xfrm_output_one(struct sk_buff *skb, int err) }if (x->type->flags &XFRM_TYPE_REPLAY_PROT ) { -XFRM_SKB_CB (skb)->seq = ++x->replay.oseq; +XFRM_SKB_CB (skb)->seq.output = ++x->replay.oseq;if (unlikely (x->replay.oseq ==0 )) {XFRM_INC_STATS (LINUX_MIB_XFRMOUTSTATESEQERROR ); x->replay.oseq--;
Re: xfrm_input() and ->seq oddities
Quoted 3 lines · Herbert Xu
Al Viro spotted a bogus use of u64 on the input sequence number which is big-endian. This patch fixes it by giving the input sequence number its own member in the
xfrm_skb_cbstructure.
This is still very odd... Where do you initialize ->seq.input? What guarantees that async call of xfrm_input() will be always preceded by at least one non-async one?
Herbert Xu
maintainerRe: xfrm_input() and ->seq oddities
Quoted 2 lines · Al Viro
This is still very odd... Where do you initialize ->seq.input? What
In xfrm_input.
Quoted 2 lines
guarantees that async call of
xfrm_input()will be always preceded by at least one non-async one?
OK I admit it isn't pretty. But the encap_type argument is reused to indicate async resumption. That is, if we enter with encap_type < 0, it means that we're resuming a previous operation and seq.input has therefore been set by the previous xfrm_input call.
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.txtRe: xfrm_input() and ->seq oddities
Quoted 6 lines · Herbert Xu
Quoted 2 lines · Al Viro
This is still very odd... Where do you initialize ->seq.input? What
In
xfrm_input.
Quoted 7 lines
Quoted 2 lines
guarantees that async call of
xfrm_input()will be always preceded by at least one non-async one?OK I admit it isn't pretty. But the
encap_typeargument is reused to indicate async resumption. That is, if we enter withencap_type< 0, it means that we're resuming a previous operation and seq.input has therefore been set by the previousxfrm_inputcall.
*Ouch*
So what you are saying is
* callers of xfrm_input_resume() are in callbacks that couldn't
have been set other than from esp_input()/esp6_input()
* these two could have only been called via ->type->input()
* ->type->input() is called from xfrm_input(), immediately after
having set ->seq.input, *or* from xfrm6_input_addr(). The former is safe.
* xfrm6_input_addr() calls ->type->input() of object it gets fromxfrm_state_lookup_byaddr(). The protocol number passed to the latter comes from xfrm6_input_addr() argument.
* the protocol numbers given to xfrm6_input_addr() by its callers
are IPPROTO_DSTOPTS and IPPROTO_ROUTING resp; ->input() instances in their xfrm_type do *not* set callbacks that could lead to xfrm_input_resume(), so we are safe.
IMO that at least deserves a comment near xfrm_input()... doe
Herbert Xu
maintainerRe: xfrm_input() and ->seq oddities
Quoted 14 lines · Al Viro
So what you are saying is
* callers ofxfrm_input_resume()are in callbacks that couldn't
have been set other than from esp_input()/esp6_input()
* these two could have only been called via ->type->input()
* ->type->input() is called fromxfrm_input(), immediately after
having set ->seq.input, *or* fromxfrm6_input_addr(). The former is safe.
*xfrm6_input_addr()calls ->type->input() of object it gets fromxfrm_state_lookup_byaddr(). The protocol number passed to the latter comes fromxfrm6_input_addr()argument.
* the protocol numbers given toxfrm6_input_addr()by its callers
areIPPROTO_DSTOPTSandIPPROTO_ROUTINGresp; ->input() instances in theirxfrm_typedo *not* set callbacks that could lead toxfrm_input_resume(), so we are safe.
This doesn't look so bad if you take out the xfrm6_input_addr call. And you can't blame that one on me :)
The xfrm6_input_addr function is really a parallel universe which has nothing to do with IPsec. It's used by Mobile IPv6 just because it happened to fit in the same schema.
In other words, IPsec transforms such as ESP cannot be called from xfrm6_input_addr and as such async resumption never occurs with xfrm6_input_addr.
Quoted 1 line
IMO that at least deserves a comment near
xfrm_input()...
Sure. There is already a comment about encap_type < 0 in there, but I think you'll probably be able to explain it much better than I can looking in from the outside so if you have a patch... :)
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.txtDavid Miller
maintainerRe: xfrm_input() and ->seq oddities
From: Herbert Xu <[email protected]>
Date: Mon, 4 Feb 2008 09:00:27 +1100
Quoted 6 lines · Al Viro
Quoted 1 line
IMO that at least deserves a comment near
xfrm_input()...Sure. There is already a comment about
encap_type< 0 in there, but I think you'll probably be able to explain it much better than I can looking in from the outside so if you have a patch... :)
Agreed on all counts ;-)
Re: xfrm_input() and ->seq oddities
In reply to Herbert XuFrom: Herbert Xu <[email protected]>
Date: Sun, 3 Feb 2008 11:20:19 +1100
Quoted 7 lines
[IPSEC]: Fix bogus usage of u64 on input sequence number
Al Viro spotted a bogus use of u64 on the input sequence number which is big-endian. This patch fixes it by giving the input sequence number its own member in the
xfrm_skb_cbstructure.Signed-off-by Herbert Xu <[email protected]>
Applied, thanks Herbert.
From: Herbert Xu <[email protected]>
Date: Sun, 3 Feb 2008 09:22:26 +1100
Quoted 8 lines · Adrian Bunk
Quoted 3 lines
A bug every C programmer makes at some point in time...
Signed-off-by Adrian Bunk <[email protected]>Good catch!
Acked-by Herbert Xu <[email protected]>
Applied.