Skip to content

Commit 88cccd9

Browse files
committed
netfilter: nf_tables: NFTA_SET_ELEM_KEY_END requires concat and interval flags
If the NFT_SET_CONCAT|NFT_SET_INTERVAL flags are set on, then the netlink attribute NFTA_SET_ELEM_KEY_END must be specified. Otherwise, NFTA_SET_ELEM_KEY_END should not be present. For catch-all element, NFTA_SET_ELEM_KEY_END should not be present. The NFT_SET_ELEM_INTERVAL_END is never used with this set flags combination. Fixes: 7b225d0 ("netfilter: nf_tables: add NFTA_SET_ELEM_KEY_END attribute") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 5a2f3dc commit 88cccd9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5844,6 +5844,24 @@ static void nft_setelem_remove(const struct net *net,
58445844
set->ops->remove(net, set, elem);
58455845
}
58465846

5847+
static bool nft_setelem_valid_key_end(const struct nft_set *set,
5848+
struct nlattr **nla, u32 flags)
5849+
{
5850+
if ((set->flags & (NFT_SET_CONCAT | NFT_SET_INTERVAL)) ==
5851+
(NFT_SET_CONCAT | NFT_SET_INTERVAL)) {
5852+
if (flags & NFT_SET_ELEM_INTERVAL_END)
5853+
return false;
5854+
if (!nla[NFTA_SET_ELEM_KEY_END] &&
5855+
!(flags & NFT_SET_ELEM_CATCHALL))
5856+
return false;
5857+
} else {
5858+
if (nla[NFTA_SET_ELEM_KEY_END])
5859+
return false;
5860+
}
5861+
5862+
return true;
5863+
}
5864+
58475865
static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
58485866
const struct nlattr *attr, u32 nlmsg_flags)
58495867
{
@@ -5903,6 +5921,9 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
59035921
return -EINVAL;
59045922
}
59055923

5924+
if (!nft_setelem_valid_key_end(set, nla, flags))
5925+
return -EINVAL;
5926+
59065927
if ((flags & NFT_SET_ELEM_INTERVAL_END) &&
59075928
(nla[NFTA_SET_ELEM_DATA] ||
59085929
nla[NFTA_SET_ELEM_OBJREF] ||
@@ -6333,6 +6354,9 @@ static int nft_del_setelem(struct nft_ctx *ctx, struct nft_set *set,
63336354
if (!nla[NFTA_SET_ELEM_KEY] && !(flags & NFT_SET_ELEM_CATCHALL))
63346355
return -EINVAL;
63356356

6357+
if (!nft_setelem_valid_key_end(set, nla, flags))
6358+
return -EINVAL;
6359+
63366360
nft_set_ext_prepare(&tmpl);
63376361

63386362
if (flags != 0) {

0 commit comments

Comments
 (0)