linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Calvin Owens <calvinowens@fb.com>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Oleg Nesterov <oleg@redhat.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Peter Feiner <pfeiner@google.com>,
	Grant Likely <grant.likely@secretlab.ca>,
	Siddhesh Poyarekar <siddhesh.poyarekar@gmail.com>,
	<linux-kernel@vger.kernel.org>, <kernel-team@fb.com>,
	Pavel Emelyanov <xemul@openvz.org>
Subject: Re: [RFC][PATCH] procfs: Always expose /proc/<pid>/map_files/ and make it readable
Date: Thu, 22 Jan 2015 21:52:16 -0800	[thread overview]
Message-ID: <20150123055216.GB36613@mail.thefacebook.com> (raw)
In-Reply-To: <20150122212740.GA2286@node.dhcp.inet.fi>

On Thursday 01/22 at 23:27 +0200, Kirill A. Shutemov wrote:
> On Thu, Jan 22, 2015 at 01:00:25PM -0800, Calvin Owens wrote:
> > On Thursday 01/22 at 13:02 +0200, Kirill A. Shutemov wrote:
> > > On Wed, Jan 21, 2015 at 06:45:54PM -0800, Calvin Owens wrote:
> > > > Currently, /proc/<pid>/map_files/ is restricted to CAP_SYS_ADMIN, and
> > > > is only exposed if CONFIG_CHECKPOINT_RESTORE is set. This interface
> > > > is very useful for enumerating the files mapped into a process when
> > > > the more verbose information in /proc/<pid>/maps is not needed.
> > > > 
> > > > This patch moves the folder out from behind CHECKPOINT_RESTORE, and
> > > > removes the CAP_SYS_ADMIN restrictions. To avoid exposing files to
> > > > processes for whom they may not be visible, a follow_link() stub is
> > > > added to the inode_operations struct attached to the symlinks that
> > > > prevent them from being followed without CAP_SYS_ADMIN.
> > > > 
> > > > Signed-off-by: Calvin Owens <calvinowens@fb.com>
> > > > ---
> > > >  fs/proc/base.c | 42 +++++++++++++++++++++++-------------------
> > > >  1 file changed, 23 insertions(+), 19 deletions(-)
> > > > 
> > > > diff --git a/fs/proc/base.c b/fs/proc/base.c
> > > > index 3f3d7ae..7d48003 100644
> > > > --- a/fs/proc/base.c
> > > > +++ b/fs/proc/base.c
> > > > @@ -1632,8 +1632,6 @@ end_instantiate:
> > > >  	return dir_emit(ctx, name, len, 1, DT_UNKNOWN);
> > > >  }
> > > >  
> > > > -#ifdef CONFIG_CHECKPOINT_RESTORE
> > > > -
> > > >  /*
> > > >   * dname_to_vma_addr - maps a dentry name into two unsigned longs
> > > >   * which represent vma start and end addresses.
> > > > @@ -1660,11 +1658,6 @@ static int map_files_d_revalidate(struct dentry *dentry, unsigned int flags)
> > > >  	if (flags & LOOKUP_RCU)
> > > >  		return -ECHILD;
> > > >  
> > > > -	if (!capable(CAP_SYS_ADMIN)) {
> > > > -		status = -EPERM;
> > > > -		goto out_notask;
> > > > -	}
> > > > -
> > > >  	inode = dentry->d_inode;
> > > >  	task = get_proc_task(inode);
> > > >  	if (!task)
> > > > @@ -1753,6 +1746,28 @@ struct map_files_info {
> > > >  	unsigned char	name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */
> > > >  };
> > > >  
> > > > +/*
> > > > + * Allowing any user to follow the symlinks in /proc/<pid>/map_files/ could
> > > > + * allow processes to access files that should not be visible to them, so
> > > > + * restrict follow_link() to CAP_SYS_ADMIN for these files.
> > > > + */
> > > > +static void *proc_map_files_follow_link(struct dentry *d, struct nameidata *n)
> > > > +{
> > > > +	if (!capable(CAP_SYS_ADMIN))
> > > > +		return ERR_PTR(-EPERM);
> > > > +
> > > > +	return proc_pid_follow_link(d, n);
> > > > +}
> > > 
> > > I have thought a bit more about this and not sure it's reasonable to
> > > limit it to CAP_SYS_ADMIN. What scenario are we protecting from?
> > > 
> > > Initially, I thought about something like this: privileged process opens a
> > > file, map part of it, closes the file and drop privileges with hope to
> > > limit further access to mapped window of the file. But I don't see what
> > > would stop the unprivileged process from accessing rest of the file using
> > > mremap(2). And if a process can do this, anybody who can ptrace(2) the
> > > process can do this.
> > > 
> > > Am I missing something?
> > 
> > The specific case I was thinking of is a process in a chroot with a
> > mounted /proc inside of it: if a process inside the chroot has the same
> > UID as a process outside of it, the chroot'ed process could follow the
> > symlinks in map_files/ and poke files it can't actually see, right?
> 
> It depends on how you define "poke". If you mean touch content of the
> file, then, well, you can do it now. You cannot do anything which requires
> file descriptor -- open(), ftrancate(), etc.

