public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Jan Kara <jack@suse.cz>,
	"Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>,
	Eric Paris <eparis@redhat.com>,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/1] fanotify: check permissions when creating file descriptor
Date: Thu, 24 Apr 2014 18:05:29 +0200	[thread overview]
Message-ID: <20140424160529.GD13573@quack.suse.cz> (raw)
In-Reply-To: <5359177E.1070907@gmx.de>

On Thu 24-04-14 15:54:06, Heinrich Schuchardt wrote:
> On 24.04.2014 11:04, Jan Kara wrote:
> >On Tue 22-04-14 16:07:47, Jan Kara wrote:
> >>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>
> >   Hum, when digging more around this code, I've found out that
> >fanotify_mark() checks whether it has a read permission to a watched file
> >when creating the mark (in fanotify_find_path()). So I don't think it's
> >really worth it to recheck the permissions when creating a file .gnupg/secring.gpgdescriptor
> >for the event. Sure it may be somewhat surprising that read fd is created
> >after a process doesn't have access to the file anymore but OTOH it is
> >similar to a situation where the process has opened the file long time ago.
> >
> 
> fanotify_mark checks for the read authorization for the marked object,
> not for the object for which the event occurs.
> 
> This means a listener may have read authorization for /home and mark
> this mount.
> Afterwards, while you sign a git tag, it will receive a FAN_OPEN event
> and use the file descriptor supplied in the event to overwrite your
> /home/jankara/.gnupg/secring.pgp
> though the file is chmod 600 and the listener is neither root nor you.
  Ah, right. Thanks for explaining this to me. I'm not really too excited
about this as a security issue because once the process has CAP_SYS_ADMIN
it basically owns the machine (it is sadly one of those capabilities which
is too broad) but I agree checking permissions when creating the fd is
reasonable.

								Honza
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

  parent reply	other threads:[~2014-04-24 16:05 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
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 [this message]
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=20140424160529.GD13573@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox