Skip to content

Commit

Permalink
netfilter: nf_tables: sanitize nft_set_desc_concat_parse()
Browse files Browse the repository at this point in the history
CVE-2022-1972

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: <zhangziming.zzm@antgroup.com>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
(cherry picked from commit fecf31e net.git)
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Acked-by: Andrea Righi <andrea.righi@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
  • Loading branch information
Pablo Neira Ayuso authored and Thadeu Lima de Souza Cascardo committed Jun 3, 2022
1 parent b9b7e78 commit 3776819
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -4151,6 +4151,9 @@ static int nft_set_desc_concat_parse(const struct nlattr *attr,
u32 len;
int err;

if (desc->field_count >= ARRAY_SIZE(desc->field_len))
return -E2BIG;

err = nla_parse_nested_deprecated(tb, NFTA_SET_FIELD_MAX, attr,
nft_concat_policy, NULL);
if (err < 0)
Expand All @@ -4160,9 +4163,8 @@ static int nft_set_desc_concat_parse(const struct nlattr *attr,
return -EINVAL;

len = ntohl(nla_get_be32(tb[NFTA_SET_FIELD_LEN]));

if (len * BITS_PER_BYTE / 32 > NFT_REG32_COUNT)
return -E2BIG;
if (!len || len > U8_MAX)
return -EINVAL;

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

Expand All @@ -4173,7 +4175,8 @@ static int nft_set_desc_concat(struct nft_set_desc *desc,
const struct nlattr *nla)
{
struct nlattr *attr;
int rem, err;
u32 num_regs = 0;
int rem, err, i;

nla_for_each_nested(attr, nla, rem) {
if (nla_type(attr) != NFTA_LIST_ELEM)
Expand All @@ -4184,6 +4187,12 @@ static int nft_set_desc_concat(struct nft_set_desc *desc,
return err;
}

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

if (num_regs > NFT_REG32_COUNT)
return -E2BIG;

return 0;
}

Expand Down

0 comments on commit 3776819

Please sign in to comment.