Skip to content

Commit 68ac0f3

Browse files
antonyantonyklassert
authored andcommitted
xfrm: state and policy should fail if XFRMA_IF_ID 0
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: 9f8550e ("xfrm: fix disable_xfrm sysctl when used on xfrm interfaces") Signed-off-by: Antony Antony <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 8dce439 commit 68ac0f3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

net/xfrm/xfrm_user.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,13 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
621621

622622
xfrm_smark_init(attrs, &x->props.smark);
623623

624-
if (attrs[XFRMA_IF_ID])
624+
if (attrs[XFRMA_IF_ID]) {
625625
x->if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
626+
if (!x->if_id) {
627+
err = -EINVAL;
628+
goto error;
629+
}
630+
}
626631

627632
err = __xfrm_init_state(x, false, attrs[XFRMA_OFFLOAD_DEV]);
628633
if (err)
@@ -1413,8 +1418,13 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
14131418

14141419
mark = xfrm_mark_get(attrs, &m);
14151420

1416-
if (attrs[XFRMA_IF_ID])
1421+
if (attrs[XFRMA_IF_ID]) {
14171422
if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
1423+
if (!if_id) {
1424+
err = -EINVAL;
1425+
goto out_noput;
1426+
}
1427+
}
14181428

14191429
if (p->info.seq) {
14201430
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
17271737

17281738
xfrm_mark_get(attrs, &xp->mark);
17291739

1730-
if (attrs[XFRMA_IF_ID])
1740+
if (attrs[XFRMA_IF_ID]) {
17311741
xp->if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
1742+
if (!xp->if_id) {
1743+
err = -EINVAL;
1744+
goto error;
1745+
}
1746+
}
17321747

17331748
return xp;
17341749
error:

0 commit comments

Comments
 (0)