From patchwork Wed Jul 26 14:06:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 13328081 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 826A4C0015E for ; Wed, 26 Jul 2023 14:07:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234366AbjGZOHE (ORCPT ); Wed, 26 Jul 2023 10:07:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234228AbjGZOHA (ORCPT ); Wed, 26 Jul 2023 10:07:00 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC69B2701 for ; Wed, 26 Jul 2023 07:06:52 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230726140650euoutp021d5051ddfac04a1fbc239e47db38a0fb~1cAcJNYlP1595615956euoutp02D for ; Wed, 26 Jul 2023 14:06:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230726140650euoutp021d5051ddfac04a1fbc239e47db38a0fb~1cAcJNYlP1595615956euoutp02D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1690380410; bh=A0yFUtcBmjlDc/JAvy8SEl8ns1g5aFjeEqkhCY5WXnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n8Cx/zpGERpqTQz+DVg8x5GyzY6Fc3IKT5Hb3hbJUgg7v4tIJlwrAZLfv7I3PLMz6 x+EX5jj/FNVmRuS+mWL6GeGYh8ZRXvQpJC9aPdhCQtjmhsxNz/jg/zaQnSyQHnRN/V oogrWrMt/08m1sQXWOfvf4KAncHKaBAGibg50ImM= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230726140650eucas1p1b2e6fc9826d0d0732b155ab6d48adfc8~1cAb_oX8t2257522575eucas1p1v; Wed, 26 Jul 2023 14:06:50 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 27.56.37758.A7821C46; Wed, 26 Jul 2023 15:06:50 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230726140650eucas1p1f5b2aa9dd8f90989c881f0a2e682b9eb~1cAbuJVld2261822618eucas1p1o; Wed, 26 Jul 2023 14:06:50 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230726140650eusmtrp1211dd44af609fa595ca6559c1464ada7~1cAbtgAVf2391823918eusmtrp1c; Wed, 26 Jul 2023 14:06:50 +0000 (GMT) X-AuditID: cbfec7f5-815ff7000002937e-e3-64c1287a64e9 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id A9.47.14344.A7821C46; Wed, 26 Jul 2023 15:06:50 +0100 (BST) Received: from localhost (unknown [106.210.248.223]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230726140649eusmtip2e2780fccf7021b940db173c2d91726aa~1cAbgzFjn3056730567eusmtip2X; Wed, 26 Jul 2023 14:06:49 +0000 (GMT) From: Joel Granados To: mcgrof@kernel.org, Kees Cook , Iurii Zaikin Cc: willy@infradead.org, josh@joshtriplett.org, Joel Granados , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 01/14] sysctl: Prefer ctl_table_header in proc_sysctl Date: Wed, 26 Jul 2023 16:06:21 +0200 Message-Id: <20230726140635.2059334-2-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230726140635.2059334-1-j.granados@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprJKsWRmVeSWpSXmKPExsWy7djP87pVGgdTDLruS1ks3f+Q0eL/gnyL M925Fnv2nmSxuLxrDpvFjQlPGS1+/wCylu30c+DwmN1wkcVjwaZSj80rtDxuvbb12LSqk82j b8sqRo/Pm+QC2KO4bFJSczLLUov07RK4MtpOXmUuaFWraFjYxNLAuE6+i5GTQ0LARGJe+yzW LkYuDiGBFYwSnf1f2CGcL4wSizfuZYRwPjNK/Fv4gh2m5fT+HawgtpDAckaJu1PNIYpeMkrc +jyXESTBJqAjcf7NHeYuRg4OEYFYicVTUkDCzALTGSWWzJEBsYUFXCWWbNnIDGKzCKhKrO+5 yQ5SzitgK9G/2BpilbxE2/XpYBM5BewkVq79DraWV0BQ4uTMJywQI+UlmrfOZgY5QULgDIfE gr7tjBDNLhKHfy6BsoUlXh3fAnW/jMTpyT0sEA2TGSX2//vADuGsZpRY1viVCaLKWqLlyhOw i5gFNCXW79KHCDtKnN66BewvCQE+iRtvBSGO4JOYtG06VJhXoqNNCKJaRaJv6RQWCFtK4vrl nWwQtofEjdMXmSYwKs5C8s4sJO/MQti7gJF5FaN4amlxbnpqsXFearlecWJucWleul5yfu4m RmDqOf3v+NcdjCtefdQ7xMjEwXiIUYKDWUmE1zBmX4oQb0piZVVqUX58UWlOavEhRmkOFiVx Xm3bk8lCAumJJanZqakFqUUwWSYOTqkGpqhy+dxNR9/82crntnlZ5F+vkxHKB7YceR/slPh6 Rvae2K0lzWWRs97cF713Kmm93pQXTrPaVFglPT8677d7/13F5axvB4P/jhm7+V7Pv3dfzv+5 NZ/G7mv7+KeGTnW0TPd7zTpt116PHfZJqooshq95js2wv6Fy/uLhLs233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vt2sbuN9lFmkysr2eM7k+miu0 /kRAk907l7VzbrclhQYv/3nxS3eD8Z2XdtMSe91KNQ3upS+Zu3iZ7o5ngVmPT2zgPG/Tbpgk usT5yzZJp/diiS7Xtq76s1nbyk7Q97TU3reGHT3uWeo9fEc7dV9ZTNX4tzRiwcZTs62Y1iqx FGckGmoxFxUnAgCTiEtOGwMAAA== X-CMS-MailID: 20230726140650eucas1p1f5b2aa9dd8f90989c881f0a2e682b9eb X-Msg-Generator: CA X-RootMTR: 20230726140650eucas1p1f5b2aa9dd8f90989c881f0a2e682b9eb X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230726140650eucas1p1f5b2aa9dd8f90989c881f0a2e682b9eb References: <20230726140635.2059334-1-j.granados@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is a preparation commit to use ctl_table_header instead of ctl_table as the element that is passed around in proc_sysctl.c. This will become necessary when the size can no longer be calculated by searching for an empty sentinel in the ctl_table array and will live in the ctl_table_header. Signed-off-by: Joel Granados --- fs/proc/proc_sysctl.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 5ea42653126e..94d71446da39 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1125,11 +1125,11 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table) return err; } -static int sysctl_check_table(const char *path, struct ctl_table *table) +static int sysctl_check_table(const char *path, struct ctl_table_header *header) { struct ctl_table *entry; int err = 0; - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, header->ctl_table) { if ((entry->proc_handler == proc_dostring) || (entry->proc_handler == proc_dobool) || (entry->proc_handler == proc_dointvec) || @@ -1159,8 +1159,7 @@ static int sysctl_check_table(const char *path, struct ctl_table *table) return err; } -static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table, - struct ctl_table_root *link_root) +static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_header *head) { struct ctl_table *link_table, *entry, *link; struct ctl_table_header *links; @@ -1170,7 +1169,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table name_bytes = 0; nr_entries = 0; - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, head->ctl_table) { nr_entries++; name_bytes += strlen(entry->procname) + 1; } @@ -1189,12 +1188,12 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table link_name = (char *)&link_table[nr_entries + 1]; link = link_table; - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, head->ctl_table) { int len = strlen(entry->procname) + 1; memcpy(link_name, entry->procname, len); link->procname = link_name; link->mode = S_IFLNK|S_IRWXUGO; - link->data = link_root; + link->data = head->root; link_name += len; link++; } @@ -1205,15 +1204,16 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table } static bool get_links(struct ctl_dir *dir, - struct ctl_table *table, struct ctl_table_root *link_root) + struct ctl_table_header *header, + struct ctl_table_root *link_root) { - struct ctl_table_header *head; + struct ctl_table_header *tmp_head; struct ctl_table *entry, *link; /* Are there links available for every entry in table? */ - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, header->ctl_table) { const char *procname = entry->procname; - link = find_entry(&head, dir, procname, strlen(procname)); + link = find_entry(&tmp_head, dir, procname, strlen(procname)); if (!link) return false; if (S_ISDIR(link->mode) && S_ISDIR(entry->mode)) @@ -1224,10 +1224,10 @@ static bool get_links(struct ctl_dir *dir, } /* The checks passed. Increase the registration count on the links */ - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, header->ctl_table) { const char *procname = entry->procname; - link = find_entry(&head, dir, procname, strlen(procname)); - head->nreg++; + link = find_entry(&tmp_head, dir, procname, strlen(procname)); + tmp_head->nreg++; } return true; } @@ -1246,13 +1246,13 @@ static int insert_links(struct ctl_table_header *head) if (IS_ERR(core_parent)) return 0; - if (get_links(core_parent, head->ctl_table, head->root)) + if (get_links(core_parent, head, head->root)) return 0; core_parent->header.nreg++; spin_unlock(&sysctl_lock); - links = new_links(core_parent, head->ctl_table, head->root); + links = new_links(core_parent, head); spin_lock(&sysctl_lock); err = -ENOMEM; @@ -1260,7 +1260,7 @@ static int insert_links(struct ctl_table_header *head) goto out; err = 0; - if (get_links(core_parent, head->ctl_table, head->root)) { + if (get_links(core_parent, head, head->root)) { kfree(links); goto out; } @@ -1371,7 +1371,7 @@ struct ctl_table_header *__register_sysctl_table( node = (struct ctl_node *)(header + 1); init_header(header, root, set, node, table); - if (sysctl_check_table(path, table)) + if (sysctl_check_table(path, header)) goto fail; spin_lock(&sysctl_lock); From patchwork Wed Jul 26 14:06:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 13328083 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 191C7C0015E for ; Wed, 26 Jul 2023 14:07:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234384AbjGZOHK (ORCPT ); Wed, 26 Jul 2023 10:07:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234194AbjGZOHC (ORCPT ); Wed, 26 Jul 2023 10:07:02 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DE3B271B for ; Wed, 26 Jul 2023 07:06:54 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230726140652euoutp02207eb5fa95c1595f7b9cc46927d5c634~1cAeE7dZr1252612526euoutp02e for ; Wed, 26 Jul 2023 14:06:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230726140652euoutp02207eb5fa95c1595f7b9cc46927d5c634~1cAeE7dZr1252612526euoutp02e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1690380412; bh=flcxV7zco8XJiJ2V96AVTp6oAIKfZxtHk3BJJ+2+M8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mcLqRmS6ZLlH2oQRKCUVtg+WARwN/pLwwFg7Pen7U4jJMWmEabZTu7+dO78AQGgbZ w4P5PpkhAjstc/u4x3uKv5NBHThJAW0HysSZuABeOWlzZOhCwiYmRjfthKkcVQl6Da 9k1m24sqEn5cT+iEh1IGfR1X3x3KvfmKLmDF4RUE= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230726140652eucas1p25eee8581f80f6eda839e6cef29d7bacb~1cAd0V_7C0710907109eucas1p2i; Wed, 26 Jul 2023 14:06:52 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 9A.56.37758.C7821C46; Wed, 26 Jul 2023 15:06:52 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230726140652eucas1p2a2ac2dd74986bd9ace8380d6f51024ff~1cAdizv1z0711407114eucas1p2S; Wed, 26 Jul 2023 14:06:52 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230726140652eusmtrp136a75f69eb7237d97cd29d9ac83bcb36~1cAdiGwzm2391823918eusmtrp11; Wed, 26 Jul 2023 14:06:52 +0000 (GMT) X-AuditID: cbfec7f5-7ffff7000002937e-ee-64c1287c59be Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D0.C7.10549.C7821C46; Wed, 26 Jul 2023 15:06:52 +0100 (BST) Received: from localhost (unknown [106.210.248.223]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230726140651eusmtip159fbf6fc3a9deef8313d0d29dfb7a087~1cAdXKVMW1545915459eusmtip1J; Wed, 26 Jul 2023 14:06:51 +0000 (GMT) From: Joel Granados To: mcgrof@kernel.org, Kees Cook , Iurii Zaikin Cc: willy@infradead.org, josh@joshtriplett.org, Joel Granados , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 02/14] sysctl: Use ctl_table_header in list_for_each_table_entry Date: Wed, 26 Jul 2023 16:06:22 +0200 Message-Id: <20230726140635.2059334-3-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230726140635.2059334-1-j.granados@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Sf1CLcRy+79637W3uzdsqffqBjA7RqsOZS52ceJ3j0jl3OY6dvVJti60h 15HToZBUTMsfIzEl1Sopv3eV1pxFaLGcyK/yo2iYH8V65/jv+Tyf5/l+nufuS2ACrZs/kaRI Y5QKiUzI5eOXWhyW0Ixpt6ThlmY/cemNHiQe0aWK7xyUi69eM+HijsaTXLE17yUS//j2B51t WLGAoIsz7+G0zqCma/Qh9OP+KNpQls2lc2vLEP3ZMCGOt4Y/X8rIkrYxyrDoDfzNmveCLccn 73B8P49lIu34HOROADUb7lo/4TmITwgoPYLuNzYuOwwh+Kgv47DDZwSVh7u4fy015i4euziH oPDHM5f/LYKHe7NHVVxqJlje2bAcRBDe1DooKZQ6aYzSIDhzMtCJvah4KO7+gJwYp4Lhyekj o5ikosCSlYWzxybCvk7NKO9ORcP5iq9urMYTTEW9OPvmRNhbV4w5MwDVSkBuyQUea14E9qEW V2ov6Ltd6+IDwVxwCGcNBQhuDA/w2KEcwdk9dg6rioS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qFJLWAkWkVo0hqaXFuem6xoV5xYm5xaV66XnJ+ 7iZGYIxsO/Zz8w7Gea8+6h1iZOJgPMQowcGsJMJrGLMvRYg3JbGyKrUoP76oNCe1+BCjKdDd E5mlRJPzgVGaVxJvaGZgamhiZmlgamlmrCTO61nQkSgkkJ5YkpqdmlqQWgTTx8TBKdXAtHy6 SJxA0pepvaLywXvsp69oN0+a/+zF3vDKTfvTT9oeVI+c0KbYLLX/RKLXdb+v+vv/qq7LXHD7 Ae/l4OC7MeKOFmzf5lf2hvXcm3Zweq1T6W2X+40/3ncFvwk6e9BV9GfER+0NJvqpzZNvZ/xv /J3qa+ESMuW23Av/uGrBt7XcNWF+cUfYpOf337nP8m6ZfEWa3YIni1cb53tIXuC8cm9Nvt7j fFvWE2YJvhHLJH65aq0wUi+9K1z7svDorS9p4qX7o/8xcVgz9ulmXJxhJNv1drXiN5+atxbf 9erUtsUWuK06zOdQ+kg9789mVddSyW4W+e66JMnW7ptMt7fsNvZW1klb0HVNuOzn4wVKLMUZ iYZazEXFiQD46aWHGgMAAA== X-CMS-MailID: 20230726140652eucas1p2a2ac2dd74986bd9ace8380d6f51024ff X-Msg-Generator: CA X-RootMTR: 20230726140652eucas1p2a2ac2dd74986bd9ace8380d6f51024ff X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230726140652eucas1p2a2ac2dd74986bd9ace8380d6f51024ff References: <20230726140635.2059334-1-j.granados@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Now that the ctl_header is the preferred way of passing ctl_table elements around, we use it (the header) in the list_for_each_table_entry macro. Signed-off-by: Joel Granados --- fs/proc/proc_sysctl.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 94d71446da39..884460b0385b 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -19,8 +19,8 @@ #include #include "internal.h" -#define list_for_each_table_entry(entry, table) \ - for ((entry) = (table); (entry)->procname; (entry)++) +#define list_for_each_table_entry(entry, header) \ + for ((entry) = (header->ctl_table); (entry)->procname; (entry)++) static const struct dentry_operations proc_sys_dentry_operations; static const struct file_operations proc_sys_file_operations; @@ -204,7 +204,7 @@ static void init_header(struct ctl_table_header *head, if (node) { struct ctl_table *entry; - list_for_each_table_entry(entry, table) { + list_for_each_table_entry(entry, head) { node->header = head; node++; } @@ -215,7 +215,7 @@ static void erase_header(struct ctl_table_header *head) { struct ctl_table *entry; - list_for_each_table_entry(entry, head->ctl_table) + list_for_each_table_entry(entry, head) erase_entry(head, entry); } @@ -242,7 +242,7 @@ static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header) err = insert_links(header); if (err) goto fail_links; - list_for_each_table_entry(entry, header->ctl_table) { + list_for_each_table_entry(entry, header) { err = insert_entry(header, entry); if (err) goto fail; @@ -1129,7 +1129,7 @@ static int sysctl_check_table(const char *path, struct ctl_table_header *header) { struct ctl_table *entry; int err = 0; - list_for_each_table_entry(entry, header->ctl_table) { + list_for_each_table_entry(entry, header) { if ((entry->proc_handler == proc_dostring) || (entry->proc_handler == proc_dobool) || (entry->proc_handler == proc_dointvec) || @@ -1169,7 +1169,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_ name_bytes = 0; nr_entries = 0; - list_for_each_table_entry(entry, head->ctl_table) { + list_for_each_table_entry(entry, head) { nr_entries++; name_bytes += strlen(entry->procname) + 1; } @@ -1188,7 +1188,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_ link_name = (char *)&link_table[nr_entries + 1]; link = link_table; - list_for_each_table_entry(entry, head->ctl_table) { + list_for_each_table_entry(entry, head) { int len = strlen(entry->procname) + 1; memcpy(link_name, entry->procname, len); link->procname = link_name; @@ -1211,7 +1211,7 @@ static bool get_links(struct ctl_dir *dir, struct ctl_table *entry, *link; /* Are there links available for every entry in table? */ - list_for_each_table_entry(entry, header->ctl_table) { + list_for_each_table_entry(entry, header) { const char *procname = entry->procname; link = find_entry(&tmp_head, dir, procname, strlen(procname)); if (!link) @@ -1224,7 +1224,7 @@ static bool get_links(struct ctl_dir *dir, } /* The checks passed. Increase the registration count on the links */ - list_for_each_table_entry(entry, header->ctl_table) { + list_for_each_table_entry(entry, header) { const char *procname = entry->procname; link = find_entry(&tmp_head, dir, procname, strlen(procname)); tmp_head->nreg++; @@ -1356,12 +1356,14 @@ struct ctl_table_header *__register_sysctl_table( { struct ctl_table_root *root = set->dir.header.root; struct ctl_table_header *header; + struct ctl_table_header h_tmp; struct ctl_dir *dir; struct ctl_table *entry; struct ctl_node *node; int nr_entries = 0; - list_for_each_table_entry(entry, table) + h_tmp.ctl_table = table; + list_for_each_table_entry(entry, (&h_tmp)) nr_entries++; header = kzalloc(sizeof(struct ctl_table_header) + @@ -1471,7 +1473,7 @@ static void put_links(struct ctl_table_header *header) if (IS_ERR(core_parent)) return; - list_for_each_table_entry(entry, header->ctl_table) { + list_for_each_table_entry(entry, header) { struct ctl_table_header *link_head; struct ctl_table *link; const char *name = entry->procname; From patchwork Wed Jul 26 14:06:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 13328084 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 33E02C001DC for ; Wed, 26 Jul 2023 14:07:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234034AbjGZOHQ (ORCPT ); Wed, 26 Jul 2023 10:07:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234335AbjGZOHC (ORCPT ); Wed, 26 Jul 2023 10:07:02 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 482632722 for ; Wed, 26 Jul 2023 07:06:55 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230726140654euoutp025f9bf59266bd03a91cc66770d6c9b86e~1cAfUbZke1252612526euoutp02g for ; Wed, 26 Jul 2023 14:06:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230726140654euoutp025f9bf59266bd03a91cc66770d6c9b86e~1cAfUbZke1252612526euoutp02g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1690380414; bh=6mB52qN+R16ZSOlZbadkP2nqRgZuKLvKv4ZQP2aLimE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KsHMve4EUJuZI3y4V+x7wPfANifMyLnhuFBwTmSv8Tsbre8M7JjhzWs8djE7plcZR emBQvp6UDkOyyyg5mgGbp3bkvCjFczW/QSW+/a+nDyGR5UC7XuunS4kV/gJ1EiPBQM ovjo9zBf3t957JBw1tUH9lIT+GxcXKy0XKFEGOTU= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230726140653eucas1p2d871c6dd058bd31fb2422dd12e6c3da0~1cAfFa4C30080000800eucas1p2b; Wed, 26 Jul 2023 14:06:53 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id FB.56.37758.D7821C46; Wed, 26 Jul 2023 15:06:53 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230726140653eucas1p2e234b7cd0af5dc506bd27399b84292a6~1cAesXzc90711407114eucas1p2V; Wed, 26 Jul 2023 14:06:53 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230726140653eusmtrp148068635e752f08c3e11322422ed43d0~1cAemxqF02391823918eusmtrp14; Wed, 26 Jul 2023 14:06:53 +0000 (GMT) X-AuditID: cbfec7f5-815ff7000002937e-f3-64c1287d0843 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 02.C7.10549.D7821C46; Wed, 26 Jul 2023 15:06:53 +0100 (BST) Received: from localhost (unknown [106.210.248.223]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230726140653eusmtip28acb5341e8d5a00219f44de2ba1c977a~1cAedM1422279822798eusmtip2A; Wed, 26 Jul 2023 14:06:53 +0000 (GMT) From: Joel Granados To: mcgrof@kernel.org, Kees Cook , Iurii Zaikin Cc: willy@infradead.org, josh@joshtriplett.org, Joel Granados , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 03/14] sysctl: Add ctl_table_size to ctl_table_header Date: Wed, 26 Jul 2023 16:06:23 +0200 Message-Id: <20230726140635.2059334-4-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230726140635.2059334-1-j.granados@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SfVDLcRzHfff7bfs15r5N9JHOw+ROZAmnObXjzsMPh/4R13HZtV+Ztsp+ lbjLhQwrS566HqTlaSp2VkiIwia5SmHzcNIZd0IeJgkV88vx3+vz+bzfn4fvfSlCUsD3o9QJ yYwuQamRCkTkRVtv07T0yXWq6ZU3ZfKT1zuQfKAkUX4vSyu/eq2BlLfVFAnkzv2vkPzHt990 6vKKeRRdmHGfpEusKXSleQr95G04bS3bK6CNVWWIdlvHRgijRGEqRqNOZXTBivWiDY1Pq8ik xmFpA1VmfgYyiAzIiwI8C+zGbtKARJQEmxHsqOgVcMEXBM3u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4hASWMoo8Xr/ZLYuRg6g hJTE92WcEDXCEn+udbFB1DxnlFjVOpcdJMEmoCNx/s0dZhBbRCBeYubj+2CDmAVmM0qsPnkI LCEs4CrxfdVRFhCbRUBVYs3X3awgNq+ArcSzJ2uYITbIS7Rdn84IYnMK2EmsXPsdrEYIqKZn 6lN2iHpBiZMzn4DNYQaqb946m3kCo8AsJKlZSFILGJlWMYqklhbnpucWG+oVJ+YWl+al6yXn 525iBMbJtmM/N+9gnPfqo94hRiYOxkOMEhzMSiK8hjH7UoR4UxIrq1KL8uOLSnNSiw8xmgLd PZFZSjQ5HxipeSXxhmYGpoYmZpYGppZmxkrivJ4FHYlCAumJJanZqakFqUUwfUwcnFINTCcZ /GIuexjN/dzsIB/A+uKG82Tjm02Pw5n1PFY0P3jyZGbbtuLZW0KFBYrWxwjuYPbmVc22mzF7 /Z/LcVHJsu9vGnd7+YTtifhYs/x3gkbEle0eqhdPZF8RY+T59G5x+8F0qfWrdknKrpXfdlJB qmvTwr/8HS9uODyf1BeywCTeeuO8z21/m4xKPs/Y8X3uzjj3/W/mVG2TzozZ9qyId+Ii0amW C6XPfxfLk/kw9eSd4Jdnks/cnc/hdf1oeFrDiy3flXfyGi+UYe7P9m98KfDr0mqVWouAz262 GyKDDl54OHVBU5V80YFMK8+vbMlllq7F/urrNZgMG0P/bVY61vlKPZzzq+ZthlUCM/X+flNi Kc5INNRiLipOBAChSKibHAMAAA== X-CMS-MailID: 20230726140653eucas1p2e234b7cd0af5dc506bd27399b84292a6 X-Msg-Generator: CA X-RootMTR: 20230726140653eucas1p2e234b7cd0af5dc506bd27399b84292a6 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230726140653eucas1p2e234b7cd0af5dc506bd27399b84292a6 References: <20230726140635.2059334-1-j.granados@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The new ctl_table_size element will hold the size of the ctl_table contained in the header. This value is passed by the callers to the sysctl register infrastructure. This is a preparation commit that allows us to systematically add ctl_table_size and start using it only when it is in all the places where there is a sysctl registration. Signed-off-by: Joel Granados --- include/linux/sysctl.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 59d451f455bf..33252ad58ebe 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -159,12 +159,22 @@ struct ctl_node { struct ctl_table_header *header; }; -/* struct ctl_table_header is used to maintain dynamic lists of - struct ctl_table trees. */ +/** + * struct ctl_table_header - maintains dynamic lists of struct ctl_table trees + * @ctl_table: pointer to the first element in ctl_table array + * @ctl_table_size: number of elements pointed by @ctl_table + * @used: The entry will never be touched when equal to 0. + * @count: Upped every time something is added to @inodes and downed every time + * something is removed from inodes + * @nreg: When nreg drops to 0 the ctl_table_header will be unregistered. + * @rcu: Delays the freeing of the inode. Introduced with "unfuck proc_sysctl ->d_compare()" + * + */ struct ctl_table_header { union { struct { struct ctl_table *ctl_table; + int ctl_table_size; int used; int count; int nreg; From patchwork Wed Jul 26 14:06:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 13328085 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 8BF4AC001DC for ; Wed, 26 Jul 2023 14:07:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234338AbjGZOHX (ORCPT ); Wed, 26 Jul 2023 10:07:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234359AbjGZOHD (ORCPT ); Wed, 26 Jul 2023 10:07:03 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AC752737 for ; Wed, 26 Jul 2023 07:06:57 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230726140655euoutp01255dd84244a51f63c42e42034ddd307f~1cAhAJUeB3202132021euoutp01Q for ; Wed, 26 Jul 2023 14:06:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230726140655euoutp01255dd84244a51f63c42e42034ddd307f~1cAhAJUeB3202132021euoutp01Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1690380415; bh=ZlhOJ8Gab+MSzPX9ZYs0a+yISdusJpdPSBybk1+HDeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GuLU8TiCaK8j7Z+zJmcO10ZpiLOMKNN761O2CbK3hV+PXUd/Ql3B5DaT473GZAWj3 SHLnHi/mjS21xdHNW+B1MYqpMnj5jFWfANQcl7aMsuoYslVvIuRHe4NQoOnNgKadB3 FqOrOKQC2byGoLn/naNabpDU0kY8svh+VnD2+wbg= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230726140655eucas1p1716d7debd87fd6db1c31cda39504208a~1cAgzGlbb2260622606eucas1p1t; Wed, 26 Jul 2023 14:06:55 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 10.F6.11320.F7821C46; Wed, 26 Jul 2023 15:06:55 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230726140655eucas1p1c71c8de9edc8441b5262c936731b91a2~1cAghMaJC1812118121eucas1p1A; Wed, 26 Jul 2023 14:06:55 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230726140655eusmtrp146bf937793ee3ac7ee9b51f49865bd32~1cAgggVUt2391823918eusmtrp19; Wed, 26 Jul 2023 14:06:55 +0000 (GMT) X-AuditID: cbfec7f4-993ff70000022c38-25-64c1287f3c72 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D3.C7.10549.F7821C46; Wed, 26 Jul 2023 15:06:55 +0100 (BST) Received: from localhost (unknown [106.210.248.223]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230726140655eusmtip12a0effc937e26b573d01a29cbefa6ae5~1cAgTexk92869028690eusmtip1e; Wed, 26 Jul 2023 14:06:55 +0000 (GMT) From: Joel Granados To: mcgrof@kernel.org, Kees Cook , Iurii Zaikin Cc: willy@infradead.org, josh@joshtriplett.org, Joel Granados , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 04/14] sysctl: Add size argument to init_header Date: Wed, 26 Jul 2023 16:06:24 +0200 Message-Id: <20230726140635.2059334-5-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230726140635.2059334-1-j.granados@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFKsWRmVeSWpSXmKPExsWy7djPc7r1GgdTDGY1qlos3f+Q0eL/gnyL M925Fnv2nmSxuLxrDpvFjQlPGS1+/wCylu30c+DwmN1wkcVjwaZSj80rtDxuvbb12LSqk82j b8sqRo/Pm+QC2KO4bFJSczLLUov07RK4Mj52b2EseCFcsW3iRbYGxiMCXYycHBICJhI7Zy5i BbGFBFYwSrxeHNHFyAVkf2GUaFpwnR3C+cwocaD3IxNMR+/pBywQieWMEuuP3maCcF4ySmz/ vJYdpIpNQEfi/Js7zF2MHBwiArESi6ekgISZBaYzSiyZIwNiCwvYS1xZeQ5sNYuAqsSMgysZ QWxeAVuJzitPmSGWyUu0XZ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nHmUASbAI6Euff3GEGsUUE4iVmPr7PBFLELDCbUWL1yUNg CWEBe4krK8+xgtgsAqoSMw6uZASxeQVsJTqvPGWG2CAv0XZ9OlicU8BOYuXa72D1QkA1PVOf skPUC0qcnPmEBcRmBqpv3jqbeQKjwCwkqVlIUgsYmVYxiqSWFuem5xYb6hUn5haX5qXrJefn bmIExsm2Yz8372Cc9+qj3iFGJg7GQ4wSHMxKIryGMftShHhTEiurUovy44tKc1KLDzGaAt09 kVlKNDkfGKl5JfGGZgamhiZmlgamlmbGSuK8ngUdiUIC6YklqdmpqQWpRTB9TBycUg1MtUkb 4jfuLX+nGb44uf32h7fZazhnXChmkO6Lry3WiD97Yf50F5PdaQm7bDjC+Nzml/ren7TVLmNP y2+D/Q85/+ZM1JFxuOcZpTA/UtluAUvnZ/vzOnybC+as8z//iy2AY2nvNeuNPybuqSurfSSs aW+6J+NCX33POskVj6/ZqL6Je7V+0iWLpuUfrBOKI94IvNaN0L9zZ+7e0wqrZy3TE54mG+6s 6vb730OJBr3TBW9Yv5YmzVp3/r5WkflWJZsXbr/U+PaLOUnf/eyzbwFv4apjPaL+QZH+R2o/ Vy7kfLrku8W2eQ8ONK80dii4aPeI72bpjqemRx+flftsrPJNtPyMtG/L21jFe6JLf7BfVmIp zkg01GIuKk4EAH43s0ocAwAA X-CMS-MailID: 20230726140655eucas1p1c71c8de9edc8441b5262c936731b91a2 X-Msg-Generator: CA X-RootMTR: 20230726140655eucas1p1c71c8de9edc8441b5262c936731b91a2 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230726140655eucas1p1c71c8de9edc8441b5262c936731b91a2 References: <20230726140635.2059334-1-j.granados@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In this commit, the size of the ctl_table array is passed to initialize the ctl_table_size element in the ctl_table_header struct. Although ctl_table_size is not currently used, this step prepares us for when we begin traversing the ctl_table array with it. In __register_sysctl_table we use a calculated size until we add the size argument to that function. Signed-off-by: Joel Granados --- fs/proc/proc_sysctl.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 884460b0385b..fa1438f1a355 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -188,9 +188,10 @@ static void erase_entry(struct ctl_table_header *head, struct ctl_table *entry) static void init_header(struct ctl_table_header *head, struct ctl_table_root *root, struct ctl_table_set *set, - struct ctl_node *node, struct ctl_table *table) + struct ctl_node *node, struct ctl_table *table, size_t table_size) { head->ctl_table = table; + head->ctl_table_size = table_size; head->ctl_table_arg = table; head->used = 0; head->count = 1; @@ -973,7 +974,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set, memcpy(new_name, name, namelen); table[0].procname = new_name; table[0].mode = S_IFDIR|S_IRUGO|S_IXUGO; - init_header(&new->header, set->dir.header.root, set, node, table); + init_header(&new->header, set->dir.header.root, set, node, table, 1); return new; } @@ -1197,7 +1198,8 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_ link_name += len; link++; } - init_header(links, dir->header.root, dir->header.set, node, link_table); + init_header(links, dir->header.root, dir->header.set, node, link_table, + head->ctl_table_size); links->nreg = nr_entries; return links; @@ -1372,7 +1374,7 @@ struct ctl_table_header *__register_sysctl_table( return NULL; node = (struct ctl_node *)(header + 1); - init_header(header, root, set, node, table); + init_header(header, root, set, node, table, nr_entries); if (sysctl_check_table(path, header)) goto fail; @@ -1537,7 +1539,7 @@ void setup_sysctl_set(struct ctl_table_set *set, { memset(set, 0, sizeof(*set)); set->is_seen = is_seen; - init_header(&set->dir.header, root, set, NULL, root_table); + init_header(&set->dir.header, root, set, NULL, root_table, 1); } void retire_sysctl_set(struct ctl_table_set *set) From patchwork Wed Jul 26 14:06:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 13328086 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 9E432C0015E for ; Wed, 26 Jul 2023 14:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233183AbjGZOHm (ORCPT ); Wed, 26 Jul 2023 10:07:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233868AbjGZOHG (ORCPT ); Wed, 26 Jul 2023 10:07:06 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6847F2D4E for ; Wed, 26 Jul 2023 07:06:59 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230726140658euoutp01274db3e1f2b51bae8604f0dfded62239~1cAjD1xYX3211332113euoutp01U for ; Wed, 26 Jul 2023 14:06:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230726140658euoutp01274db3e1f2b51bae8604f0dfded62239~1cAjD1xYX3211332113euoutp01U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1690380418; bh=uk1lVMRV3vGO5Qj9WjqlASY9SYqLs0/HcEQUQxX19Rw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EKAmgduM7qzb2gIDDmckuuVzf25+OAdO4ayEbPOT+yir3pA0BER3a2MX63wSH3eWW sTNl5PPj29iH8ZzwTXL49RvffUsKQElqVXaniGzXlxgnx2bmdqJoyALh2F8SDKbDF3 jtpD0M5ya253gi1NtX8OVUVfiSY8PkAwyBN2gLRI= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230726140657eucas1p15c9fb223083bdcc0cb2e453039297ba1~1cAicl1Jr2260622606eucas1p1v; Wed, 26 Jul 2023 14:06:57 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 23.F6.11320.18821C46; Wed, 26 Jul 2023 15:06:57 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230726140656eucas1p26cd9da21663d25b51dda75258aaa3b55~1cAh7604I0631806318eucas1p2d; Wed, 26 Jul 2023 14:06:56 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230726140656eusmtrp27aa5978c675164d2f45044b932f3fabb~1cAh7N5a32014720147eusmtrp2X; Wed, 26 Jul 2023 14:06:56 +0000 (GMT) X-AuditID: cbfec7f4-97dff70000022c38-2c-64c12881da24 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 41.57.14344.08821C46; Wed, 26 Jul 2023 15:06:56 +0100 (BST) Received: from localhost (unknown [106.210.248.223]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230726140656eusmtip1bd0558d02c1d90789e02183fa3849da1~1cAhrKSyu0800208002eusmtip1X; Wed, 26 Jul 2023 14:06:56 +0000 (GMT) From: Joel Granados To: mcgrof@kernel.org, Kees Cook , Iurii Zaikin , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: willy@infradead.org, josh@joshtriplett.org, Joel Granados , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 05/14] sysctl: Add a size arg to __register_sysctl_table Date: Wed, 26 Jul 2023 16:06:25 +0200 Message-Id: <20230726140635.2059334-6-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230726140635.2059334-1-j.granados@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02SeUwTURDG87rbdkFqtoXYEVEjnqBWMRrXA7x1NV6EaOIVaegGOVpMS/E2 KJeCNlhUQsVQL44qEGtFMVoQBayoKFBBPBBjNQoeCHIHbLsY/W/mm9+8b77kEZjIzPUkwhTR jFIhjfTmueJFFT3Pph+Zcl82M9cqpDKr43HKVvGBT10paUbUoD6KepIip54XabjU3XsWnKq9 k8mjGlJtiKrQj6A6q1oR1ddtl7KL1y8W0OdiX+C0Ke8Vh9Yb1fSNXF+6scWfNhqO8+gfZiuP 1pgMiG43jtnostV1oYyJDIthlDMCgl13vcqxYLsrJXvTU6y8WGSelIxcCCBng6FJjyUjV0JE 5iLQPj6B2KYDQZdJN9S0IyhLvMD/u6JLiMMctYjMQZBVx7DQFwQFpflcx4BHToPq1jfOdz3I NgSajMd8R4ORhQisHReRg3InabjcU+DcwMmJkJFqcVoISH/ozG/HWbuxkFif7uRdyADIy+/i sowQLBkfnQxmZ+JunsNYvpuAgevBbL0cas0ViK3d4WulaSiCFwwWZ3EcBwGZhqBk4Cefba4i yD7ym8NSCyC+7qN9QNgdfKDwzgxWXgK1318ihwzkcGj4JmRvGA7aonSMlQVwLFHE0hNAc+X0 UBRPqK8t5rE1DSXZCdxUNE73Xxrdf2l0/3z1CDMgMaNWyUMZ1SwFs0eikspVakWoJCRKbkT2 L1Y1UNlxG+V8bZOUIQ6ByhAQmLeHwG+7WSYSyKT79jPKqJ1KdSSjKkOjCNxbLJjqbwkRkaHS aCaCYXYzyr9TDuHiGcuBvoIw8Y60/vPJKTM1/NmTNcmTQdSyuWbt2ftJamEpc2zYA02P7UV5 eMqeLeMnrHy2LSP0/aWkwM8+h87k1/g++tRt9FgTzfk1JzPiMml4HV9K3E0YG5R0c564+mFx d8M6/YO61sq+H/vT621yqdesg37aXnz9p/nf322zBvfb8qo+lyiqjvK313fG+MSe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J6pkpn0kWLO4cbPBylX/CJsEtsiMh7n9D5tdBiW1ble9X6x2czT/0sv27l uijshOeCjLL7W4oEoieJq6qELuac058fpCagzW9mGf/vhu8q9g37KzpSZpqa17/Q5HoR0ssc eWCOQ8Zla505xdsWlc1lyuh/JlL6xdlxcv2JacG3TyqxFGckGmoxFxUnAgDdHjk0PwMAAA== X-CMS-MailID: 20230726140656eucas1p26cd9da21663d25b51dda75258aaa3b55 X-Msg-Generator: CA X-RootMTR: 20230726140656eucas1p26cd9da21663d25b51dda75258aaa3b55 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230726140656eucas1p26cd9da21663d25b51dda75258aaa3b55 References: <20230726140635.2059334-1-j.granados@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is part of the effort to remove the sentinel element in the ctl_table arrays. We add a table_size argument to __register_sysctl_table and adjust callers, all of which pass ctl_table pointers and need an explicit call to ARRAY_SIZE. The new table_size argument does not yet have any effect in the init_header call which is still dependent on the sentinel's presence. table_size *does* however drive the `kzalloc` allocation in __register_sysctl_table with no adverse effects as the allocated memory is either one element greater than the calculated ctl_table array (for the calls in ipc_sysctl.c, mq_sysctl.c and ucount.c) or the exact size of the calculated ctl_table array (for the call from sysctl_net.c and register_sysctl). This approach will allows us to "just" remove the sentinel without further changes to __register_sysctl_table as table_size will represent the exact size for all the callers at that point. Temporarily implement a size calculation in register_net_sysctl, which is an indirection call for all the network register calls. Signed-off-by: Joel Granados --- fs/proc/proc_sysctl.c | 22 +++++++++++----------- include/linux/sysctl.h | 2 +- ipc/ipc_sysctl.c | 4 +++- ipc/mq_sysctl.c | 4 +++- kernel/ucount.c | 3 ++- net/sysctl_net.c | 8 +++++++- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index fa1438f1a355..8d04f01a89c1 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1354,27 +1354,20 @@ static struct ctl_dir *sysctl_mkdir_p(struct ctl_dir *dir, const char *path) */ struct ctl_table_header *__register_sysctl_table( struct ctl_table_set *set, - const char *path, struct ctl_table *table) + const char *path, struct ctl_table *table, size_t table_size) { struct ctl_table_root *root = set->dir.header.root; struct ctl_table_header *header; - struct ctl_table_header h_tmp; struct ctl_dir *dir; - struct ctl_table *entry; struct ctl_node *node; - int nr_entries = 0; - - h_tmp.ctl_table = table; - list_for_each_table_entry(entry, (&h_tmp)) - nr_entries++; header = kzalloc(sizeof(struct ctl_table_header) + - sizeof(struct ctl_node)*nr_entries, GFP_KERNEL_ACCOUNT); + sizeof(struct ctl_node)*table_size, GFP_KERNEL_ACCOUNT); if (!header) return NULL; node = (struct ctl_node *)(header + 1); - init_header(header, root, set, node, table, nr_entries); + init_header(header, root, set, node, table, table_size); if (sysctl_check_table(path, header)) goto fail; @@ -1423,8 +1416,15 @@ struct ctl_table_header *__register_sysctl_table( */ struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table) { + int count = 0; + struct ctl_table *entry; + struct ctl_table_header t_hdr; + + t_hdr.ctl_table = table; + list_for_each_table_entry(entry, (&t_hdr)) + count++; return __register_sysctl_table(&sysctl_table_root.default_set, - path, table); + path, table, count); } EXPORT_SYMBOL(register_sysctl); diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 33252ad58ebe..0495c858989f 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -226,7 +226,7 @@ extern void retire_sysctl_set(struct ctl_table_set *set); struct ctl_table_header *__register_sysctl_table( struct ctl_table_set *set, - const char *path, struct ctl_table *table); + const char *path, struct ctl_table *table, size_t table_size); struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table); void unregister_sysctl_table(struct ctl_table_header * table); diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c index ef313ecfb53a..8c62e443f78b 100644 --- a/ipc/ipc_sysctl.c +++ b/ipc/ipc_sysctl.c @@ -259,7 +259,9 @@ bool setup_ipc_sysctls(struct ipc_namespace *ns) tbl[i].data = NULL; } - ns->ipc_sysctls = __register_sysctl_table(&ns->ipc_set, "kernel", tbl); + ns->ipc_sysctls = __register_sysctl_table(&ns->ipc_set, + "kernel", tbl, + ARRAY_SIZE(ipc_sysctls)); } if (!ns->ipc_sysctls) { kfree(tbl); diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c index fbf6a8b93a26..ebb5ed81c151 100644 --- a/ipc/mq_sysctl.c +++ b/ipc/mq_sysctl.c @@ -109,7 +109,9 @@ bool setup_mq_sysctls(struct ipc_namespace *ns) tbl[i].data = NULL; } - ns->mq_sysctls = __register_sysctl_table(&ns->mq_set, "fs/mqueue", tbl); + ns->mq_sysctls = __register_sysctl_table(&ns->mq_set, + "fs/mqueue", tbl, + ARRAY_SIZE(mq_sysctls)); } if (!ns->mq_sysctls) { kfree(tbl); diff --git a/kernel/ucount.c b/kernel/ucount.c index ee8e57fd6f90..2b80264bb79f 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -104,7 +104,8 @@ bool setup_userns_sysctls(struct user_namespace *ns) for (i = 0; i < UCOUNT_COUNTS; i++) { tbl[i].data = &ns->ucount_max[i]; } - ns->sysctls = __register_sysctl_table(&ns->set, "user", tbl); + ns->sysctls = __register_sysctl_table(&ns->set, "user", tbl, + ARRAY_SIZE(user_table)); } if (!ns->sysctls) { kfree(tbl); diff --git a/net/sysctl_net.c b/net/sysctl_net.c index 4b45ed631eb8..8ee4b74bc009 100644 --- a/net/sysctl_net.c +++ b/net/sysctl_net.c @@ -163,10 +163,16 @@ 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) { + int count = 0; + struct ctl_table *entry; + if (!net_eq(net, &init_net)) ensure_safe_net_sysctl(net, path, table); - return __register_sysctl_table(&net->sysctls, path, table); + for (entry = table; entry->procname; entry++) + count++; + + return __register_sysctl_table(&net->sysctls, path, table, count); } EXPORT_SYMBOL_GPL(register_net_sysctl); From patchwork Wed Jul 26 14:06:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 13328087 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 0A7EAC001B0 for ; Wed, 26 Jul 2023 14:08:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233279AbjGZOIM (ORCPT ); Wed, 26 Jul 2023 10:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234402AbjGZOHP (ORCPT ); Wed, 26 Jul 2023 10:07:15 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEE592D57 for ; Wed, 26 Jul 2023 07:07:01 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230726140700euoutp010ef241bfe1b15ac5e47fe479dd0f5cb6~1cAlcfW6k3202132021euoutp01W for ; Wed, 26 Jul 2023 14:07:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230726140700euoutp010ef241bfe1b15ac5e47fe479dd0f5cb6~1cAlcfW6k3202132021euoutp01W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1690380420; bh=l0L9NM3baww7PVLEXdKvMFx2kXphPK9z7x02k5Zm7P0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GaZxoBUp0wCR4r6ry2u8S1nlpqI/0qhL2+zbvIjyGJR+l3toEsBx2lbuszRlVdZuN a7u5sBbS7gNqEgWKaE7fYAt2x2czxScQ+8Qw80/uY3XSteIXks2Mt84KNlWh0SSdmw dolELmm/P+GgX1xIbOffGwpWjeDTt3xHs9OVnbUA= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230726140659eucas1p1999364497c41da742f5a590178eed9e0~1cAkx_DyJ2259322593eucas1p1k; Wed, 26 Jul 2023 14:06:59 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 27.F6.11320.38821C46; Wed, 26 Jul 2023 15:06:59 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230726140659eucas1p2c3cd9f57dd13c71ddeb78d2480587e72~1cAkRDtvl0079900799eucas1p2w; Wed, 26 Jul 2023 14:06:59 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230726140659eusmtrp23f74b881de77cedcdbb407cdb337d489~1cAkQSJFE2014720147eusmtrp2e; Wed, 26 Jul 2023 14:06:59 +0000 (GMT) X-AuditID: cbfec7f4-97dff70000022c38-36-64c12883b123 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 73.57.14344.38821C46; Wed, 26 Jul 2023 15:06:59 +0100 (BST) Received: from localhost (unknown [106.210.248.223]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230726140659eusmtip26b7013f9921e15f7a7bc21417164a14d~1cAj_0AFI2113521135eusmtip2C; Wed, 26 Jul 2023 14:06:59 +0000 (GMT) From: Joel Granados To: mcgrof@kernel.org, Catalin Marinas , Will Deacon , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Kees Cook , Iurii Zaikin , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: willy@infradead.org, josh@joshtriplett.org, Joel Granados , Christian Borntraeger , Sven Schnelle , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 06/14] sysctl: Add size to register_sysctl Date: Wed, 26 Jul 2023 16:06:26 +0200 Message-Id: <20230726140635.2059334-7-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230726140635.2059334-1-j.granados@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOKsWRmVeSWpSXmKPExsWy7djPc7rNGgdTDA6v1bfYePolm8Xjv4fY LN4v62G0mHO+hcXi6bFH7BYXZn1jtXg9bxWjxdL9Dxkt/i/ItzjTnWtxYVsfq8Wmx9dYLfbs PclicXnXHDaLCQubmS1uTHjKaHFsgZjFt9NvGC2WrV/LbtFyx9Ti9w+ggmU7/RzEPNbMW8Po MbvhIovHlpU3mTwWbCr12LxCy+PWa1uPTas62TwmLDrA6LF5Sb3H+31X2Tz6tqxi9Pi8SS6A J4rLJiU1J7MstUjfLoErY/qtDWwFHWYVz9efZmlgfK7TxcjJISFgIrH10EHWLkYuDiGBFYwS c/YtY4NwvjBKHNy+kQnC+cwosfvdPXaYlhenW6ESyxklnqzpYQZJCAm8ZJS4c9sGxGYT0JE4 /+YOM0iRiMAmZom73xaCOcwCZ5kkjq+fDDZKWMBKYtvfCUwgNouAqsTrvpdgk3gFbCWOrH3G ArFOXqLt+nRGEJtTwE5i5drvrBA1ghInZz4Bq2EGqmneOpsZov4ap8SE6WpdjBxAtovEtPPF EGFhiVfHt0B9ICPxf+d8sA8kBCYzSuz/94EdwlnNKLGs8SsTRJW1RMuVJ+wgg5gFNCXW79KH CDtKrPk5kw1iPp/EjbeCECfwSUzaNp0ZIswr0dEmBFGtItG3dArUJ1IS1y/vZIOwPSTWrj/H PoFRcRaSZ2Yhe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EJtXwFbiyNpnLBAb5CXark9nBLE5BewkVq79DjZHCKimZ+pTdoh6QYmT M5+wQMyXl2jeOpt5AqPALCSpWUhSCxiZVjGKpJYW56bnFhvpFSfmFpfmpesl5+duYgTG97Zj P7fsYFz56qPeIUYmDsZDjBIczEoivIYx+1KEeFMSK6tSi/Lji0pzUosPMZoC3T2RWUo0OR+Y YPJK4g3NDEwNTcwsDUwtzYyVxHk9CzoShQTSE0tSs1NTC1KLYPqYODilGpiinPWzzRwXTTw/ 73dG9sPzC6ct69rAHnGEZdtlV56fL45f6pKYN5lx5+ot1/zTbYu2vLc2a714qPL//5/T/63k 328/LenmJ58lepr/3oquurK1S2rzuVvhznpzrF40eXZ6NWzTs5NUznmd91vN+/QOhaIN94XX HLl47v6qp5nnYh6kBx5X+C80b6qlwXLps0lJyaFzD/p8atlwTjAq+T1HT0P6ph3t3qlflD+d v/mAIcolOP1B8JTJ784/uZR/4sBlG0a/tZMZVmjp6jPXzm2s+l2UtfHxtQoLz/UuK1hmNswN aF1/YcYEplgW24aVQnc1N6suX//1qqZmneq015HHbZbIzmN77PCGm/X2/cTgqUosxRmJhlrM RcWJAB+R3qZ4AwAA X-CMS-MailID: 20230726140659eucas1p2c3cd9f57dd13c71ddeb78d2480587e72 X-Msg-Generator: CA X-RootMTR: 20230726140659eucas1p2c3cd9f57dd13c71ddeb78d2480587e72 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230726140659eucas1p2c3cd9f57dd13c71ddeb78d2480587e72 References: <20230726140635.2059334-1-j.granados@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In order to remove the end element from the ctl_table struct arrays, we replace the register_syctl function with a macro that will add the ARRAY_SIZE to the new register_sysctl_sz function. In this way the callers that are already using an array of ctl_table structs do not have to change. We *do* change the callers that pass the ctl_table array as a pointer. Signed-off-by: Joel Granados --- arch/arm64/kernel/armv8_deprecated.c | 2 +- arch/s390/appldata/appldata_base.c | 2 +- fs/proc/proc_sysctl.c | 30 +++++++++++++++------------- include/linux/sysctl.h | 10 ++++++++-- kernel/ucount.c | 2 +- net/sysctl_net.c | 2 +- 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c index 1febd412b4d2..e459cfd33711 100644 --- a/arch/arm64/kernel/armv8_deprecated.c +++ b/arch/arm64/kernel/armv8_deprecated.c @@ -569,7 +569,7 @@ static void __init register_insn_emulation(struct insn_emulation *insn) sysctl->extra2 = &insn->max; sysctl->proc_handler = emulation_proc_handler; - register_sysctl("abi", sysctl); + register_sysctl_sz("abi", sysctl, 1); } } diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c index bbefe5e86bdf..3b0994625652 100644 --- a/arch/s390/appldata/appldata_base.c +++ b/arch/s390/appldata/appldata_base.c @@ -365,7 +365,7 @@ int appldata_register_ops(struct appldata_ops *ops) ops->ctl_table[0].proc_handler = appldata_generic_handler; ops->ctl_table[0].data = ops; - ops->sysctl_header = register_sysctl(appldata_proc_name, ops->ctl_table); + ops->sysctl_header = register_sysctl_sz(appldata_proc_name, ops->ctl_table, 1); if (!ops->sysctl_header) goto out; return 0; diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 8d04f01a89c1..c04293911e7e 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -43,7 +43,7 @@ static struct ctl_table sysctl_mount_point[] = { */ struct ctl_table_header *register_sysctl_mount_point(const char *path) { - return register_sysctl(path, sysctl_mount_point); + return register_sysctl_sz(path, sysctl_mount_point, 0); } EXPORT_SYMBOL(register_sysctl_mount_point); @@ -1398,7 +1398,7 @@ struct ctl_table_header *__register_sysctl_table( } /** - * register_sysctl - register a sysctl table + * register_sysctl_sz - register a sysctl table * @path: The path to the directory the sysctl table is in. If the path * doesn't exist we will create it for you. * @table: the table structure. The calller must ensure the life of the @table @@ -1408,25 +1408,20 @@ struct ctl_table_header *__register_sysctl_table( * to call unregister_sysctl_table() and can instead use something like * register_sysctl_init() which does not care for the result of the syctl * registration. + * @table_size: The number of elements in table. * * Register a sysctl table. @table should be a filled in ctl_table * array. A completely 0 filled entry terminates the table. * * See __register_sysctl_table for more details. */ -struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table) +struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table, + size_t table_size) { - int count = 0; - struct ctl_table *entry; - struct ctl_table_header t_hdr; - - t_hdr.ctl_table = table; - list_for_each_table_entry(entry, (&t_hdr)) - count++; return __register_sysctl_table(&sysctl_table_root.default_set, - path, table, count); + path, table, table_size); } -EXPORT_SYMBOL(register_sysctl); +EXPORT_SYMBOL(register_sysctl_sz); /** * __register_sysctl_init() - register sysctl table to path @@ -1451,10 +1446,17 @@ EXPORT_SYMBOL(register_sysctl); void __init __register_sysctl_init(const char *path, struct ctl_table *table, const char *table_name) { - struct ctl_table_header *hdr = register_sysctl(path, table); + int count = 0; + struct ctl_table *entry; + struct ctl_table_header t_hdr, *hdr; + + t_hdr.ctl_table = table; + list_for_each_table_entry(entry, (&t_hdr)) + count++; + hdr = register_sysctl_sz(path, table, count); if (unlikely(!hdr)) { - pr_err("failed when register_sysctl %s to %s\n", table_name, path); + pr_err("failed when register_sysctl_sz %s to %s\n", table_name, path); return; } kmemleak_not_leak(hdr); diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 0495c858989f..b1168ae281c9 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -215,6 +215,9 @@ struct ctl_path { const char *procname; }; +#define register_sysctl(path, table) \ + register_sysctl_sz(path, table, ARRAY_SIZE(table)) + #ifdef CONFIG_SYSCTL void proc_sys_poll_notify(struct ctl_table_poll *poll); @@ -227,7 +230,8 @@ extern void retire_sysctl_set(struct ctl_table_set *set); struct ctl_table_header *__register_sysctl_table( struct ctl_table_set *set, const char *path, struct ctl_table *table, size_t table_size); -struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table); +struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table, + size_t table_size); void unregister_sysctl_table(struct ctl_table_header * table); extern int sysctl_init_bases(void); @@ -262,7 +266,9 @@ static inline struct ctl_table_header *register_sysctl_mount_point(const char *p return NULL; } -static inline struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table) +static inline struct ctl_table_header *register_sysctl_sz(const char *path, + struct ctl_table *table, + size_t table_size) { return NULL; } diff --git a/kernel/ucount.c b/kernel/ucount.c index 2b80264bb79f..4aa6166cb856 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -365,7 +365,7 @@ static __init int user_namespace_sysctl_init(void) * default set so that registrations in the child sets work * properly. */ - user_header = register_sysctl("user", empty); + user_header = register_sysctl_sz("user", empty, 0); kmemleak_ignore(user_header); BUG_ON(!user_header); BUG_ON(!setup_userns_sysctls(&init_user_ns)); diff --git a/net/sysctl_net.c b/net/sysctl_net.c index 8ee4b74bc009..d9cbbb51b143 100644 --- a/net/sysctl_net.c +++ b/net/sysctl_net.c @@ -101,7 +101,7 @@ __init int net_sysctl_init(void) * registering "/proc/sys/net" as an empty directory not in a * network namespace. */ - net_header = register_sysctl("net", empty); + net_header = register_sysctl_sz("net", empty, 0); if (!net_header) goto out; ret = register_pernet_subsys(&sysctl_pernet_ops); From patchwork Wed Jul 26 14:06:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 13328088 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 910B9C0015E for ; Wed, 26 Jul 2023 14:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234228AbjGZOIO (ORCPT ); Wed, 26 Jul 2023 10:08:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234400AbjGZOHP (ORCPT ); Wed, 26 Jul 2023 10:07:15 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 593192688 for ; Wed, 26 Jul 2023 07:07:02 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230726140700euoutp0190f585839cce18a22abbc7a703084b62~1cAltdPSW3221432214euoutp01L for ; Wed, 26 Jul 2023 14:07:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230726140700euoutp0190f585839cce18a22abbc7a703084b62~1cAltdPSW3221432214euoutp01L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1690380420; bh=O9C8cu+eriqJgnbO4v2Z8b/dkIKixZDljclAYTZ36o0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qwTrNETLohSqW5oINSHaiw+BRoLXW4UBmr3d7nZYjDQbWNshhhM8jurvzhIOtDK4c QP+4oq76T/f4lm04LTtjaXTcxTPSjF+Y/lwRpPwk9UGOPxfuGad/yyyFEwMqCO5bzD alhawVDXskp841YewpEBmrtaKgsKqo5LslWwJv+o= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230726140700eucas1p23c3d90dc8d83fc17d20e7181ad9cdf58~1cAlgA4qF3020930209eucas1p2T; Wed, 26 Jul 2023 14:07:00 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id BC.66.42423.48821C46; Wed, 26 Jul 2023 15:07:00 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230726140700eucas1p1e6b16e884362ebec50f6712b3f11a533~1cAlMkQVf2040620406eucas1p1h; Wed, 26 Jul 2023 14:07:00 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230726140700eusmtrp23cb07803949101e69d6e6784132527b8~1cAlL-95p2014720147eusmtrp2g; Wed, 26 Jul 2023 14:07:00 +0000 (GMT) X-AuditID: cbfec7f2-a3bff7000002a5b7-79-64c1288491dd Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 05.57.14344.48821C46; Wed, 26 Jul 2023 15:07:00 +0100 (BST) Received: from localhost (unknown [106.210.248.223]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230726140700eusmtip26639b8677aab72762d4dfdf7367693e1~1cAk7WVCu2007220072eusmtip2G; Wed, 26 Jul 2023 14:07:00 +0000 (GMT) From: Joel Granados To: mcgrof@kernel.org, Kees Cook , Iurii Zaikin Cc: willy@infradead.org, josh@joshtriplett.org, Joel Granados , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 07/14] sysctl: Add size arg to __register_sysctl_init Date: Wed, 26 Jul 2023 16:06:27 +0200 Message-Id: <20230726140635.2059334-8-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230726140635.2059334-1-j.granados@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBKsWRmVeSWpSXmKPExsWy7djPc7otGgdTDHYsULFYuv8ho8X/BfkW Z7pzLfbsPclicXnXHDaLGxOeMlr8/gFkLdvp58DhMbvhIovHgk2lHptXaHncem3rsWlVJ5tH 35ZVjB6fN8kFsEdx2aSk5mSWpRbp2yVwZXTvfsNS0ChYcepUG0sD4xq+LkZODgkBE4n/7T2s XYxcHEICKxglDsy6wg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o/Pm+QC2KP0bIryS0tSFTLyi0tslaINLYz0DC0t9IxMLPUMjc1jrYxMlfTtbFJSczLL Uov07RL0Mrp3v2EpaBSsOHWqjaWBcQ1fFyMnh4SAicTn359Zuxi5OIQEljJK/Lz7j72LkQMo ISXxfRknRI2wxJ9rXWwQNc8ZJVau38AOkmAT0JE4/+YOM4gtIhAvMfPxfSaQImaB2YwSq08e AksIC7hK/Go9D2azCKhKLD65jAVkAa+ArcSa6aoQC+Ql2q5PZwSxOQXsJFau/c4KYgsBlfRM fQq2i1dAUOLkzCcsIDYzUH3z1tnMExgFZiFJzUKSWsDItIpRJLW0ODc9t9hIrzgxt7g0L10v OT93EyMwSrYd+7llB+PKVx/1DjEycTAeYpTgYFYS4TWM2ZcixJuSWFmVWpQfX1Sak1p8iNEU 6OyJzFKiyfnAOM0riTc0MzA1NDGzNDC1NDNWEuf1LOhIFBJITyxJzU5NLUgtgulj4uCUamBa wv5vmVce543wyHq5rhvfO278lvnwKOfW9FK9LY8bTvQ97j9TWK5QVcvR277nJcvTOQcuVl7b v2nGLmOZvMJNHQrVmRIuG/QeTY/edfzY4wtpn18I2asvXMmueHeFgv+aQyveLro38Q+TcsK/ LN4VT79KdkgZTojbsNF9qrDdN6UFUVXLsxvfckU/8uaeEtuRIOEk8YXBoTIgufzllzSXKveC P6bbrebc/NR5UWODnpmXV0iKYsbpWxabm0/Gf/aeOm3T6mUXw67n2075N/mFcrUKc/k390OZ Z9acv2p4L4BZ42Je6m7H1bOmyGzuY/8UeeFk8/XVd09cUll5Sni19y87yb2uzzmbjQ6rrD7U ocRSnJFoqMVcVJwIAN5IOfYbAwAA X-CMS-MailID: 20230726140700eucas1p1e6b16e884362ebec50f6712b3f11a533 X-Msg-Generator: CA X-RootMTR: 20230726140700eucas1p1e6b16e884362ebec50f6712b3f11a533 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230726140700eucas1p1e6b16e884362ebec50f6712b3f11a533 References: <20230726140635.2059334-1-j.granados@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is part of the effort to remove the sentinel element from the ctl_table array at register time. We add a size argument to __register_sysctl_init and modify the register_sysctl_init macro to calculate the array size with ARRAY_SIZE. The original callers do not need to be updated as they will go through the new macro. Signed-off-by: Joel Granados --- fs/proc/proc_sysctl.c | 11 ++--------- include/linux/sysctl.h | 5 +++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index c04293911e7e..6c0721cd35f3 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1444,16 +1444,9 @@ EXPORT_SYMBOL(register_sysctl_sz); * Context: if your base directory does not exist it will be created for you. */ void __init __register_sysctl_init(const char *path, struct ctl_table *table, - const char *table_name) + const char *table_name, size_t table_size) { - int count = 0; - struct ctl_table *entry; - struct ctl_table_header t_hdr, *hdr; - - t_hdr.ctl_table = table; - list_for_each_table_entry(entry, (&t_hdr)) - count++; - hdr = register_sysctl_sz(path, table, count); + struct ctl_table_header *hdr = register_sysctl_sz(path, table, table_size); if (unlikely(!hdr)) { pr_err("failed when register_sysctl_sz %s to %s\n", table_name, path); diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index b1168ae281c9..09d7429d67c0 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -236,8 +236,9 @@ void unregister_sysctl_table(struct ctl_table_header * table); extern int sysctl_init_bases(void); extern void __register_sysctl_init(const char *path, struct ctl_table *table, - const char *table_name); -#define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table) + const char *table_name, size_t table_size); +#define register_sysctl_init(path, table) \ + __register_sysctl_init(path, table, #table, ARRAY_SIZE(table)) extern struct ctl_table_header *register_sysctl_mount_point(const char *path); void do_sysctl_args(void); From patchwork Wed Jul 26 14:06:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 13328098 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 0DDF8C41513 for ; Wed, 26 Jul 2023 14:08:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234133AbjGZOIx (ORCPT ); Wed, 26 Jul 2023 10:08:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234396AbjGZOH4 (ORCPT ); Wed, 26 Jul 2023 10:07:56 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C3D42727 for ; Wed, 26 Jul 2023 07:07:16 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230726140714euoutp02ab2a4f5c09105826d68213726ffe6eee~1cAyymBL_1608116081euoutp02U for ; Wed, 26 Jul 2023 14:07:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230726140714euoutp02ab2a4f5c09105826d68213726ffe6eee~1cAyymBL_1608116081euoutp02U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1690380435; bh=y+3JcMDmwcBxmDJnO96kGfYESZ6WRSROP/M0qnZiaW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bn8TlKhaPm+ZoNVd1/sk8+To5fFDMyF8NWplF1EFtK0Ja4bYvIxtB9ek8mo548IZg qVrJ7TTRD0zEHi3nbJSRzRD6Z/UHSz/l6jmklfsW8lch+iL5j9gSe6xuqoPkxOaaOF n/QKCdN/Wc2bHqQAFpAaP7SRnOSQoz37IyoyIiZE= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230726140714eucas1p17067e35c5306c93c315855e164a426f4~1cAyiQPQ62256722567eucas1p1_; Wed, 26 Jul 2023 14:07:14 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 3D.76.42423.29821C46; Wed, 26 Jul 2023 15:07:14 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230726140714eucas1p186bad44daf14c4c8c93f9aaf52deade5~1cAyRGU8u2041620416eucas1p1-; Wed, 26 Jul 2023 14:07:14 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230726140714eusmtrp17d12f7d118f120e8c898b69e46e1046a~1cAyQjihf2411224112eusmtrp1b; Wed, 26 Jul 2023 14:07:14 +0000 (GMT) X-AuditID: cbfec7f2-a3bff7000002a5b7-b0-64c12892eb80 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id B3.67.14344.29821C46; Wed, 26 Jul 2023 15:07:14 +0100 (BST) Received: from localhost (unknown [106.210.248.223]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230726140714eusmtip1e2ad697c5d7344b8bd32e0d7e06a4b6a~1cAyDjtKe0954609546eusmtip1X; Wed, 26 Jul 2023 14:07:14 +0000 (GMT) From: Joel Granados To: mcgrof@kernel.org, Kees Cook , Iurii Zaikin Cc: willy@infradead.org, josh@joshtriplett.org, Joel Granados , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 14/14] sysctl: Use size as stopping criteria for list macro Date: Wed, 26 Jul 2023 16:06:34 +0200 Message-Id: <20230726140635.2059334-15-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230726140635.2059334-1-j.granados@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01SeUxScRzvx3vAk0Jf5OI7ZGkGyy6PYg3zbNZGp3bNDlsxeKkT0fGkzNWy u6y8Ukm0zRVZis6NLirNIsvMssyWrexaWh65NDNsNk18tPrvc32v7UtgAiNbRMRrUyidVqnx 5vDwaw9+Nc3L9bmr9s+wSuUXaj8i+WhJkvzxiUR5dU0DLm+5WcyRv8ruQPLhoTFUemN1OKEo Sm/GFSUWveLypdmK1z0hCkv5cY4i80o5UgxYpkVxN/OC1ZQmfiel8wvdzosr/tXATTbwUofe ytLRPSIDuRBAyiCnfwTPQDxCQF5CMGCzOMkPBE967iCGDCB4N2LG/pZU3bJjjHERwYu6g07S haDzUyfXkeKQc+Hp17YxgyDcya1wPk/tkDHSgMBULHbgKeQKyDE1IgfGSSmMfrSxHZhPhoLN XsBmhnnCkVbDeMZlTC+rtDszk6GhsB1nenrCwatF4zsA+ZCAB1kVOFO8BN6brjobTYHu+itc Bouh8fRJnCk4jaB2pI/LEDOC0v2DLCYVBIdetHMdF2DkLKi66cfIi6Em6xbukIF0hVe9k5kl XCH3mgFjZD4cOyJg0hLIvJDnXEcErS03OAxWQNHvVnY2mm787xzjf+cY/80tQVg5ElJ6OjGW ogO01C5fWplI67WxvqqkRAsae5/GkfrvVnS2u9/XhlgEsiEgMG93fkDMbbWAr1buTqN0Sdt0 eg1F25AHgXsL+XNCGlQCMlaZQiVQVDKl++uyCBdROmtroXvWl+uR+Su9ot08xcurC18fmBgt kfp49MlExJYlh1XrZrlZzxXNaA18TFSE/az4bNqr32BUqpKW1S7fIQl/FLZ44caIVaW3O7u8 Bg2xK4vJfeKXEwc3RT17meI5v/7YF4tYz65r7gwsXaQNCmtsar7PEvoHPcyXtuW6RkzgfuYI Zf0JEbLVe98cTZiZqhL09MYJy4fz3Gdopg1WVvKj3mAc29Nv6+2mR8Lz8+oyaxa0e/Unl53c kB1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5 6C+HrcU2jpO77hd8c8pS7Pf36Wdr3Lxpcah/hpaUjd6J0vmrlN+4GTn7inl+7r3gslx3qhJL cUaioRZzUXEiAEYQkfAaAwAA X-CMS-MailID: 20230726140714eucas1p186bad44daf14c4c8c93f9aaf52deade5 X-Msg-Generator: CA X-RootMTR: 20230726140714eucas1p186bad44daf14c4c8c93f9aaf52deade5 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230726140714eucas1p186bad44daf14c4c8c93f9aaf52deade5 References: <20230726140635.2059334-1-j.granados@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add header->ctl_table_size as an additional stopping criteria for the list_for_each_table_entry macro. In this way it will execute until it finds an "empty" ->procname or until the size runs out. Therefore if a ctl_table array with a sentinel is passed its size will be too big (by one element) but it will stop on the sentinel. On the other hand, if the ctl_table array without a sentinel is passed its size will be just write and there will be no need for a sentinel. Signed-off-by: Joel Granados --- fs/proc/proc_sysctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 6c0721cd35f3..3eea34d98d54 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -19,8 +19,9 @@ #include #include "internal.h" -#define list_for_each_table_entry(entry, header) \ - for ((entry) = (header->ctl_table); (entry)->procname; (entry)++) +#define list_for_each_table_entry(entry, header) \ + entry = header->ctl_table; \ + for (size_t i = 0 ; i < header->ctl_table_size && entry->procname; ++i, entry++) static const struct dentry_operations proc_sys_dentry_operations; static const struct file_operations proc_sys_file_operations;