public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: David Howells <dhowells@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Tejun Heo <tj@kernel.org>, Li Zefan <lizefan@huawei.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	cgroups@vger.kernel.org, fenghua.yu@intel.com,
	linux-kernel@vger.kernel.org
Subject: Re: fs_context-related oops in mainline
Date: Fri, 15 Mar 2019 12:18:13 +0000	[thread overview]
Message-ID: <20190315121813.GY2217@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20190315115002.GA9055@light.dominikbrodowski.net>

On Fri, Mar 15, 2019 at 12:50:02PM +0100, Dominik Brodowski wrote:
> On Fri, Mar 15, 2019 at 11:44:45AM +0000, David Howells wrote:
> > Dominik Brodowski <linux@dominikbrodowski.net> wrote:
> > 
> > > [    0.839322] RIP: 0010:sysfs_init_fs_context+0x82/0xd0
> > 
> > Could you load your kernel into gdb and then do:
> > 
> > 	i li *sysfs_init_fs_context+0x82
> 
> Doesn't seem necessary as per my mail to Al a few seconds ago:
> kobj_ns_grab_current(KOBJ_NS_TYPE_NET) returns NULL, so
> 
>         fc->user_ns = get_user_ns(netns->user_ns);
> 
> will try to dereference a null pointer.
> 
> Thanks,
> 	Dominik
> 

Charming...  It's netns being turned off, and the thing we'd missed
is that kobj_ns_current_may_mount() becomes constant true in that
setup.  IOW, ns_capable(..., CAP_SYS_ADMIN) is suppressed entirely
in that case (well, aside of what may_mount() has done in
do_mount/sys_fsmount).

So what we need is making that "change fc->user_ns" conditional
on netns != NULL, as in

diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 4cb21b558a85..1b56686ab178 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -71,9 +71,11 @@ static int sysfs_init_fs_context(struct fs_context *fc)
 	kfc->magic = SYSFS_MAGIC;
 	fc->fs_private = kfc;
 	fc->ops = &sysfs_fs_context_ops;
-	if (fc->user_ns)
-		put_user_ns(fc->user_ns);
-	fc->user_ns = get_user_ns(netns->user_ns);
+	if (netns) {
+		if (fc->user_ns)
+			put_user_ns(fc->user_ns);
+		fc->user_ns = get_user_ns(netns->user_ns);
+	}
 	fc->global = true;
 	return 0;
 }

  reply	other threads:[~2019-03-15 12:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-15  7:43 fs_context-related oops in mainline Dominik Brodowski
2019-03-15 11:34 ` Al Viro
2019-03-15 11:46   ` Dominik Brodowski
2019-03-15 11:44 ` David Howells
2019-03-15 11:50   ` Dominik Brodowski
2019-03-15 12:18     ` Al Viro [this message]
2019-03-15 12:57       ` Dominik Brodowski
2019-03-15 14:24       ` David Howells
2019-03-15 14:29         ` Greg Kroah-Hartman
2019-03-15 14:51         ` Al Viro

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=20190315121813.GY2217@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=cgroups@vger.kernel.org \
    --cc=dhowells@redhat.com \
    --cc=fenghua.yu@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=lizefan@huawei.com \
    --cc=tj@kernel.org \
    /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