Commit 257a4b01 authored by Herbert Xu's avatar Herbert Xu Committed by Steffen Klassert

xfrm: Forbid state updates from changing encap type

Currently we allow state updates to competely replace the contents
of x->encap.  This is bad because on the user side ESP only sets up
header lengths depending on encap_type once when the state is first
created.  This could result in the header lengths getting out of
sync with the actual state configuration.

In practice key managers will never do a state update to change the
encapsulation type.  Only the port numbers need to be changed as the
peer NAT entry is updated.

Therefore this patch adds a check in xfrm_state_update to forbid
any changes to the encap_type.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
parent 2758b3e3
...@@ -1534,8 +1534,12 @@ int xfrm_state_update(struct xfrm_state *x) ...@@ -1534,8 +1534,12 @@ int xfrm_state_update(struct xfrm_state *x)
err = -EINVAL; err = -EINVAL;
spin_lock_bh(&x1->lock); spin_lock_bh(&x1->lock);
if (likely(x1->km.state == XFRM_STATE_VALID)) { if (likely(x1->km.state == XFRM_STATE_VALID)) {
if (x->encap && x1->encap) if (x->encap && x1->encap &&
x->encap->encap_type == x1->encap->encap_type)
memcpy(x1->encap, x->encap, sizeof(*x1->encap)); memcpy(x1->encap, x->encap, sizeof(*x1->encap));
else if (x->encap || x1->encap)
goto fail;
if (x->coaddr && x1->coaddr) { if (x->coaddr && x1->coaddr) {
memcpy(x1->coaddr, x->coaddr, sizeof(*x1->coaddr)); memcpy(x1->coaddr, x->coaddr, sizeof(*x1->coaddr));
} }
...@@ -1552,6 +1556,8 @@ int xfrm_state_update(struct xfrm_state *x) ...@@ -1552,6 +1556,8 @@ int xfrm_state_update(struct xfrm_state *x)
x->km.state = XFRM_STATE_DEAD; x->km.state = XFRM_STATE_DEAD;
__xfrm_state_put(x); __xfrm_state_put(x);
} }
fail:
spin_unlock_bh(&x1->lock); spin_unlock_bh(&x1->lock);
xfrm_state_put(x1); xfrm_state_put(x1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment