Skip to content

Commit 47dd693

Browse files
antonyantonygregkh
authored andcommitted
xfrm: state and policy should fail if XFRMA_IF_ID 0
[ Upstream commit 68ac0f3 ] 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 <antony.antony@secunet.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent db36904 commit 47dd693

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎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)
@@ -1353,8 +1358,13 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
13531358

13541359
mark = xfrm_mark_get(attrs, &m);
13551360

1356-
if (attrs[XFRMA_IF_ID])
1361+
if (attrs[XFRMA_IF_ID]) {
13571362
if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
1363+
if (!if_id) {
1364+
err = -EINVAL;
1365+
goto out_noput;
1366+
}
1367+
}
13581368

13591369
if (p->info.seq) {
13601370
x = xfrm_find_acq_byseq(net, mark, p->info.seq);
@@ -1667,8 +1677,13 @@ static struct xfrm_policy *xfrm_policy_construct(struct net *net, struct xfrm_us
16671677

16681678
xfrm_mark_get(attrs, &xp->mark);
16691679

1670-
if (attrs[XFRMA_IF_ID])
1680+
if (attrs[XFRMA_IF_ID]) {
16711681
xp->if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
1682+
if (!xp->if_id) {
1683+
err = -EINVAL;
1684+
goto error;
1685+
}
1686+
}
16721687

16731688
return xp;
16741689
error:

0 commit comments

Comments
 (0)