The 'struct ctl_table.procname' field (sysctl filename) cannot be accessed by scripts since it is defined in kernel headers (see "don't include kernel headers into userspace" in file2alias.c) and its offset may be randomized.
Unrandomize '.procname' as the first field so its offset is always zero and match the 'struct ctl_table' symbol address, which can be found by scripts. Originally-by: Mauricio Faria de Oliveira <[email protected]> Signed-off-by: Mauricio Faria de Oliveira <[email protected]> --- include/linux/sysctl.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 7e05fafd5544e1c4a3283dc13b0692f39515d01e..120c0f05bd083e08d8104ff05136138f2e8cdb07 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -220,7 +220,14 @@ static inline void *proc_sys_poll_event(struct ctl_table_poll *poll) /* A sysctl table is an array of struct ctl_table: */ struct ctl_table { + + /* This must be the first field for module aliases (file2alias.c) */ const char *procname; /* Text ID for /proc/sys */ + +#ifdef CONFIG_SYSCTL_MODULE_ALIASES + /* This begins the randomizable portion of the struct. */ + randomized_struct_fields_start +#endif void *data; int maxlen; umode_t mode; @@ -228,7 +235,14 @@ struct ctl_table { struct ctl_table_poll *poll; void *extra1; void *extra2; +#ifdef CONFIG_SYSCTL_MODULE_ALIASES + /* New fields go above here, so they are in the randomized portion. */ + randomized_struct_fields_end +}; +static_assert(offsetof(const struct ctl_table, procname) == 0); +#else } __randomize_layout; +#endif struct ctl_node { struct rb_node node; -- 2.47.3

