From: Florian Westphal <fw@strlen.de>
To: <netdev@vger.kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
<netfilter-devel@vger.kernel.org>,
Stefano Brivio <sbrivio@redhat.com>
Subject: [PATCH net-next 07/12] netfilter: nft_set_pipapo: do not rely on ZERO_SIZE_PTR
Date: Wed, 21 Feb 2024 12:26:09 +0100 [thread overview]
Message-ID: <20240221112637.5396-8-fw@strlen.de> (raw)
In-Reply-To: <20240221112637.5396-1-fw@strlen.de>
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>
---
net/netfilter/nft_set_pipapo.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c
index dedb17a4e07c..625c06b8bc39 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) {
@@ -1367,11 +1369,17 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)
src->bsize * sizeof(*dst->lt) *
src->groups * NFT_PIPAPO_BUCKETS(src->bb));
- dst->mt = kvmalloc(src->rules * sizeof(*src->mt), GFP_KERNEL);
- if (!dst->mt)
- goto out_mt;
+ if (src->rules > 0) {
+ dst->mt = kvmalloc_array(src->rules, sizeof(*src->mt),
+ GFP_KERNEL);
+ 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.0
next prev parent reply other threads:[~2024-02-21 11:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-21 11:26 [PATCH net-next 00/12] netfilter updates for net-next Florian Westphal
2024-02-21 11:26 ` [PATCH net-next 01/12] netfilter: expect: Simplify the allocation of slab caches in nf_conntrack_expect_init Florian Westphal
2024-02-23 3:20 ` patchwork-bot+netdevbpf
2024-02-21 11:26 ` [PATCH net-next 02/12] netfilter: nf_log: consolidate check for NULL logger in lookup function Florian Westphal
2024-02-21 11:26 ` [PATCH net-next 03/12] netfilter: nf_log: validate nf_logger_find_get() Florian Westphal
2024-02-21 11:26 ` [PATCH net-next 04/12] netfilter: nft_osf: simplify init path Florian Westphal
2024-02-21 11:26 ` [PATCH net-next 05/12] netfilter: xtables: fix up kconfig dependencies Florian Westphal
2024-02-21 11:26 ` [PATCH net-next 06/12] netfilter: nft_set_pipapo: constify lookup fn args where possible Florian Westphal
2024-02-21 11:26 ` Florian Westphal [this message]
2024-02-21 11:26 ` [PATCH net-next 08/12] netfilter: nft_set_pipapo: shrink data structures Florian Westphal
2024-02-21 11:26 ` [PATCH net-next 09/12] netfilter: nft_set_pipapo: speed up bulk element insertions Florian Westphal
2024-02-21 11:26 ` [PATCH net-next 10/12] netfilter: nft_set_pipapo: use GFP_KERNEL for insertions Florian Westphal
2024-02-21 11:26 ` [PATCH net-next 11/12] netfilter: move nf_reinject into nfnetlink_queue modules Florian Westphal
2024-02-21 11:26 ` [PATCH net-next 12/12] netfilter: x_tables: Use unsafe_memcpy() for 0-sized destination Florian Westphal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240221112637.5396-8-fw@strlen.de \
--to=fw@strlen.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).