Skip to contentSkip to conversation

sysctl: move umh and keys sysctls

PATCH In review Luis Chamberlain 4 participants 8 messages May 30, 2023 – Jun 7, 2023

Subsystems (5)
lore
Share & tools
lore

Luis Chamberlain

author maintainer
#0 lore raw

cover sysctl: move umh and keys sysctls

If you look at kernel/sysctl.c there are two sysctl arrays which are declared in header files but registered with no good reason now on kernel/sysctl.c instead of the place they belong. So just do the registration where it belongs.

The penalty of this is just 66 bytes for moving both registrations to its own file, but soon we'll be removing all sysctl empty entries at each array, and we've already done tons of cleanup on fs/proc/proc_sysctl.c which saved us hundreds of bytes so we have few karma points.

With this, we no now only have two sysctl arrays left to start clearing up the kernel one and the vm one.

Luis Chamberlain (2):
sysctl: move umh sysctl registration to its own file
sysctl: move security keys sysctl registration to its own file

 include/linux/key.h    |  3 ---
 include/linux/umh.h    |  2 --
 kernel/sysctl.c        |  5 -----
 kernel/umh.c           | 11 ++++++++++-
 security/keys/sysctl.c |  7 +++++++
 5 files changed, 17 insertions(+), 11 deletions(-)
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH 1/2 sysctl: move umh sysctl registration to its own file

Move the umh sysctl registration to its own file, the array is already there. We do this to remove the clutter out of kernel/sysctl.c to avoid merge conflicts.

This also lets the sysctls not be built at all now when CONFIG_SYSCTL is not enabled.

This has a small penalty of 23 bytes but soon we'll be removing all the empty entries on sysctl arrays so just do this cleanup now:

./scripts/bloat-o-meter vmlinux.base vmlinux.1 add/remove: 2/0 grow/shrink: 0/1 up/down: 49/-26 (23)
Function old new delta

init_umh_sysctls                               -      33     +33
__pfx_init_umh_sysctls                         -      16     +16
sysctl_init_bases                            111      85     -26

Total: Before=21256914, After=21256937, chg +0.00%

---
 include/linux/umh.h |  2 --
 kernel/sysctl.c     |  1 -
 kernel/umh.c        | 11 ++++++++++-
 3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/umh.h +0 -2
