net/netfilter/nft_set_pipapo.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
From: Florian Westphal <fw@strlen.de>
commit 07ace0bbe03b3d8e85869af1dec5e4087b1d57b8 upstream
pipapo relies on kmalloc(0) returning ZERO_SIZE_PTR (i.e., not NULL
but pointer is invalid).
Rework this to not call slab allocator when we'd request a 0-byte
allocation.
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Mukul Sikka <mukul.sikka@broadcom.com>
Signed-off-by: Brennan Lamoreaux <brennan.lamoreaux@broadcom.com>
[Keerthana: In older stable branches (v6.6 and earlier), the allocation logic in
pipapo_clone() still relies on `src->rules` rather than `src->rules_alloc`
(introduced in v6.9 via 9f439bd6ef4f). Consequently, the previously
backported INT_MAX clamping check uses `src->rules`. This patch correctly
moves that `src->rules > (INT_MAX / ...)` check inside the new
`if (src->rules > 0)` block]
Signed-off-by: Keerthana K <keerthana.kalyanasundaram@broadcom.com>
---
net/netfilter/nft_set_pipapo.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c
index 863162c82330..2072c89a467d 100644
--- a/net/netfilter/nft_set_pipapo.c
+++ b/net/netfilter/nft_set_pipapo.c
@@ -525,6 +525,8 @@ static struct nft_pipapo_elem *pipapo_get(const struct net *net,
int i;
m = priv->clone;
+ if (m->bsize_max == 0)
+ return ret;
res_map = kmalloc_array(m->bsize_max, sizeof(*res_map), GFP_ATOMIC);
if (!res_map) {
@@ -1365,14 +1367,20 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)
src->bsize * sizeof(*dst->lt) *
src->groups * NFT_PIPAPO_BUCKETS(src->bb));
- if (src->rules > (INT_MAX / sizeof(*src->mt)))
- goto out_mt;
+ if (src->rules > 0) {
+ if (src->rules > (INT_MAX / sizeof(*src->mt)))
+ goto out_mt;
+
+ dst->mt = kvmalloc_array(src->rules, sizeof(*src->mt),
+ GFP_KERNEL);
+ if (!dst->mt)
+ goto out_mt;
- dst->mt = kvmalloc(src->rules * sizeof(*src->mt), GFP_KERNEL_ACCOUNT);
- if (!dst->mt)
- goto out_mt;
+ memcpy(dst->mt, src->mt, src->rules * sizeof(*src->mt));
+ } else {
+ dst->mt = NULL;
+ }
- memcpy(dst->mt, src->mt, src->rules * sizeof(*src->mt));
src++;
dst++;
}
--
2.43.7
On Mon, Apr 13, 2026 at 04:32:47AM +0000, Keerthana K wrote: > From: Florian Westphal <fw@strlen.de> > > commit 07ace0bbe03b3d8e85869af1dec5e4087b1d57b8 upstream > > pipapo relies on kmalloc(0) returning ZERO_SIZE_PTR (i.e., not NULL > but pointer is invalid). > > Rework this to not call slab allocator when we'd request a 0-byte > allocation. > > Reviewed-by: Stefano Brivio <sbrivio@redhat.com> > Signed-off-by: Florian Westphal <fw@strlen.de> > Signed-off-by: Mukul Sikka <mukul.sikka@broadcom.com> > Signed-off-by: Brennan Lamoreaux <brennan.lamoreaux@broadcom.com> > [Keerthana: In older stable branches (v6.6 and earlier), the allocation logic in > pipapo_clone() still relies on `src->rules` rather than `src->rules_alloc` > (introduced in v6.9 via 9f439bd6ef4f). Consequently, the previously > backported INT_MAX clamping check uses `src->rules`. This patch correctly > moves that `src->rules > (INT_MAX / ...)` check inside the new > `if (src->rules > 0)` block] > Signed-off-by: Keerthana K <keerthana.kalyanasundaram@broadcom.com> > --- > net/netfilter/nft_set_pipapo.c | 20 ++++++++++++++------ > 1 file changed, 14 insertions(+), 6 deletions(-) Does not apply to 5.15.y :(
© 2016 - 2026 Red Hat, Inc.