Skip to content

Commit 1b9335a

Browse files
committed
netfilter: nf_tables: reject mismatching sum of field_len with set key length
The field length description provides the length of each separated key field in the concatenation, each field gets rounded up to 32-bits to calculate the pipapo rule width from pipapo_init(). The set key length provides the total size of the key aligned to 32-bits. Register-based arithmetics still allows for combining mismatching set key length and field length description, eg. set key length 10 and field description [ 5, 4 ] leading to pipapo width of 12. Cc: [email protected] Fixes: 3ce67e3 ("netfilter: nf_tables: do not allow mismatch field size and set key length") Reported-by: Noam Rathaus <[email protected]> Reviewed-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 0a5b8ff commit 1b9335a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5065,7 +5065,7 @@ static int nft_set_desc_concat_parse(const struct nlattr *attr,
50655065
static int nft_set_desc_concat(struct nft_set_desc *desc,
50665066
const struct nlattr *nla)
50675067
{
5068-
u32 num_regs = 0, key_num_regs = 0;
5068+
u32 len = 0, num_regs;
50695069
struct nlattr *attr;
50705070
int rem, err, i;
50715071

@@ -5079,12 +5079,12 @@ static int nft_set_desc_concat(struct nft_set_desc *desc,
50795079
}
50805080

50815081
for (i = 0; i < desc->field_count; i++)
5082-
num_regs += DIV_ROUND_UP(desc->field_len[i], sizeof(u32));
5082+
len += round_up(desc->field_len[i], sizeof(u32));
50835083

5084-
key_num_regs = DIV_ROUND_UP(desc->klen, sizeof(u32));
5085-
if (key_num_regs != num_regs)
5084+
if (len != desc->klen)
50865085
return -EINVAL;
50875086

5087+
num_regs = DIV_ROUND_UP(desc->klen, sizeof(u32));
50885088
if (num_regs > NFT_REG32_COUNT)
50895089
return -E2BIG;
50905090

0 commit comments

Comments
 (0)