Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ADC7C43334 for ; Sun, 26 Jun 2022 16:43:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231534AbiFZQnz (ORCPT ); Sun, 26 Jun 2022 12:43:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231514AbiFZQnz (ORCPT ); Sun, 26 Jun 2022 12:43:55 -0400 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF0C6BE2C for ; Sun, 26 Jun 2022 09:43:52 -0700 (PDT) Received: from in02.mta.xmission.com ([166.70.13.52]:35486) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5VMU-00CexQ-3l; Sun, 26 Jun 2022 10:43:50 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:57694 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5VMT-008MK1-1s; Sun, 26 Jun 2022 10:43:49 -0600 From: "Eric W. Biederman" To: Kuniyuki Iwashima Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Pavel Emelyanov , Herbert Xu , Kuniyuki Iwashima , References: <20220626082331.36119-1-kuniyu@amazon.com> Date: Sun, 26 Jun 2022 11:43:27 -0500 In-Reply-To: <20220626082331.36119-1-kuniyu@amazon.com> (Kuniyuki Iwashima's message of "Sun, 26 Jun 2022 01:23:31 -0700") Message-ID: <871qvbwf2o.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1o5VMT-008MK1-1s;;;mid=<871qvbwf2o.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX19yP3gzbiyZQZgVvq8CUuFEy5NpK/3MGaQ= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH v2 net] af_unix: Do not call kmemdup() for init_net's sysctl table. X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Kuniyuki Iwashima writes: > While setting up init_net's sysctl table, we need not duplicate the global > table and can use it directly. Acked-by: "Eric W. Biederman" I am not quite certain the savings of a single entry table justivies the complexity. But the looks correct. Eric > > Fixes: 1597fbc0faf8 ("[UNIX]: Make the unix sysctl tables per-namespace") > Signed-off-by: Kuniyuki Iwashima > --- > 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; > }