index 5d1f6129b847..daa6a7048c11 100644
@@ -42,8 +42,6 @@ call_usermodehelper_setup(const char *path, char **argv, char **envp,
 extern int
 call_usermodehelper_exec(struct subprocess_info *info, int wait);
 
-extern struct ctl_table usermodehelper_table[];
-
 enum umh_disable_depth {
 	UMH_ENABLED = 0,
 	UMH_FREEZING,
kernel/sysctl.c +0 -1
index 241b817c0240..caf4a91522a1 100644
@@ -2322,7 +2322,6 @@ static struct ctl_table vm_table[] = {
 int __init sysctl_init_bases(void)
 {
 	register_sysctl_init("kernel", kern_table);
-	register_sysctl_init("kernel/usermodehelper", usermodehelper_table);
 #ifdef CONFIG_KEYS
 	register_sysctl_init("kernel/keys", key_sysctls);
 #endif
kernel/umh.c +10 -1
index 60aa9e764a38..41088c5c39fd 100644
@@ -544,7 +544,8 @@ static int proc_cap_handler(struct ctl_table *table, int write,
 	return 0;
 }
 
-struct ctl_table usermodehelper_table[] = {
+#if defined(CONFIG_SYSCTL)
+static struct ctl_table usermodehelper_table[] = {
 	{
 		.procname	= "bset",
 		.data		= &usermodehelper_bset,
@@ -561,3 +562,11 @@ struct ctl_table usermodehelper_table[] = {
 	},
 	{ }
 };
+
+static int __init init_umh_sysctls(void)
+{
+	register_sysctl_init("kernel/usermodehelper", usermodehelper_table);
+	return 0;
+}
+early_initcall(init_umh_sysctls);
+#endif /* CONFIG_SYSCTL */
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH 2/2 sysctl: move security keys sysctl registration to its own file

In reply to Luis Chamberlain

The security keys sysctls are already declared on its own file, just move the sysctl registration to its own file to help avoid merge conflicts on sysctls.c, and help with clearing up sysctl.c further.

This creates a small penalty of 23 bytes:

./scripts/bloat-o-meter vmlinux.1 vmlinux.2 add/remove: 2/0 grow/shrink: 0/1 up/down: 49/-26 (23)
Function old new delta

init_security_keys_sysctls                     -      33     +33
__pfx_init_security_keys_sysctls               -      16     +16
sysctl_init_bases                             85      59     -26

Total: Before=21256937, After=21256960, chg +0.00%

But soon we'll be saving tons of bytes anyway, as we modify the sysctl registrations to use ARRAY_SIZE and so we get rid of all the empty array elements so let's just clean this up now.

---
 include/linux/key.h    | 3 ---
 kernel/sysctl.c        | 4 ----
 security/keys/sysctl.c | 7 +++++++
 3 files changed, 7 insertions(+), 7 deletions(-)
include/linux/key.h +0 -3
index 8dc7f7c3088b..938d7ecfb495 100644
@@ -490,9 +490,6 @@ do {									\
 	rcu_assign_pointer((KEY)->payload.rcu_data0, (PAYLOAD));	\
 } while (0)
 
-#ifdef CONFIG_SYSCTL
-extern struct ctl_table key_sysctls[];
-#endif
 /*
  * the userspace interface
  */
kernel/sysctl.c +0 -4
index caf4a91522a1..48046932d573 100644
@@ -2322,10 +2322,6 @@ static struct ctl_table vm_table[] = {
 int __init sysctl_init_bases(void)
 {
 	register_sysctl_init("kernel", kern_table);
-#ifdef CONFIG_KEYS
-	register_sysctl_init("kernel/keys", key_sysctls);
-#endif
-
 	register_sysctl_init("vm", vm_table);
 
 	return 0;
security/keys/sysctl.c +7 -0
index b46b651b3c4c..b72b82bb20c6 100644
@@ -68,3 +68,10 @@ struct ctl_table key_sysctls[] = {
 #endif
 	{ }
 };
+
+static int __init init_security_keys_sysctls(void)
+{
+	register_sysctl_init("kernel/keys", key_sysctls);
+	return 0;
+}
+early_initcall(init_security_keys_sysctls);
Signature · 1 line
2.39.2
maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] sysctl: move security keys sysctl registration to its own file

Quoted 20 lines · Luis Chamberlain

The security keys sysctls are already declared on its own file, just move the sysctl registration to its own file to help avoid merge conflicts on sysctls.c, and help with clearing up sysctl.c further.

This creates a small penalty of 23 bytes:

./scripts/bloat-o-meter vmlinux.1 vmlinux.2 add/remove: 2/0 grow/shrink: 0/1 up/down: 49/-26 (23)
Function old new delta

init_security_keys_sysctls                     -      33     +33
__pfx_init_security_keys_sysctls               -      16     +16
sysctl_init_bases                             85      59     -26

Total: Before=21256937, After=21256960, chg +0.00%

But soon we'll be saving tons of bytes anyway, as we modify the sysctl registrations to use ARRAY_SIZE and so we get rid of all the empty array elements so let's just clean this up now.

Quoted 6 lines
---
 include/linux/key.h    | 3 ---
 kernel/sysctl.c        | 4 ----
 security/keys/sysctl.c | 7 +++++++
 3 files changed, 7 insertions(+), 7 deletions(-)

Ultimately I'll leave the ACK to David or Jarkko, but this looks reasonable to me.

Signature · 1 line
paul-moore.com
author maintainer
#5 lore raw

Re: [PATCH 2/2] sysctl: move security keys sysctl registration to its own file

Quoted 28 lines · Paul Moore
Quoted 20 lines · Luis Chamberlain

The security keys sysctls are already declared on its own file, just move the sysctl registration to its own file to help avoid merge conflicts on sysctls.c, and help with clearing up sysctl.c further.

This creates a small penalty of 23 bytes:

./scripts/bloat-o-meter vmlinux.1 vmlinux.2 add/remove: 2/0 grow/shrink: 0/1 up/down: 49/-26 (23)
Function old new delta

init_security_keys_sysctls                     -      33     +33
__pfx_init_security_keys_sysctls               -      16     +16
sysctl_init_bases                             85      59     -26

Total: Before=21256937, After=21256960, chg +0.00%

But soon we'll be saving tons of bytes anyway, as we modify the sysctl registrations to use ARRAY_SIZE and so we get rid of all the empty array elements so let's just clean this up now.

Quoted 6 lines
---
 include/linux/key.h    | 3 ---
 kernel/sysctl.c        | 4 ----
 security/keys/sysctl.c | 7 +++++++
 3 files changed, 7 insertions(+), 7 deletions(-)
Quoted 4 lines

Ultimately I'll leave the ACK to David or Jarkko, but this looks reasonable to me.

I've queued this onto sysctl-next as I haven't seen any complaints. I can drop it if there are complaints or regressions reported by folks on linux-next.

Luis

maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] sysctl: move umh sysctl registration to its own file

In reply to Luis Chamberlain
Quoted 17 lines · Luis Chamberlain

Move the umh sysctl registration to its own file, the array is already there. We do this to remove the clutter out of kernel/sysctl.c to avoid merge conflicts.

This also lets the sysctls not be built at all now when CONFIG_SYSCTL is not enabled.

This has a small penalty of 23 bytes but soon we'll be removing all the empty entries on sysctl arrays so just do this cleanup now:

./scripts/bloat-o-meter vmlinux.base vmlinux.1 add/remove: 2/0 grow/shrink: 0/1 up/down: 49/-26 (23)
Function old new delta

init_umh_sysctls                               -      33     +33
__pfx_init_umh_sysctls                         -      16     +16
sysctl_init_bases                            111      85     -26
Quoted 8 lines

Total: Before=21256914, After=21256937, chg +0.00%

---
 include/linux/umh.h |  2 --
 kernel/sysctl.c     |  1 -
 kernel/umh.c        | 11 ++++++++++-
 3 files changed, 10 insertions(+), 4 deletions(-)

BR, Jarkko

maintainer Acked-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] sysctl: move security keys sysctl registration to its own file

In reply to Luis Chamberlain
Quoted 19 lines · Luis Chamberlain

The security keys sysctls are already declared on its own file, just move the sysctl registration to its own file to help avoid merge conflicts on sysctls.c, and help with clearing up sysctl.c further.

This creates a small penalty of 23 bytes:

./scripts/bloat-o-meter vmlinux.1 vmlinux.2 add/remove: 2/0 grow/shrink: 0/1 up/down: 49/-26 (23)
Function old new delta

init_security_keys_sysctls                     -      33     +33
__pfx_init_security_keys_sysctls               -      16     +16
sysctl_init_bases                             85      59     -26

Total: Before=21256937, After=21256960, chg +0.00%

But soon we'll be saving tons of bytes anyway, as we modify the sysctl registrations to use ARRAY_SIZE and so we get rid of all the empty array elements so let's just clean this up now.

Quoted 6 lines
---
 include/linux/key.h    | 3 ---
 kernel/sysctl.c        | 4 ----
 security/keys/sysctl.c | 7 +++++++
 3 files changed, 7 insertions(+), 7 deletions(-)

BR, Jarkko

maintainer Acked-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] sysctl: move security keys sysctl registration to its own file

In reply to Luis Chamberlain
Quoted 13 lines · Luis Chamberlain

The security keys sysctls are already declared on its own file, just move the sysctl registration to its own file to help avoid merge conflicts on sysctls.c, and help with clearing up sysctl.c further.

This creates a small penalty of 23 bytes:

./scripts/bloat-o-meter vmlinux.1 vmlinux.2 add/remove: 2/0 grow/shrink: 0/1 up/down: 49/-26 (23)
Function old new delta

init_security_keys_sysctls                     -      33     +33
__pfx_init_security_keys_sysctls               -      16     +16
sysctl_init_bases                             85      59     -26
Quoted 7 lines

Total: Before=21256937, After=21256960, chg +0.00%

But soon we'll be saving tons of bytes anyway, as we modify the sysctl registrations to use ARRAY_SIZE and so we get rid of all the empty array elements so let's just clean this up now.