From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Pavel Emelyanov <xemul@openvz.org>,
Herbert Xu <herbert@gondor.apana.org.au>,
"Kuniyuki Iwashima" <kuniyu@amazon.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>
Subject: [PATCH v2 net] af_unix: Do not call kmemdup() for init_net's sysctl table.
Date: Sun, 26 Jun 2022 01:23:31 -0700 [thread overview]
Message-ID: <20220626082331.36119-1-kuniyu@amazon.com> (raw)
While setting up init_net's sysctl table, we need not duplicate the global
table and can use it directly.
Fixes: 1597fbc0faf8 ("[UNIX]: Make the unix sysctl tables per-namespace")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
v2:
* Fix NULL comparison style by checkpatch.pl
v1: https://lore.kernel.org/all/20220626074454.28944-1-kuniyu@amazon.com/
---
---
net/unix/sysctl_net_unix.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
index 01d44e2598e2..4bd856d05135 100644
--- a/net/unix/sysctl_net_unix.c
+++ b/net/unix/sysctl_net_unix.c
@@ -26,11 +26,16 @@ int __net_init unix_sysctl_register(struct net *net)
{
struct ctl_table *table;
- table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
- if (table == NULL)
- goto err_alloc;
+ if (net_eq(net, &init_net)) {
+ table = unix_table;
+ } else {
+ table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
+ if (!table)
+ goto err_alloc;
+
+ table[0].data = &net->unx.sysctl_max_dgram_qlen;
+ }
- table[0].data = &net->unx.sysctl_max_dgram_qlen;
net->unx.ctl = register_net_sysctl(net, "net/unix", table);
if (net->unx.ctl == NULL)
goto err_reg;
@@ -38,7 +43,8 @@ int __net_init unix_sysctl_register(struct net *net)
return 0;
err_reg:
- kfree(table);
+ if (net_eq(net, &init_net))
+ kfree(table);
err_alloc:
return -ENOMEM;
}
--
2.30.2
next reply other threads:[~2022-06-26 8:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-26 8:23 Kuniyuki Iwashima [this message]
2022-06-26 16:43 ` [PATCH v2 net] af_unix: Do not call kmemdup() for init_net's sysctl table Eric W. Biederman
2022-06-27 17:58 ` Jakub Kicinski
2022-06-27 18:30 ` Kuniyuki Iwashima
2022-06-27 18:40 ` Eric Dumazet
2022-06-27 18:58 ` Kuniyuki Iwashima
2022-06-27 19:06 ` Eric Dumazet
2022-06-27 19:15 ` Kuniyuki Iwashima
2022-06-27 19:36 ` Eric Dumazet
2022-06-27 19:59 ` Kuniyuki Iwashima
2022-06-27 20:04 ` Eric Dumazet
2022-06-27 20:18 ` Kuniyuki Iwashima
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=20220626082331.36119-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=xemul@openvz.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;
as well as URLs for NNTP newsgroup(s).