The patch titled Subject: sysctl: add helper to register a sysctl mount point has been added to the -mm tree. Its filename is sysctl-add-helper-to-register-a-sysctl-mount-point.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/sysctl-add-helper-to-register-a-sysctl-mount-point.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/sysctl-add-helper-to-register-a-sysctl-mount-point.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Luis Chamberlain <mcgrof@xxxxxxxxxx> Subject: sysctl: add helper to register a sysctl mount point The way to create a subdirectory on top of sysctl_mount_point is a bit obscure, and *why* we do that even so more. Provide a helper which makes it clear why we do this. Link: https://lkml.kernel.org/r/20211124231435.1445213-4-mcgrof@xxxxxxxxxx Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx> Suggested-by: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: Amir Goldstein <amir73il@xxxxxxxxx> Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> Cc: Antti Palosaari <crope@xxxxxx> Cc: Arnd Bergmann <arnd@xxxxxxxx> Cc: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx> Cc: Benjamin LaHaise <bcrl@xxxxxxxxx> Cc: Clemens Ladisch <clemens@xxxxxxxxxx> Cc: David Airlie <airlied@xxxxxxxx> Cc: Douglas Gilbert <dgilbert@xxxxxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: Iurii Zaikin <yzaikin@xxxxxxxxxx> Cc: James E.J. Bottomley <jejb@xxxxxxxxxxxxx> Cc: Jani Nikula <jani.nikula@xxxxxxxxx> Cc: Jani Nikula <jani.nikula@xxxxxxxxxxxxxxx> Cc: Jan Kara <jack@xxxxxxx> Cc: Joel Becker <jlbec@xxxxxxxxxxxx> Cc: John Ogness <john.ogness@xxxxxxxxxxxxx> Cc: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx> Cc: Joseph Qi <joseph.qi@xxxxxxxxxxxxxxxxx> Cc: Julia Lawall <julia.lawall@xxxxxxxx> Cc: Kees Cook <keescook@xxxxxxxxxxxx> Cc: Lukas Middendorf <kernel@xxxxxxxxxxx> Cc: Mark Fasheh <mark@xxxxxxxxxx> Cc: Martin K. Petersen <martin.petersen@xxxxxxxxxx> Cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx> Cc: Paul Turner <pjt@xxxxxxxxxx> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx> Cc: Petr Mladek <pmladek@xxxxxxxx> Cc: Phillip Potter <phil@xxxxxxxxxxxxxxxx> Cc: Qing Wang <wangqing@xxxxxxxx> Cc: "Rafael J. Wysocki" <rafael@xxxxxxxxxx> Cc: Rodrigo Vivi <rodrigo.vivi@xxxxxxxxx> Cc: Sebastian Reichel <sre@xxxxxxxxxx> Cc: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx> Cc: Stephen Kitt <steve@xxxxxxx> Cc: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> Cc: Suren Baghdasaryan <surenb@xxxxxxxxxx> Cc: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> Cc: "Theodore Ts'o" <tytso@xxxxxxx> Cc: Xiaoming Ni <nixiaoming@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/proc/proc_sysctl.c | 13 +++++++++++++ include/linux/sysctl.h | 7 +++++++ 2 files changed, 20 insertions(+) --- a/fs/proc/proc_sysctl.c~sysctl-add-helper-to-register-a-sysctl-mount-point +++ a/fs/proc/proc_sysctl.c @@ -35,6 +35,19 @@ struct ctl_table sysctl_mount_point[] = { } }; +/** + * register_sysctl_mount_point() - registers a sysctl mount point + * @path: path for the mount point + * + * Used to create a permanently empty directory to serve as mount point. + * There are some subtle but important permission checks this allows in the + * case of unprivileged mounts. + */ +struct ctl_table_header *register_sysctl_mount_point(const char *path) +{ + return register_sysctl(path, sysctl_mount_point); +} + static bool is_empty_dir(struct ctl_table_header *head) { return head->ctl_table[0].child == sysctl_mount_point; --- a/include/linux/sysctl.h~sysctl-add-helper-to-register-a-sysctl-mount-point +++ a/include/linux/sysctl.h @@ -209,6 +209,8 @@ extern int sysctl_init(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) +extern struct ctl_table_header *register_sysctl_mount_point(const char *path); + void do_sysctl_args(void); extern int pwrsw_enabled; @@ -223,6 +225,11 @@ static inline struct ctl_table_header *r { return NULL; } + +static inline struct sysctl_header *register_sysctl_mount_point(const char *path) +{ + return NULL; +} static inline struct ctl_table_header *register_sysctl_paths( const struct ctl_path *path, struct ctl_table *table) _ Patches currently in -mm which might be from mcgrof@xxxxxxxxxx are zram-use-attribute_groups.patch hpet-simplify-subdirectory-registration-with-register_sysctl.patch i915-simplify-subdirectory-registration-with-register_sysctl.patch macintosh-mac_hidc-simplify-subdirectory-registration-with-register_sysctl.patch ocfs2-simplify-subdirectory-registration-with-register_sysctl.patch test_sysctl-simplify-subdirectory-registration-with-register_sysctl.patch inotify-simplify-subdirectory-registration-with-register_sysctl-fix.patch cdrom-simplify-subdirectory-registration-with-register_sysctl.patch sysctl-add-helper-to-register-a-sysctl-mount-point.patch fs-move-binfmt_misc-sysctl-to-its-own-file.patch sysctl-share-unsigned-long-const-values.patch