Ah okay, I didn't realize you couldn't get the file descriptor. I wrote
a quick test case, you get -EACCES on open() in my chroot scenario.

I'll resend without the CAP_SYS_ADMIN check.

Thanks,
Calvin

  reply	other threads:[~2015-01-23  5:52 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14  0:20 [RFC][PATCH] procfs: Add /proc/<pid>/mapped_files Calvin Owens
2015-01-14  0:23 ` Calvin Owens
2015-01-14 14:13 ` Rasmus Villemoes
2015-01-14 14:37   ` Siddhesh Poyarekar
2015-01-14 14:53     ` Rasmus Villemoes
2015-01-14 21:03       ` Calvin Owens
2015-01-14 22:45         ` Andrew Morton
2015-01-14 23:51           ` Rasmus Villemoes
2015-01-16  1:15             ` Andrew Morton
2015-01-16 11:00               ` Kirill A. Shutemov
2015-01-14 15:25 ` Kirill A. Shutemov
2015-01-14 15:33   ` Cyrill Gorcunov
2015-01-14 20:46     ` Calvin Owens
2015-01-14 21:16       ` Cyrill Gorcunov
2015-01-22  2:45         ` [RFC][PATCH] procfs: Always expose /proc/<pid>/map_files/ and make it readable Calvin Owens
2015-01-22  7:16           ` Cyrill Gorcunov
2015-01-22 11:02           ` Kirill A. Shutemov
2015-01-22 21:00             ` Calvin Owens
2015-01-22 21:27               ` Kirill A. Shutemov
2015-01-23  5:52                 ` Calvin Owens [this message]
2015-01-24  3:15           ` [RFC][PATCH v2] " Calvin Owens
2015-01-26 12:47             ` Kirill A. Shutemov
2015-01-26 21:00               ` Cyrill Gorcunov
2015-01-26 23:43                 ` Andrew Morton
2015-01-27  0:15                   ` Kees Cook
2015-01-27  7:37                     ` Cyrill Gorcunov
2015-01-27 19:53                       ` Kees Cook
2015-01-27 21:35                         ` Cyrill Gorcunov
2015-01-27 21:46                         ` Pavel Emelyanov
2015-01-27  0:19                   ` Kirill A. Shutemov
2015-01-27  6:46                   ` Cyrill Gorcunov
2015-01-27  6:50                     ` Andrew Morton
2015-01-27  7:23                       ` Cyrill Gorcunov
2015-01-28  4:38                   ` Calvin Owens
2015-01-30  1:30                     ` Kees Cook
2015-01-31  1:58                       ` Calvin Owens
2015-02-02 14:01                         ` Austin S Hemmelgarn
2015-02-04  3:53                           ` Calvin Owens
2015-02-02 20:16                         ` Andy Lutomirski
2015-02-04  3:28                           ` Calvin Owens
2015-02-12  2:29             ` [RFC][PATCH v3] " Calvin Owens
2015-02-12  7:45               ` Cyrill Gorcunov
2015-02-14 20:40               ` [RFC][PATCH v4] " Calvin Owens
2015-03-10 22:17                 ` Cyrill Gorcunov
2015-04-28 22:23                   ` Calvin Owens
2015-04-29  7:32                     ` Cyrill Gorcunov
2015-05-19  3:10                 ` [PATCH v5] " Calvin Owens
2015-05-19  3:29                   ` Joe Perches
2015-05-19 18:04                   ` Andy Lutomirski
2015-05-21  1:52                     ` Calvin Owens
2015-05-21  2:10                       ` Andy Lutomirski
2015-06-09  3:39                   ` [PATCH v6] " Calvin Owens
2015-06-09 17:27                     ` Kees Cook
2015-06-09 17:47                       ` Andy Lutomirski
2015-06-09 18:15                         ` Cyrill Gorcunov
2015-06-09 21:13                     ` Andrew Morton
2015-06-10  1:39                       ` Calvin Owens
2015-06-10 20:58                         ` Andrew Morton
2015-06-11 11:10                           ` Alexey Dobriyan
2015-06-11 18:49                             ` Andrew Morton
2015-06-12  9:55                               ` Alexey Dobriyan
2015-06-19  2:32                     ` [PATCH v7] " Calvin Owens
2015-07-15 22:21                       ` Andrew Morton
2015-07-15 23:39                         ` Calvin Owens
2015-02-14 20:44               ` [PATCH] procfs: Return -ESRCH on /proc/N/fd/* when PID N doesn't exist Calvin Owens
2015-01-14 22:40 ` [RFC][PATCH] procfs: Add /proc/<pid>/mapped_files Kirill A. Shutemov

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=20150123055216.GB36613@mail.thefacebook.com \
    --to=calvinowens@fb.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=gorcunov@gmail.com \
    --cc=grant.likely@secretlab.ca \
    --cc=kernel-team@fb.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=pfeiner@google.com \
    --cc=siddhesh.poyarekar@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xemul@openvz.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;
as well as URLs for NNTP newsgroup(s).