Skip to content

Commit c88f3e3

Browse files
ummakynesgregkh
authored andcommitted
netfilter: nf_tables: sanitize nft_set_desc_concat_parse()
commit fecf31e upstream. Add several sanity checks for nft_set_desc_concat_parse(): - validate desc->field_count not larger than desc->field_len array. - field length cannot be larger than desc->field_len (ie. U8_MAX) - total length of the concatenation cannot be larger than register array. Joint work with Florian Westphal. Fixes: f3a2181 ("netfilter: nf_tables: Support for sets with multiple ranged fields") Reported-by: <[email protected]> Reviewed-by: Stefano Brivio <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 67429e6 commit c88f3e3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4167,6 +4167,9 @@ static int nft_set_desc_concat_parse(const struct nlattr *attr,
41674167
u32 len;
41684168
int err;
41694169

4170+
if (desc->field_count >= ARRAY_SIZE(desc->field_len))
4171+
return -E2BIG;
4172+
41704173
err = nla_parse_nested_deprecated(tb, NFTA_SET_FIELD_MAX, attr,
41714174
nft_concat_policy, NULL);
41724175
if (err < 0)
@@ -4176,9 +4179,8 @@ static int nft_set_desc_concat_parse(const struct nlattr *attr,
41764179
return -EINVAL;
41774180

41784181
len = ntohl(nla_get_be32(tb[NFTA_SET_FIELD_LEN]));
4179-
4180-
if (len * BITS_PER_BYTE / 32 > NFT_REG32_COUNT)
4181-
return -E2BIG;
4182+
if (!len || len > U8_MAX)
4183+
return -EINVAL;
41824184

41834185
desc->field_len[desc->field_count++] = len;
41844186

@@ -4189,7 +4191,8 @@ static int nft_set_desc_concat(struct nft_set_desc *desc,
41894191
const struct nlattr *nla)
41904192
{
41914193
struct nlattr *attr;
4192-
int rem, err;
4194+
u32 num_regs = 0;
4195+
int rem, err, i;
41934196

41944197
nla_for_each_nested(attr, nla, rem) {
41954198
if (nla_type(attr) != NFTA_LIST_ELEM)
@@ -4200,6 +4203,12 @@ static int nft_set_desc_concat(struct nft_set_desc *desc,
42004203
return err;
42014204
}
42024205

4206+
for (i = 0; i < desc->field_count; i++)
4207+
num_regs += DIV_ROUND_UP(desc->field_len[i], sizeof(u32));
4208+
4209+
if (num_regs > NFT_REG32_COUNT)
4210+
return -E2BIG;
4211+
42034212
return 0;
42044213
}
42054214

0 commit comments

Comments
 (0)