提交 bcfd09f7 编写于 作者: H Herbert Xu 提交者: Steffen Klassert

xfrm: Return error on unknown encap_type in init_state

Currently esp will happily create an xfrm state with an unknown
encap type for IPv4, without setting the necessary state parameters.
This patch fixes it by returning -EINVAL.

There is a similar problem in IPv6 where if the mode is unknown
we will skip initialisation while returning zero.  However, this
is harmless as the mode has already been checked further up the
stack.  This patch removes this anomaly by aligning the IPv6
behaviour with IPv4 and treating unknown modes (which cannot
actually happen) as transport mode.

Fixes: 38320c70 ("[IPSEC]: Use crypto_aead and authenc in ESP")
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
上级 d16b46e4
...@@ -981,6 +981,7 @@ static int esp_init_state(struct xfrm_state *x) ...@@ -981,6 +981,7 @@ static int esp_init_state(struct xfrm_state *x)
switch (encap->encap_type) { switch (encap->encap_type) {
default: default:
err = -EINVAL;
goto error; goto error;
case UDP_ENCAP_ESPINUDP: case UDP_ENCAP_ESPINUDP:
x->props.header_len += sizeof(struct udphdr); x->props.header_len += sizeof(struct udphdr);
......
...@@ -890,13 +890,12 @@ static int esp6_init_state(struct xfrm_state *x) ...@@ -890,13 +890,12 @@ static int esp6_init_state(struct xfrm_state *x)
x->props.header_len += IPV4_BEET_PHMAXLEN + x->props.header_len += IPV4_BEET_PHMAXLEN +
(sizeof(struct ipv6hdr) - sizeof(struct iphdr)); (sizeof(struct ipv6hdr) - sizeof(struct iphdr));
break; break;
default:
case XFRM_MODE_TRANSPORT: case XFRM_MODE_TRANSPORT:
break; break;
case XFRM_MODE_TUNNEL: case XFRM_MODE_TUNNEL:
x->props.header_len += sizeof(struct ipv6hdr); x->props.header_len += sizeof(struct ipv6hdr);
break; break;
default:
goto error;
} }
align = ALIGN(crypto_aead_blocksize(aead), 4); align = ALIGN(crypto_aead_blocksize(aead), 4);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册