ocfs2-devel.oss.oracle.com archive mirror
 help / color / mirror / Atom feed
From: Eric W. Biederman <ebiederm@xmission.com>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: jack@suse.cz, rafael@kernel.org, airlied@linux.ie,
	benh@kernel.crashing.org, amir73il@gmail.com, clemens@ladisch.de,
	dri-devel@lists.freedesktop.org, joseph.qi@linux.alibaba.com,
	sfr@canb.auug.org.au, mark@fasheh.com, rdna@fb.com,
	yzaikin@google.com, keescook@chromium.org, arnd@arndb.de,
	intel-gfx@lists.freedesktop.org, julia.lawall@lip6.fr,
	viro@zeniv.linux.org.uk, nixiaoming@huawei.com, vbabka@suse.cz,
	axboe@kernel.dk, tytso@mit.edu, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	linuxppc-dev@lists.ozlabs.org, ocfs2-devel@oss.oracle.com,
	jlbec@evilplan.org
Subject: [Ocfs2-devel] [PATCH 12/13] sysctl: add helper to register empty subdir
Date: Fri, 29 May 2020 08:03:02 -0500	[thread overview]
Message-ID: <878shasxkp.fsf@x220.int.ebiederm.org> (raw)
In-Reply-To: <20200529074108.16928-13-mcgrof@kernel.org> (Luis Chamberlain's message of "Fri, 29 May 2020 07:41:07 +0000")

Luis Chamberlain <mcgrof@kernel.org> writes:

> The way to create a subdirectory from the base set of directories
> is a bit obscure, so provide a helper which makes this clear, and
> also helps remove boiler plate code required to do this work.

I agreee calling:
register_sysctl("fs/binfmt_misc", sysctl_mount_point)
is a bit obscure but if you are going to make a wrapper
please make it the trivial one liner above.

Say something that looks like:
	struct sysctl_header *register_sysctl_mount_point(const char *path)
        {
        	return register_sysctl(path, sysctl_mount_point);
        }

And yes please talk about a mount point and not an empty dir, as these
are permanently empty directories to serve as mount points.  There are
some subtle but important permission checks this allows in the case of
unprivileged mounts.

Further code like this belong in proc_sysctl.c next to all of the code
it is related to so that it is easier to see how to refactor the code if
necessary.

Eric

>
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---
>  include/linux/sysctl.h |  7 +++++++
>  kernel/sysctl.c        | 16 +++++++++++++---
>  2 files changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
> index 33a471b56345..89c92390e6de 100644
> --- a/include/linux/sysctl.h
> +++ b/include/linux/sysctl.h
> @@ -208,6 +208,8 @@ extern void register_sysctl_init(const char *path, struct ctl_table *table,
>  extern struct ctl_table_header *register_sysctl_subdir(const char *base,
>  						       const char *subdir,
>  						       struct ctl_table *table);
> +extern void register_sysctl_empty_subdir(const char *base, const char *subdir);
> +
>  void do_sysctl_args(void);
>  
>  extern int pwrsw_enabled;
> @@ -231,6 +233,11 @@ inline struct ctl_table_header *register_sysctl_subdir(const char *base,
>  	return NULL;
>  }
>  
> +static inline void register_sysctl_empty_subdir(const char *base,
> +						const char *subdir)
> +{
> +}
> +
>  static inline struct ctl_table_header *register_sysctl_paths(
>  			const struct ctl_path *path, struct ctl_table *table)
>  {
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index f9a35325d5d5..460532cd5ac8 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -3188,13 +3188,17 @@ struct ctl_table_header *register_sysctl_subdir(const char *base,
>  		{ }
>  	};
>  
> -	if (!table->procname)
> +	if (table != sysctl_mount_point && !table->procname)
>  		goto out;
>  
>  	hdr = register_sysctl_table(base_table);
>  	if (unlikely(!hdr)) {
> -		pr_err("failed when creating subdirectory sysctl %s/%s/%s\n",
> -		       base, subdir, table->procname);
> +		if (table != sysctl_mount_point)
> +			pr_err("failed when creating subdirectory sysctl %s/%s/%s\n",
> +			       base, subdir, table->procname);
> +		else
> +			pr_err("failed when creating empty subddirectory %s/%s\n",
> +			       base, subdir);
>  		goto out;
>  	}
>  	kmemleak_not_leak(hdr);
> @@ -3202,6 +3206,12 @@ struct ctl_table_header *register_sysctl_subdir(const char *base,
>  	return hdr;
>  }
>  EXPORT_SYMBOL_GPL(register_sysctl_subdir);
> +
> +void register_sysctl_empty_subdir(const char *base,
> +				  const char *subdir)
> +{
> +	register_sysctl_subdir(base, subdir, sysctl_mount_point);
> +}
>  #endif /* CONFIG_SYSCTL */
>  /*
>   * No sense putting this after each symbol definition, twice,

  parent reply	other threads:[~2020-05-29 13:03 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-29  7:40 [Ocfs2-devel] [PATCH 00/13] sysctl: spring cleaning Luis Chamberlain
2020-05-29  7:40 ` [Ocfs2-devel] [PATCH 01/13] sysctl: add new register_sysctl_subdir() helper Luis Chamberlain
2020-05-29  8:13   ` Jani Nikula
2020-05-29 12:16     ` Luis Chamberlain
2020-05-29 12:40   ` Eric W. Biederman
2020-05-29 12:42     ` Eric W. Biederman
2020-05-29  7:40 ` [Ocfs2-devel] [PATCH 02/13] cdrom: use new sysctl subdir helper register_sysctl_subdir() Luis Chamberlain
2020-05-29 12:46   ` Eric W. Biederman
2020-05-29  7:40 ` [Ocfs2-devel] [PATCH 03/13] hpet: " Luis Chamberlain
2020-05-29  7:40 ` [Ocfs2-devel] [PATCH 04/13] i915: " Luis Chamberlain
2020-05-29  7:41 ` [Ocfs2-devel] [PATCH 05/13] macintosh/mac_hid.c: " Luis Chamberlain
2020-05-29  7:41 ` [Ocfs2-devel] [PATCH 06/13] ocfs2: " Luis Chamberlain
2020-05-29  8:23   ` Kees Cook
2020-05-29 11:49     ` [Ocfs2-devel] [Intel-gfx] " Luis Chamberlain
2020-05-29 14:49       ` Kees Cook
2020-05-29  7:41 ` [Ocfs2-devel] [PATCH 07/13] test_sysctl: " Luis Chamberlain
2020-05-29  7:41 ` [Ocfs2-devel] [PATCH 08/13] inotify: simplify sysctl declaration with register_sysctl_subdir() Luis Chamberlain
2020-05-29  7:41 ` [Ocfs2-devel] [PATCH 09/13] firmware_loader: " Luis Chamberlain
2020-05-29 10:26   ` Greg KH
2020-05-29 11:59     ` Xiaoming Ni
2020-05-29 12:09     ` Luis Chamberlain
2020-05-29  7:41 ` [Ocfs2-devel] [PATCH 10/13] eventpoll: " Luis Chamberlain
2020-05-29  7:41 ` [Ocfs2-devel] [PATCH 11/13] random: " Luis Chamberlain
2020-05-29 10:26   ` Greg KH
2020-05-29 12:09     ` Xiaoming Ni
2020-05-29  7:41 ` [Ocfs2-devel] [PATCH 12/13] sysctl: add helper to register empty subdir Luis Chamberlain
2020-05-29  8:15   ` Kees Cook
2020-05-29 13:03   ` Eric W. Biederman [this message]
2020-05-29  7:41 ` [Ocfs2-devel] [PATCH 13/13] fs: move binfmt_misc sysctl to its own file Luis Chamberlain
2020-05-29  8:14   ` Kees Cook
2020-06-04  8:45   ` Xiaoming Ni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878shasxkp.fsf@x220.int.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=airlied@linux.ie \
    --cc=akpm@linux-foundation.org \
    --cc=amir73il@gmail.com \
    --cc=arnd@arndb.de \
    --cc=axboe@kernel.dk \
    --cc=benh@kernel.crashing.org \
    --cc=clemens@ladisch.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jack@suse.cz \
    --cc=jlbec@evilplan.org \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=julia.lawall@lip6.fr \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mark@fasheh.com \
    --cc=mcgrof@kernel.org \
    --cc=nixiaoming@huawei.com \
    --cc=ocfs2-devel@oss.oracle.com \
    --cc=rafael@kernel.org \
    --cc=rdna@fb.com \
    --cc=sfr@canb.auug.org.au \
    --cc=tytso@mit.edu \
    --cc=vbabka@suse.cz \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yzaikin@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).