2019-05-21 08:25:08

by Anirudh Gupta

[permalink] [raw]
Subject: [PATCH net] xfrm: Fix xfrm sel prefix length validation

Family of src/dst can be different from family of selector src/dst.
Use xfrm selector family to validate address prefix length,
while verifying new sa from userspace.

Validated patch with this command:
ip xfrm state add src 1.1.6.1 dst 1.1.6.2 proto esp spi 4260196 \
reqid 20004 mode tunnel aead "rfc4106(gcm(aes))" \
0x1111016400000000000000000000000044440001 128 \
sel src 1011:1:4::2/128 sel dst 1021:1:4::2/128 dev Port5

Fixes: 07bf7908950a ("xfrm: Validate address prefix lengths in the xfrm selector.")
Signed-off-by: Anirudh Gupta <[email protected]>
---
net/xfrm/xfrm_user.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index eb8d14389601..1d1fe2208ab5 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -150,6 +150,23 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,

err = -EINVAL;
switch (p->family) {
+ case AF_INET:
+ break;
+
+ case AF_INET6:
+#if IS_ENABLED(CONFIG_IPV6)
+ break;
+#else
+ err = -EAFNOSUPPORT;
+ goto out;
+#endif
+
+ default:
+ goto out;
+ }
+
+ err = -EINVAL;
+ switch (p->sel.family) {
case AF_INET:
if (p->sel.prefixlen_d > 32 || p->sel.prefixlen_s > 32)
goto out;
--
2.19.0



2019-05-21 12:24:15

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH net] xfrm: Fix xfrm sel prefix length validation

On Tue, May 21, 2019 at 01:52:47PM +0530, Anirudh Gupta wrote:
> Family of src/dst can be different from family of selector src/dst.
> Use xfrm selector family to validate address prefix length,
> while verifying new sa from userspace.
>
> Validated patch with this command:
> ip xfrm state add src 1.1.6.1 dst 1.1.6.2 proto esp spi 4260196 \
> reqid 20004 mode tunnel aead "rfc4106(gcm(aes))" \
> 0x1111016400000000000000000000000044440001 128 \
> sel src 1011:1:4::2/128 sel dst 1021:1:4::2/128 dev Port5
>
> Fixes: 07bf7908950a ("xfrm: Validate address prefix lengths in the xfrm selector.")
> Signed-off-by: Anirudh Gupta <[email protected]>
> ---
> net/xfrm/xfrm_user.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
> index eb8d14389601..1d1fe2208ab5 100644
> --- a/net/xfrm/xfrm_user.c
> +++ b/net/xfrm/xfrm_user.c
> @@ -150,6 +150,23 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
>
> err = -EINVAL;
> switch (p->family) {
> + case AF_INET:
> + break;
> +
> + case AF_INET6:
> +#if IS_ENABLED(CONFIG_IPV6)
> + break;
> +#else
> + err = -EAFNOSUPPORT;
> + goto out;
> +#endif
> +
> + default:
> + goto out;
> + }
> +
> + err = -EINVAL;

This is not needed because you already set it at the start.

Otherwise this looks good to me.

Thanks,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt