From: Ian Kent <raven@themaw.net>
To: Oleg Nesterov <oleg@redhat.com>
Cc: akpm@linux-foundation.org, sukadev@us.ibm.com,
ebiederm@xmission.com, mszeredi@suse.cz,
serge.hallyn@canonical.com, linux-kernel@vger.kernel.org
Subject: Re: [patch 1/2] autofs4: allow autofs to work outside the initial PID namespace
Date: Mon, 18 Nov 2013 11:04:43 +0800 [thread overview]
Message-ID: <1384743883.2380.23.camel@perseus.fritz.box> (raw)
In-Reply-To: <20131116160334.GA19309@redhat.com>
On Sat, 2013-11-16 at 17:03 +0100, Oleg Nesterov wrote:
> On 11/15, Andrew Morton wrote:
> >
> > Enable autofs4 to work in a "container". oz_pgrp is converted from pid_t
> > to struct pid and this is stored at mount time based on the "pgrp=" option
> > or if the option is missing then the current pgrp.
>
> I don't understand this code, so I am probably wrong. And this is minor
> anyway, but...
And I don't understand the namespace code myself but I think you are
correct about the raceand I'm not sure what to do about it either just
yet.
The sbi->wq_mutex will prevent user space daemon notifications and wait
releases but it won't prevent lookups or umounts, the sbi->fs_lock would
be needed for that.
I'm not sure that matters though since there can be only one user space
daemon handling an automount point and the case below here requires
there is no current process owner of the mount the pipe fd is to be set
for (ie. the "if (!sbi->catatonic) { ... }"). That just means a new
process is attempting to "reconnect" to the mount, so umount shouldn't
be a problem. I guess there is a chance that the root user or an errant
pre-existing process might try and umount the mount ...
It might be sufficient to surround the contents of show_options() with a
lock on wq_mutex and update the check at the top to
"lock; if (!sbi || sbi->catatonic) {unlock, return 0; } ..."
but it might be necessary to use the sbi->fs_lock in both locations,
since a catatonic automount has no outstanding waits and can't create
new waits (and hence there can't be any valid wait release ioctls).
I'll think a bit more about the potential umount issue before offering a
patch.
>
> > @@ -357,7 +358,17 @@ static int autofs_dev_ioctl_setpipefd(st
> > mutex_unlock(&sbi->wq_mutex);
> > return -EBUSY;
> > } else {
> > - struct file *pipe = fget(pipefd);
> > + struct file *pipe;
> > +
> > + new_pid = get_task_pid(current, PIDTYPE_PGID);
> > +
> > + if (ns_of_pid(new_pid) != ns_of_pid(sbi->oz_pgrp)) {
> > + AUTOFS_WARN("Not allowed to change PID namespace");
> > + err = -EINVAL;
> > + goto out;
> > + }
> > +
> > + pipe = fget(pipefd);
> > if (!pipe) {
> > err = -EBADF;
> > goto out;
> > @@ -367,12 +378,13 @@ static int autofs_dev_ioctl_setpipefd(st
> > fput(pipe);
> > goto out;
> > }
> > - sbi->oz_pgrp = task_pgrp_nr(current);
> > + swap(sbi->oz_pgrp, new_pid);
> > sbi->pipefd = pipefd;
> > sbi->pipe = pipe;
> > sbi->catatonic = 0;
> > }
> > out:
> > + put_pid(new_pid);
>
> This looks suspicious, put_pid() can actually kfree the old sbi->oz_pgrp
> swapped above. IOW, this assumes we can't race with any user of ->oz_pgrp.
>
> For example,
>
> > @@ -80,7 +83,7 @@ static int autofs4_show_options(struct s
> > if (!gid_eq(root_inode->i_gid, GLOBAL_ROOT_GID))
> > seq_printf(m, ",gid=%u",
> > from_kgid_munged(&init_user_ns, root_inode->i_gid));
> > - seq_printf(m, ",pgrp=%d", sbi->oz_pgrp);
> > + seq_printf(m, ",pgrp=%d", pid_vnr(sbi->oz_pgrp));
>
> Can't this race with autofs_dev_ioctl_setpipefd() above?
>
> Oleg.
>
next prev parent reply other threads:[~2013-11-18 3:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20131115222222.6F70A1CA1A1@corp2gmr1-1.eem.corp.google.com>
2013-11-16 16:03 ` Oleg Nesterov
2013-11-18 3:04 ` Ian Kent [this message]
2013-11-18 18:22 ` Oleg Nesterov
2013-05-07 13:54 [PATCH " Miklos Szeredi
2013-05-07 18:14 ` Serge E. Hallyn
-- strict thread matches above, loose matches on Subject: below --
2012-11-22 16:24 Miklos Szeredi
2012-11-23 3:45 ` Ian Kent
2012-11-23 12:09 ` Ian Kent
2012-11-23 14:30 ` Miklos Szeredi
2012-11-24 2:23 ` Ian Kent
2012-11-24 2:37 ` Ian Kent
2012-11-24 12:07 ` Eric W. Biederman
2012-11-24 21:12 ` Miklos Szeredi
2012-11-24 22:35 ` Eric W. Biederman
2012-11-25 23:25 ` Ian Kent
2012-11-26 2:29 ` Ian Kent
2012-11-26 8:05 ` Miklos Szeredi
2012-11-26 14:38 ` Eric W. Biederman
2012-11-26 16:11 ` Miklos Szeredi
2012-11-13 11:48 Miklos Szeredi
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=1384743883.2380.23.camel@perseus.fritz.box \
--to=raven@themaw.net \
--cc=akpm@linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mszeredi@suse.cz \
--cc=oleg@redhat.com \
--cc=serge.hallyn@canonical.com \
--cc=sukadev@us.ibm.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
Powered by JetHome