Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5481662rwb; Wed, 9 Aug 2023 05:04:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8zkAih7N+9IQs+JfXweV8851Z9NiWJebtB7y6lnjBEngq413aL9WuO+bYB2+7a+jA60O2 X-Received: by 2002:a05:6a00:99a:b0:667:d0ff:6a0f with SMTP id u26-20020a056a00099a00b00667d0ff6a0fmr3831179pfg.5.1691582695291; Wed, 09 Aug 2023 05:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691582695; cv=none; d=google.com; s=arc-20160816; b=HUFITJCXmBMk6c6XJWHg4DU7qpOdqO+X7+PyXFU18Wzc9NnxYw4fEOHDt8XaEULZdN wS6KPfplmIKOvHDwchStOzqXHtijDG3GXZwv7IKql1Zx/t7EzjyHytDktOc8jmdxToRr n3fH7bRva6SBE9Cx+lRinB7XkvjyJiB5ovfxT3IEDeQjTwJtcmm0dqg0p2Pu8hUmAz8I fqIr9fN/pklyxUIzyJIsaMy+N7JJpKrgA2+FqZQbQECbwd+KTxtnyXlGCrX9uKmnVNib DNsWuDMe5FqN5rwJhhWHbSK6zMAI6E/QGkQEOwdOgFplGVm6feYOo6dTBO12DcC6Y1uX KdAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y0Ehqjwr7n7aalL24v3eoFH6zkXkMLmEA1uyOzpkdUI=; fh=yJYy1gNyqt+ZQdQgHW0QnMhG/WDC5gaPesekaVcjNqQ=; b=Cg89k5JxaaftoTOIlLccqPN9KYS1f9yTdnqeX3uExsQY4C6LX5+jVKRp5ruNt0E15X uFWGGCIpxHCD4OdE423gGV6tho/rwXoOVUFPDJx2R2ow0rbVV2a8k/JgyGihzBeVQxnV ycAC9mRmcym4MUd9e8nwRaBjADKJ/Kzsywpt7upKYfG3Wd69RYDJrpz+q/rpTlHJ990L zFWzYvanJOH5B06I7x/aalZ8B+trEH48Hqw/JRSY4AUNe023KtzgoUzlTSCv3FLsAm2q ztgA+cfPlmrvGtgO9pmNqX1PKIV9cG6IATJ2wcTcf3UvpI70tsMb30MFDsOVgKju1W6e T9uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=H2CgJ05O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cg19-20020a056a00291300b00687546abaf6si8981721pfb.195.2023.08.09.05.04.43; Wed, 09 Aug 2023 05:04:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=H2CgJ05O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232473AbjHIKun (ORCPT + 99 others); Wed, 9 Aug 2023 06:50:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232367AbjHIKua (ORCPT ); Wed, 9 Aug 2023 06:50:30 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C258B2115; Wed, 9 Aug 2023 03:50:26 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fe426b8583so58425975e9.2; Wed, 09 Aug 2023 03:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691578225; x=1692183025; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y0Ehqjwr7n7aalL24v3eoFH6zkXkMLmEA1uyOzpkdUI=; b=H2CgJ05O88mtUkv8Ftw6TkmecV0v7sKcIi3Tsn9GBrQX05jqDPhbD2B/ScxcMO29RM Lj6x0UzluUoOPs98f6Tlr+Tk8cGJaXK6l+9ZOTDUmVPUSgcWt30XAdDS43WgFLBBaExy 98susFYk9dmGQlPIVAf3Nbucn1IQCKFadE8y8S5N2AQhSJCuQMHeZhgnicADH0kuanTH 4QycPhkp2niM9RbeZNtJ03nQE1qAuEoo0lyE0g8KEHFXcIx+jfcEIKnvHU/7dm6jE4RQ na8Dh+Z2zcd3s79bUfBxcF4kRpNxRKt7x1KPsfrKIp8ELBr/vYWA2+4F7+Hg2zmMT0S6 ILQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691578225; x=1692183025; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y0Ehqjwr7n7aalL24v3eoFH6zkXkMLmEA1uyOzpkdUI=; b=N+bzRV496nN2a8mcCZTQ6zgl55e+OlsP7Af4hfgzm7J9LHJv2yys4Ydy7HZ6Ujob+J /ny8X7Z0qanjy+ibYY8ceYRkqwH+ZhE8U6QcMYyfu4eQm60RKdvxJt5vrYgqxT5sEFfW QrLM6SzJXay0uWv1p3wjPRsyQIQu4QTa0/EXQpHYDZorX50o7580SdcxOgwiKZRku4rw apW8KZJVznLz0H/PdgcJSFuoXh6Nzxr6KWLU1rmfj4sf9zjp/WF3/WzlmXZu3e/qwc0u BhXevaqQz7EwC0szDRPsrG5UY0PetGfJ4aa0A5oPxHEzMSRa6/g2l7WTeVTyuMWkyx+1 bgoQ== X-Gm-Message-State: AOJu0YxZUZsjwiWNDlhj8ceOsiDnlOaBDJTl1J8rOtBVJ3gQH0LNRAui sZyNk9wAASGGf7BqHrBLil4= X-Received: by 2002:a7b:ca4c:0:b0:3fb:415a:d07 with SMTP id m12-20020a7bca4c000000b003fb415a0d07mr1774295wml.36.1691578225183; Wed, 09 Aug 2023 03:50:25 -0700 (PDT) Received: from localhost ([165.225.194.193]) by smtp.gmail.com with ESMTPSA id n12-20020a7bcbcc000000b003fe557829ccsm1602527wmi.28.2023.08.09.03.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 03:50:24 -0700 (PDT) From: Joel Granados X-Google-Original-From: Joel Granados To: mcgrof@kernel.org Cc: rds-devel@oss.oracle.com, "David S. Miller" , Florian Westphal , willy@infradead.org, Jan Karcher , Wen Gu , Simon Horman , Tony Lu , linux-wpan@vger.kernel.org, Matthieu Baerts , Christian Borntraeger , mptcp@lists.linux.dev, Heiko Carstens , Stefan Schmidt , Will Deacon , Julian Anastasov , netfilter-devel@vger.kernel.org, Joerg Reuter , linux-kernel@vger.kernel.org, Alexander Gordeev , linux-sctp@vger.kernel.org, Xin Long , Herbert Xu , linux-hams@vger.kernel.org, Vasily Gorbik , coreteam@netfilter.org, Ralf Baechle , Steffen Klassert , Pablo Neira Ayuso , keescook@chromium.org, Roopa Prabhu , David Ahern , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Jozsef Kadlecsik , Wenjia Zhang , josh@joshtriplett.org, linux-fsdevel@vger.kernel.org, Alexander Aring , Nikolay Aleksandrov , netdev@vger.kernel.org, Santosh Shilimkar , linux-s390@vger.kernel.org, Sven Schnelle , "D. Wythe" , Eric Dumazet , lvs-devel@vger.kernel.org, linux-rdma@vger.kernel.org, Paolo Abeni , Iurii Zaikin , Marcelo Ricardo Leitner , bridge@lists.linux-foundation.org, Karsten Graul , Mat Martineau , Miquel Raynal , Jakub Kicinski , Joel Granados , Greg Kroah-Hartman Subject: [PATCH v3 08/14] sysctl: Add size to register_net_sysctl function Date: Wed, 9 Aug 2023 12:50:00 +0200 Message-Id: <20230809105006.1198165-9-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230809105006.1198165-1-j.granados@samsung.com> References: <20230809105006.1198165-1-j.granados@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit adds size to the register_net_sysctl indirection function to facilitate the removal of the sentinel elements (last empty markers) from the ctl_table arrays. Though we don't actually remove any sentinels in this commit, register_net_sysctl* now has the capability of forwarding table_size for when that happens. We create a new function register_net_sysctl_sz with an extra size argument. A macro replaces the existing register_net_sysctl. The size in the macro is SIZE_MAX instead of ARRAY_SIZE to avoid compilation errors while we systematically migrate to register_net_sysctl_sz. Will change to ARRAY_SIZE in subsequent commits. Care is taken to add table_size to the stopping criteria in such a way that when we remove the empty sentinel element, it will continue stopping in the last element of the ctl_table array. Signed-off-by: Joel Granados Suggested-by: Greg Kroah-Hartman --- include/net/net_namespace.h | 10 ++++++---- net/sysctl_net.c | 22 +++++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 78beaa765c73..e4e5fe75a281 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -469,15 +469,17 @@ void unregister_pernet_device(struct pernet_operations *); struct ctl_table; +#define register_net_sysctl(net, path, table) \ + register_net_sysctl_sz(net, path, table, SIZE_MAX) #ifdef CONFIG_SYSCTL int net_sysctl_init(void); -struct ctl_table_header *register_net_sysctl(struct net *net, const char *path, - struct ctl_table *table); +struct ctl_table_header *register_net_sysctl_sz(struct net *net, const char *path, + struct ctl_table *table, size_t table_size); void unregister_net_sysctl_table(struct ctl_table_header *header); #else static inline int net_sysctl_init(void) { return 0; } -static inline struct ctl_table_header *register_net_sysctl(struct net *net, - const char *path, struct ctl_table *table) +static inline struct ctl_table_header *register_net_sysctl_sz(struct net *net, + const char *path, struct ctl_table *table, size_t table_size) { return NULL; } diff --git a/net/sysctl_net.c b/net/sysctl_net.c index d9cbbb51b143..051ed5f6fc93 100644 --- a/net/sysctl_net.c +++ b/net/sysctl_net.c @@ -122,12 +122,13 @@ __init int net_sysctl_init(void) * allocated. */ static void ensure_safe_net_sysctl(struct net *net, const char *path, - struct ctl_table *table) + struct ctl_table *table, size_t table_size) { struct ctl_table *ent; pr_debug("Registering net sysctl (net %p): %s\n", net, path); - for (ent = table; ent->procname; ent++) { + ent = table; + for (size_t i = 0; i < table_size && ent->procname; ent++, i++) { unsigned long addr; const char *where; @@ -160,21 +161,24 @@ static void ensure_safe_net_sysctl(struct net *net, const char *path, } } -struct ctl_table_header *register_net_sysctl(struct net *net, - const char *path, struct ctl_table *table) +struct ctl_table_header *register_net_sysctl_sz(struct net *net, + const char *path, + struct ctl_table *table, + size_t table_size) { - int count = 0; + int count; struct ctl_table *entry; if (!net_eq(net, &init_net)) - ensure_safe_net_sysctl(net, path, table); + ensure_safe_net_sysctl(net, path, table, table_size); - for (entry = table; entry->procname; entry++) - count++; + entry = table; + for (count = 0 ; count < table_size && entry->procname; entry++, count++) + ; return __register_sysctl_table(&net->sysctls, path, table, count); } -EXPORT_SYMBOL_GPL(register_net_sysctl); +EXPORT_SYMBOL_GPL(register_net_sysctl_sz); void unregister_net_sysctl_table(struct ctl_table_header *header) { -- 2.30.2