Skip to content

Commit 3ce67e3

Browse files
committed
netfilter: nf_tables: do not allow mismatch field size and set key length
The set description provides the size of each field in the set whose sum should not mismatch the set key length, bail out otherwise. I did not manage to crash nft_set_pipapo with mismatch fields and set key length so far, but this is UB which must be disallowed. Fixes: f3a2181 ("netfilter: nf_tables: Support for sets with multiple ranged fields") Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent b1db244 commit 3ce67e3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4813,8 +4813,8 @@ static int nft_set_desc_concat_parse(const struct nlattr *attr,
48134813
static int nft_set_desc_concat(struct nft_set_desc *desc,
48144814
const struct nlattr *nla)
48154815
{
4816+
u32 num_regs = 0, key_num_regs = 0;
48164817
struct nlattr *attr;
4817-
u32 num_regs = 0;
48184818
int rem, err, i;
48194819

48204820
nla_for_each_nested(attr, nla, rem) {
@@ -4829,6 +4829,10 @@ static int nft_set_desc_concat(struct nft_set_desc *desc,
48294829
for (i = 0; i < desc->field_count; i++)
48304830
num_regs += DIV_ROUND_UP(desc->field_len[i], sizeof(u32));
48314831

4832+
key_num_regs = DIV_ROUND_UP(desc->klen, sizeof(u32));
4833+
if (key_num_regs != num_regs)
4834+
return -EINVAL;
4835+
48324836
if (num_regs > NFT_REG32_COUNT)
48334837
return -E2BIG;
48344838

0 commit comments

Comments
 (0)