]> git.baikalelectronics.ru Git - kernel.git/commitdiff
xfrm: state and policy should fail if XFRMA_IF_ID 0
authorAntony Antony <antony.antony@secunet.com>
Sun, 12 Dec 2021 10:35:00 +0000 (11:35 +0100)
committerSteffen Klassert <steffen.klassert@secunet.com>
Fri, 17 Dec 2021 06:17:35 +0000 (07:17 +0100)
xfrm ineterface does not allow xfrm if_id = 0
fail to create or update xfrm state and policy.

With this commit:
 ip xfrm policy add src 192.0.2.1 dst 192.0.2.2 dir out if_id 0
 RTNETLINK answers: Invalid argument

 ip xfrm state add src 192.0.2.1 dst 192.0.2.2 proto esp spi 1 \
            reqid 1 mode tunnel aead 'rfc4106(gcm(aes))' \
            0x1111111111111111111111111111111111111111 96 if_id 0
 RTNETLINK answers: Invalid argument

v1->v2 change:
 - add Fixes: tag

Fixes: 23a4e32a6468 ("xfrm: fix disable_xfrm sysctl when used on xfrm interfaces")
Signed-off-by: Antony Antony <antony.antony@secunet.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_user.c

index 0a2d2bae28316f4a43cec96c3e698b42f6b6864b..b571892fe10f5a1e0216af39fb89d0833ec1d32e 100644 (file)
@@ -621,8 +621,13 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
 
        xfrm_smark_init(attrs, &x->props.smark);
 
-       if (attrs[XFRMA_IF_ID])
+       if (attrs[XFRMA_IF_ID]) {
                x->if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
+               if (!x->if_id) {
+                       err = -EINVAL;
+                       goto error;
+               }
+       }
 
        err = __xfrm_init_state(x, false, attrs[XFRMA_OFFLOAD_DEV]);
        if (err)
@@ -1413,8 +1418,13 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
 
        mark = xfrm_mark_get(attrs, &m);
 
-       if (attrs[XFRMA_IF_ID])
+       if (attrs[XFRMA_IF_ID]) {
                if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
+               if (!if_id) {
+                       err = -EINVAL;
+                       goto out_noput;
+               }
+       }
 
        if (p->info.seq) {
                x = xfrm_find_acq_byseq(net, mark, p->info.seq);
@@ -1727,8 +1737,13 @@ static struct xfrm_policy *xfrm_policy_construct(struct net *net, struct xfrm_us
 
        xfrm_mark_get(attrs, &xp->mark);
 
-       if (attrs[XFRMA_IF_ID])
+       if (attrs[XFRMA_IF_ID]) {
                xp->if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
+               if (!xp->if_id) {
+                       err = -EINVAL;
+                       goto error;
+               }
+       }
 
        return xp;
  error: