Skip to content

Commit

Permalink
fuse: allow server to run in different pid_ns
Browse files Browse the repository at this point in the history
Commit 0b6e9ea ("fuse: Add support for pid namespaces") broke
Sandstorm.io development tools, which have been sending FUSE file
descriptors across PID namespace boundaries since early 2014.

The above patch added a check that prevented I/O on the fuse device file
descriptor if the pid namespace of the reader/writer was different from the
pid namespace of the mounter.  With this change passing the device file
descriptor to a different pid namespace simply doesn't work.  The check was
added because pids are transferred to/from the fuse userspace server in the
namespace registered at mount time.

To fix this regression, remove the checks and do the following:

1) the pid in the request header (the pid of the task that initiated the
filesystem operation) is translated to the reader's pid namespace.  If a
mapping doesn't exist for this pid, then a zero pid is used.  Note: even if
a mapping would exist between the initiator task's pid namespace and the
reader's pid namespace the pid will be zero if either mapping from
initator's to mounter's namespace or mapping from mounter's to reader's
namespace doesn't exist.

2) The lk.pid value in setlk/setlkw requests and getlk reply is left alone.
Userspace should not interpret this value anyway.  Also allow the
setlk/setlkw operations if the pid of the task cannot be represented in the
mounter's namespace (pid being zero in that case).

Reported-by: Kenton Varda <kenton@sandstorm.io>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Fixes: 0b6e9ea ("fuse: Add support for pid namespaces")
Cc: <stable@vger.kernel.org> # v4.12+
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Seth Forshee <seth.forshee@canonical.com>
  • Loading branch information
Miklos Szeredi committed Sep 12, 2017
1 parent 569dbb8 commit 5d6d3a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
13 changes: 7 additions & 6 deletions fs/fuse/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,9 +1222,6 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
struct fuse_in *in;
unsigned reqsize;

if (task_active_pid_ns(current) != fc->pid_ns)
return -EIO;

restart:
spin_lock(&fiq->waitq.lock);
err = -EAGAIN;
Expand Down Expand Up @@ -1262,6 +1259,13 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,

in = &req->in;
reqsize = in->h.len;

if (task_active_pid_ns(current) != fc->pid_ns) {
rcu_read_lock();
in->h.pid = pid_vnr(find_pid_ns(in->h.pid, fc->pid_ns));
rcu_read_unlock();
}

/* If request is too large, reply with an error and restart the read */
if (nbytes < reqsize) {
req->out.h.error = -EIO;
Expand Down Expand Up @@ -1823,9 +1827,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
struct fuse_req *req;
struct fuse_out_header oh;

if (task_active_pid_ns(current) != fc->pid_ns)
return -EIO;

if (nbytes < sizeof(struct fuse_out_header))
return -EINVAL;

Expand Down
3 changes: 0 additions & 3 deletions fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2181,9 +2181,6 @@ static int fuse_setlk(struct file *file, struct file_lock *fl, int flock)
if ((fl->fl_flags & FL_CLOSE_POSIX) == FL_CLOSE_POSIX)
return 0;

if (pid && pid_nr == 0)
return -EOVERFLOW;

fuse_lk_fill(&args, file, fl, opcode, pid_nr, flock, &inarg);
err = fuse_simple_request(fc, &args);

Expand Down

0 comments on commit 5d6d3a3

Please sign in to comment.