[PATCH RFC 9/9] ucount: Register user_table as a template
From: Joel Granados
Date: Thu Nov 26 2026 - 06:49:12 EST
Add SYSCTL_OVERLAY_DATA to UCOUNT_ENTRY() so every entry of user_table
carries it, and register the table through
__register_sysctl_table_tmpl(), passing the copy that
setup_userns_sysctls() already fills by position as the overlay. Free
the copy once the call returns and stop freeing ctl_table_arg in
retire_userns_sysctls().
Signed-off-by: Joel Granados <joel.granados@xxxxxxxxxx>
---
kernel/ucount.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/kernel/ucount.c b/kernel/ucount.c
index 94b70502dc9ded4de4a946b73141119efc3a26fe..bf021247f5ee5999f3c298e318c25dc2164a8c9b 100644
--- a/kernel/ucount.c
+++ b/kernel/ucount.c
@@ -69,6 +69,7 @@ static long ue_int_max = INT_MAX;
.procname = name, \
.maxlen = sizeof(long), \
.mode = 0644, \
+ .flags = SYSCTL_OVERLAY_DATA, \
.proc_handler = proc_doulongvec_minmax, \
.extra1 = &ue_zero, \
.extra2 = &ue_int_max, \
@@ -109,11 +110,12 @@ 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,
- ARRAY_SIZE(user_table));
- }
- if (!ns->sysctls) {
+ ns->sysctls = __register_sysctl_table_tmpl(&ns->set, "user",
+ CTL_TABLE_TMPL(user_table),
+ tbl, ARRAY_SIZE(user_table));
kfree(tbl);
+ }
+ if (!ns->sysctls) {
retire_sysctl_set(&ns->set);
return false;
}
@@ -124,12 +126,8 @@ bool setup_userns_sysctls(struct user_namespace *ns)
void retire_userns_sysctls(struct user_namespace *ns)
{
#ifdef CONFIG_SYSCTL
- const struct ctl_table *tbl;
-
- tbl = ns->sysctls->ctl_table_arg;
unregister_sysctl_table(ns->sysctls);
retire_sysctl_set(&ns->set);
- kfree(tbl);
#endif
}
--
2.50.1