From cec030ec414ec94fb25b49da688eea264e054e42 Mon Sep 17 00:00:00 2001 From: Joel Granados Date: Fri, 26 Jan 2024 12:53:10 +0100 Subject: [PATCH 1/4] MAINTAINERS: Update sysctl tree location To more efficiently co-maintain the sysctl subsystem a shared repository has been created at https://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl.git and the sysctl-next branch that Luis Chamberlain (mcgrof@kernel.org) maintained at https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=sysctl-next has moved to the shared sysctl-next branch located at https://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl.git/log/?h=sysctl-next. This commit changes the sysctl tree in MAINTAINERS to reflect this change. Acked-by: Kees Cook Acked-by: Luis Chamberlain Signed-off-by: Joel Granados --- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 8d1052fa6a69..adf69ab891e0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17616,7 +17616,7 @@ M: Joel Granados L: linux-kernel@vger.kernel.org L: linux-fsdevel@vger.kernel.org S: Maintained -T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git sysctl-next +T: git git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl.git sysctl-next F: fs/proc/proc_sysctl.c F: include/linux/sysctl.h F: kernel/sysctl-test.c From 0f6588b351d4fbec8f8e63e99df20fec6f121e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 19 Feb 2024 21:19:22 +0100 Subject: [PATCH 2/4] scripts: check-sysctl-docs: adapt to new API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The script expects the old sysctl_register_paths() API which was removed some time ago. Adapt it to work with the new sysctl_register()/sysctl_register_sz()/sysctl_register_init() APIs. Signed-off-by: Thomas Weißschuh Reviewed-by: Joel Granados Signed-off-by: Joel Granados --- scripts/check-sysctl-docs | 45 +++++++++++---------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/scripts/check-sysctl-docs b/scripts/check-sysctl-docs index 4f163e0bf6a4..739afd766708 100755 --- a/scripts/check-sysctl-docs +++ b/scripts/check-sysctl-docs @@ -8,7 +8,7 @@ # Example invocation: # scripts/check-sysctl-docs -vtable="kernel" \ # Documentation/admin-guide/sysctl/kernel.rst \ -# $(git grep -l register_sysctl_) +# $(git grep -l register_sysctl) # # Specify -vdebug=1 to see debugging information @@ -20,14 +20,10 @@ BEGIN { } # The following globals are used: -# children: maps ctl_table names and procnames to child ctl_table names # documented: maps documented entries (each key is an entry) # entries: maps ctl_table names and procnames to counts (so # enumerating the subkeys for a given ctl_table lists its # procnames) -# files: maps procnames to source file names -# paths: maps ctl_path names to paths -# curpath: the name of the current ctl_path struct # curtable: the name of the current ctl_table struct # curentry: the name of the current proc entry (procname when parsing # a ctl_table, constructed path when parsing a ctl_path) @@ -94,44 +90,23 @@ FNR == NR { # Stage 2: process each file and find all sysctl tables BEGINFILE { - delete children delete entries - delete paths - curpath = "" curtable = "" curentry = "" if (debug) print "Processing file " FILENAME } -/^static struct ctl_path/ { - match($0, /static struct ctl_path ([^][]+)/, tables) - curpath = tables[1] - if (debug) print "Processing path " curpath -} - -/^static struct ctl_table/ { - match($0, /static struct ctl_table ([^][]+)/, tables) - curtable = tables[1] +/^static( const)? struct ctl_table/ { + match($0, /static( const)? struct ctl_table ([^][]+)/, tables) + curtable = tables[2] if (debug) print "Processing table " curtable } /^};$/ { - curpath = "" curtable = "" curentry = "" } -curpath && /\.procname[\t ]*=[\t ]*".+"/ { - match($0, /.procname[\t ]*=[\t ]*"([^"]+)"/, names) - if (curentry) { - curentry = curentry "/" names[1] - } else { - curentry = names[1] - } - if (debug) print "Setting path " curpath " to " curentry - paths[curpath] = curentry -} - curtable && /\.procname[\t ]*=[\t ]*".+"/ { match($0, /.procname[\t ]*=[\t ]*"([^"]+)"/, names) curentry = names[1] @@ -140,10 +115,14 @@ curtable && /\.procname[\t ]*=[\t ]*".+"/ { file[curentry] = FILENAME } -/\.child[\t ]*=/ { - child = trimpunct($NF) - if (debug) print "Linking child " child " to table " curtable " entry " curentry - children[curtable][curentry] = child +/register_sysctl.*/ { + match($0, /register_sysctl(|_init|_sz)\("([^"]+)" *, *([^,)]+)/, tables) + if (debug) print "Registering table " tables[3] " at " tables[2] + if (tables[2] == table) { + for (entry in entries[tables[3]]) { + printentry(entry) + } + } } END { From 8e88291043155956c2851c44e8fd0a562ea2ee49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 19 Feb 2024 21:19:23 +0100 Subject: [PATCH 3/4] ipc: remove linebreaks from arguments of __register_sysctl_table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calls to __register_sysctl_table will be validated by scripts/check-sysctl-docs. As this script is line-based remove the linebreak which would confuse the script. Signed-off-by: Thomas Weißschuh Reviewed-by: Joel Granados Signed-off-by: Joel Granados --- ipc/ipc_sysctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c index 8c62e443f78b..e4008288a3ba 100644 --- a/ipc/ipc_sysctl.c +++ b/ipc/ipc_sysctl.c @@ -259,8 +259,7 @@ 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) { From 4f1136a55dc8e2c27d51e934d0675e12331c7291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 19 Feb 2024 21:19:24 +0100 Subject: [PATCH 4/4] scripts: check-sysctl-docs: handle per-namespace sysctls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some sysctl tables are registered for each namespace. (Like in ipc/ipc_sysctl.c) These need special handling to track the variable assignments. Signed-off-by: Thomas Weißschuh Reviewed-by: Joel Granados Signed-off-by: Joel Granados --- scripts/check-sysctl-docs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/check-sysctl-docs b/scripts/check-sysctl-docs index 739afd766708..20274c63e745 100755 --- a/scripts/check-sysctl-docs +++ b/scripts/check-sysctl-docs @@ -93,6 +93,7 @@ BEGINFILE { delete entries curtable = "" curentry = "" + delete vars if (debug) print "Processing file " FILENAME } @@ -105,6 +106,7 @@ BEGINFILE { /^};$/ { curtable = "" curentry = "" + delete vars } curtable && /\.procname[\t ]*=[\t ]*".+"/ { @@ -125,6 +127,24 @@ curtable && /\.procname[\t ]*=[\t ]*".+"/ { } } +/kmemdup.*/ { + match($0, /([^ \t]+) *= *kmemdup\(([^,]+) *,/, names) + if (debug) print "Found variable " names[1] " for table " names[2] + if (names[2] in entries) { + vars[names[1]] = names[2] + } +} + +/__register_sysctl_table.*/ { + match($0, /__register_sysctl_table\([^,]+, *"([^"]+)" *, *([^,]+)/, tables) + if (debug) print "Registering variable table " tables[2] " at " tables[1] + if (tables[1] == table && tables[2] in vars) { + for (entry in entries[vars[tables[2]]]) { + printentry(entry) + } + } +} + END { for (entry in documented) { if (!seen[entry]) {