Skip to contentSkip to conversation

netfilter: nft_set_pipapo: reject mismatched sum of field_len with key length

PATCH Superseded Pablo Neira Ayuso 2 participants 3 messages Jan 27, 2025 – Jan 28, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nft_set_pipapo: reject mismatched sum of field_len with key length

The field length description provides the length of each separated key fields in the concatenation. The set key length provides the total size of the key aligned to 32-bits for the pipapo set backend. Reject with EINVAL if the field length description and set key length provided by userspace are inconsistent.

Fixes 3c4287f62044 ("nf_tables: Add set type for arbitrary concatenation of ranges")
---
 net/netfilter/nft_set_pipapo.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/netfilter/nft_set_pipapo.c +7 -0
index 7be342b495f5..3b1a53e68989 100644
@@ -2235,6 +2235,7 @@ static int nft_pipapo_init(const struct nft_set *set,
 	struct nft_pipapo_match *m;
 	struct nft_pipapo_field *f;
 	int err, i, field_count;
+	unsigned int len = 0;
 
 	BUILD_BUG_ON(offsetof(struct nft_pipapo_elem, priv) != 0);
 
@@ -2246,6 +2247,12 @@ static int nft_pipapo_init(const struct nft_set *set,
 	if (field_count > NFT_PIPAPO_MAX_FIELDS)
 		return -EINVAL;
 
+	for (i = 0; i < field_count; i++)
+		len += round_up(desc->field_len[i], sizeof(u32));
+
+	if (len != set->klen)
+		return -EINVAL;
+
 	m = kmalloc(struct_size(m, f, field_count), GFP_KERNEL);
 	if (!m)
 		return -ENOMEM;
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 25 lines · Pablo Neira Ayuso

The field length description provides the length of each separated key fields in the concatenation. The set key length provides the total size of the key aligned to 32-bits for the pipapo set backend. Reject with EINVAL if the field length description and set key length provided by userspace are inconsistent.

Fixes 3c4287f62044 ("nf_tables: Add set type for arbitrary concatenation of ranges")
---
 net/netfilter/nft_set_pipapo.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/netfilter/nft_set_pipapo.c +1 -0
index 7be342b495f5..3b1a53e68989 100644
@@ -2235,6 +2235,7 @@ static int nft_pipapo_init(const struct nft_set *set,
 	struct nft_pipapo_match *m;
 	struct nft_pipapo_field *f;
 	int err, i, field_count;
+	unsigned int len = 0;
 
 	BUILD_BUG_ON(offsetof(struct nft_pipapo_elem, priv) != 0);
 

net/netfilter/nft_set_pipapo.c static int nft_pipapo_init(const struct nft_set *set, · line 2255

Quoted 9 lines
net/netfilter/nft_set_pipapo.c +6 -0
@@ -2246,6 +2247,12 @@ static int nft_pipapo_init(const struct nft_set *set,
 	if (field_count > NFT_PIPAPO_MAX_FIELDS)
 		return -EINVAL;
 
+	for (i = 0; i < field_count; i++)
+		len += round_up(desc->field_len[i], sizeof(u32));
+
+	if (len != set->klen)
+		return -EINVAL;
+

I fail to grasp why nft_set_desc_concat() doesn't catch it:

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

        key_num_regs = DIV_ROUND_UP(desc->klen, sizeof(u32));
        if (key_num_regs != num_regs);	----> here....
                return -EINVAL;
author maintainer
#2 lore raw
Quoted 38 lines · Florian Westphal
Quoted 25 lines · Pablo Neira Ayuso

The field length description provides the length of each separated key fields in the concatenation. The set key length provides the total size of the key aligned to 32-bits for the pipapo set backend. Reject with EINVAL if the field length description and set key length provided by userspace are inconsistent.

Fixes 3c4287f62044 ("nf_tables: Add set type for arbitrary concatenation of ranges")
---
 net/netfilter/nft_set_pipapo.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/netfilter/nft_set_pipapo.c +1 -0
index 7be342b495f5..3b1a53e68989 100644
@@ -2235,6 +2235,7 @@ static int nft_pipapo_init(const struct nft_set *set,
 	struct nft_pipapo_match *m;
 	struct nft_pipapo_field *f;
 	int err, i, field_count;
+	unsigned int len = 0;
 
 	BUILD_BUG_ON(offsetof(struct nft_pipapo_elem, priv) != 0);
 

net/netfilter/nft_set_pipapo.c static int nft_pipapo_init(const struct nft_set *set, · line 2255

Quoted 9 lines
net/netfilter/nft_set_pipapo.c +6 -0
@@ -2246,6 +2247,12 @@ static int nft_pipapo_init(const struct nft_set *set,
 	if (field_count > NFT_PIPAPO_MAX_FIELDS)
 		return -EINVAL;
 
+	for (i = 0; i < field_count; i++)
+		len += round_up(desc->field_len[i], sizeof(u32));
+
+	if (len != set->klen)
+		return -EINVAL;
+

I fail to grasp why nft_set_desc_concat() doesn't catch it:

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

        key_num_regs = DIV_ROUND_UP(desc->klen, sizeof(u32));
        if (key_num_regs != num_regs);	----> here....
                return -EINVAL;

This check is loose, I will post a v2 fixing up nft_set_desc_concat().

Thanks.