From: Jan Kara <jack@suse.cz>
To: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
Cc: Jan Kara <jack@suse.cz>, Heinrich Schuchardt <xypron.glpk@gmx.de>,
Eric Paris <eparis@redhat.com>,
lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/1] fanotify: check permissions when creating file descriptor
Date: Tue, 22 Apr 2014 16:07:47 +0200 [thread overview]
Message-ID: <20140422140747.GF366@quack.suse.cz> (raw)
In-Reply-To: <CAKgNAkh=Shj6UO6x_KieQEYUoY+guokNute0iwUfiSYFJbeTfQ@mail.gmail.com>
On Tue 22-04-14 15:50:26, Michael Kerrisk (man-pages) wrote:
> On Tue, Apr 22, 2014 at 3:40 PM, Jan Kara <jack@suse.cz> wrote:
> > On Sat 19-04-14 22:53:53, Heinrich Schuchardt wrote:
> >> When monitoring a directory or a mount with the fanotify API
> >> the call to fanotify_init checks,
> >> * the process has cap_sys_admin capability
> >>
> >> The call to fanotify_mark checks,
> >> * the process has read authorization for directory or mount
> >>
> >> A directory or mount may contain files for which the process
> >> has no read or write authorization.
> >> Yet when reading from the fanotify file descriptor, structures
> >> fanotify_event_metadata are returned, which contain a file
> >> descriptor for these files, and will allow to read or write.
> >>
> >> The patch adds an authorization check for read and write
> >> permission. In case of missing permission, reading from the
> >> fanotify file descriptor returns EACCES.
> > OK, am I right you are concerned about a situation where fanotify group
> > descriptor is passed to an unpriviledged process which handles all the
> > incoming events? I'm asking because the permission checking can be
> > relatively expensive (think of acls) so we better do it for a reason.
> > I'd prefer to hear from Eric what the original intention regarding
> > permissions was...
>
> If I understand correctly, passing to an unprivileged process is the
> point. The point is I think that supposedly one only needs to
> CAP_SYS_ADMIN to use fanotify. However, once you have that capability,
> then you implicitly get the effect of CAP_DAC_READ_SEARCH and
> CAP_DAC_OVERRIDE as well.
Ah, OK. Thanks for explanation. Then I'm OK with the patch. So feel free
to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> >> fs/notify/fanotify/fanotify_user.c | 20 +++++++++++++++-----
> >> 1 file changed, 15 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> >> index 4e565c8..5d22a20 100644
> >> --- a/fs/notify/fanotify/fanotify_user.c
> >> +++ b/fs/notify/fanotify/fanotify_user.c
> >> @@ -62,6 +62,8 @@ static int create_fd(struct fsnotify_group *group,
> >> {
> >> int client_fd;
> >> struct file *new_file;
> >> + int mask;
> >> + int ret;
> >>
> >> pr_debug("%s: group=%p event=%p\n", __func__, group, event);
> >>
> >> @@ -75,11 +77,19 @@ static int create_fd(struct fsnotify_group *group,
> >> */
> >> /* it's possible this event was an overflow event. in that case dentry and mnt
> >> * are NULL; That's fine, just don't call dentry open */
> >> - if (event->path.dentry && event->path.mnt)
> >> - new_file = dentry_open(&event->path,
> >> - group->fanotify_data.f_flags | FMODE_NONOTIFY,
> >> - current_cred());
> >> - else
> >> + if (event->path.dentry && event->path.mnt) {
> >> + /* check permissions before granting access to file */
> >> + mask = MAY_READ;
> >> + if (group->fanotify_data.f_flags & (O_RDWR | O_WRONLY))
> >> + mask |= MAY_WRITE;
> >> + ret = inode_permission(event->path.dentry->d_inode, mask);
> >> + if (ret)
> >> + new_file = ERR_PTR(ret);
> >> + else
> >> + new_file = dentry_open(&event->path,
> >> + group->fanotify_data.f_flags | FMODE_NONOTIFY,
> >> + current_cred());
> >> + } else
> >> new_file = ERR_PTR(-EOVERFLOW);
> >> if (IS_ERR(new_file)) {
> >> /*
> >> --
> >> 1.9.1
> >>
> > --
> > Jan Kara <jack@suse.cz>
> > SUSE Labs, CR
>
>
>
> --
> Michael Kerrisk
> Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
> Linux/UNIX System Programming Training: http://man7.org/training/
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
next prev parent reply other threads:[~2014-04-22 14:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-19 20:53 [PATCH 1/1] fanotify: check permissions when creating file descriptor Heinrich Schuchardt
2014-04-22 13:40 ` Jan Kara
2014-04-22 13:50 ` Michael Kerrisk (man-pages)
2014-04-22 13:52 ` Michael Kerrisk (man-pages)
2014-04-22 14:07 ` Jan Kara [this message]
2014-04-22 20:51 ` Heinrich Schuchardt
2014-04-24 10:01 ` Jan Kara
2014-04-24 9:04 ` Jan Kara
2014-04-24 13:54 ` Heinrich Schuchardt
2014-04-24 15:05 ` Michael Kerrisk (man-pages)
2014-04-24 16:05 ` Jan Kara
2014-04-24 16:14 ` Michael Kerrisk (man-pages)
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=20140422140747.GF366@quack.suse.cz \
--to=jack@suse.cz \
--cc=eparis@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=xypron.glpk@gmx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.