xfrm: Return error on unknown encap_type in init_state
authorHerbert Xu <herbert@gondor.apana.org.au>
Fri, 5 Jan 2018 11:12:32 +0000 (22:12 +1100)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 3 Mar 2018 15:50:56 +0000 (15:50 +0000)
commitf5df4e3a6342a9686a2d08820394b2aad3eed737
treee2dadb5c567b8d7fff8216b47b1d1abe6081c5a6
parent24ff3690834d18f20bd6ee06d0c178f9c5c3ff8e
xfrm: Return error on unknown encap_type in init_state

commit bcfd09f7837f5240c30fd2f52ee7293516641faa upstream.

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: 38320c70d282 ("[IPSEC]: Use crypto_aead and authenc in ESP")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
net/ipv4/esp4.c
net/ipv6/esp6.c