Linux Netfilter development
 help / color / mirror / Atom feed
From: Thomas Haller <thaller@redhat.com>
To: NetFilter <netfilter-devel@vger.kernel.org>
Cc: Thomas Haller <thaller@redhat.com>
Subject: [PATCH nft 1/2] libnftables: drop gmp_init() and mp_set_memory_functions()
Date: Tue, 19 Sep 2023 14:36:16 +0200	[thread overview]
Message-ID: <20230919123621.2770734-1-thaller@redhat.com> (raw)

Setting global handles for libgmp via mp_set_memory_functions() is very
ugly. When we don't use mini-gmp, then potentially there are other users
of the library in the same process, and every process fighting about the
allocation functions is not gonna work.

It also means, we must not reset the allocation functions after somebody
already allocated GMP data with them. Which we cannot ensure, as we
don't know what other parts of the process are doing.

It's also unnecessary. The default allocation functions for gmp and
mini-gmp already abort the process on allocation failure ([1], [2]),
just like our xmalloc().

Just don't do this.

[1] https://gmplib.org/repo/gmp/file/8225bdfc499f/memory.c#l37
[2] https://git.netfilter.org/nftables/tree/src/mini-gmp.c?id=6d19a902c1d77cb51b940b1ce65f31b1cad38b74#n286

Signed-off-by: Thomas Haller <thaller@redhat.com>
---
 include/nftables.h |  1 -
 src/gmputil.c      | 10 ----------
 src/libnftables.c  |  1 -
 3 files changed, 12 deletions(-)

diff --git a/include/nftables.h b/include/nftables.h
index b9b2b01c2689..4b7c335928da 100644
--- a/include/nftables.h
+++ b/include/nftables.h
@@ -224,7 +224,6 @@ struct input_descriptor {
 
 void ct_label_table_init(struct nft_ctx *ctx);
 void mark_table_init(struct nft_ctx *ctx);
-void gmp_init(void);
 void realm_table_rt_init(struct nft_ctx *ctx);
 void devgroup_table_init(struct nft_ctx *ctx);
 void xt_init(void);
diff --git a/src/gmputil.c b/src/gmputil.c
index 7f65630db59c..bf472c65de48 100644
--- a/src/gmputil.c
+++ b/src/gmputil.c
@@ -197,13 +197,3 @@ int mpz_vfprintf(FILE *fp, const char *f, va_list args)
 	return n;
 }
 #endif
-
-static void *gmp_xrealloc(void *ptr, size_t old_size, size_t new_size)
-{
-	return xrealloc(ptr, new_size);
-}
-
-void gmp_init(void)
-{
-	mp_set_memory_functions(xmalloc, gmp_xrealloc, NULL);
-}
diff --git a/src/libnftables.c b/src/libnftables.c
index c5f5729409d1..c34ee43de1fa 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -196,7 +196,6 @@ struct nft_ctx *nft_ctx_new(uint32_t flags)
 
 	if (!init_once) {
 		init_once = true;
-		gmp_init();
 #ifdef HAVE_LIBXTABLES
 		xt_init();
 #endif
-- 
2.41.0


             reply	other threads:[~2023-09-19 12:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19 12:36 Thomas Haller [this message]
2023-09-19 12:36 ` [PATCH nft 2/2] libnftables: move init-once guard inside xt_init() Thomas Haller
2023-09-19 13:42   ` Pablo Neira Ayuso
2023-09-19 13:42 ` [PATCH nft 1/2] libnftables: drop gmp_init() and mp_set_memory_functions() Pablo Neira Ayuso

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=20230919123621.2770734-1-thaller@redhat.com \
    --to=thaller@redhat.com \
    --cc=netfilter-devel@vger.kernel.org \
    /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