All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, Andrew Ayer <agwa@andrewayer.name>
Subject: Re: [PATCH 0/3] Implement the f*xattrat family of functions
Date: Wed, 26 Feb 2014 16:49:12 +0100	[thread overview]
Message-ID: <530E0CF8.8040001@redhat.com> (raw)
In-Reply-To: <20140121135811.1261F401159C6@oldenburg.str.redhat.com>

On 01/21/2014 02:51 PM, Florian Weimer wrote:
> To my knowledge, it is not possible to implement AT_EMPTY_PATH in
> userspace in a race-free manner (even with the /proc/self/fd kludge), so
> I'd like to add the for missing system calls.

I would like to pick up this again.

Here's an extended rationale for this functionality (which also applies 
to fchmodat4):

I need a (relatively) race-free way to check that the link count of a 
file is less than 2, followed by a setxattr operation on the file 
handle.  Ideally, the file has not been opened fully, to avoid open side 
effects, so this suggests using O_PATH.  But the current fsetxattr 
implementation is not compatible with O_PATH.  In the end, I want to 
teach chmod -R/chown -R and various SELinux relabeling mechanisms not to 
do stupid things when hard links are involved.  For this application, it 
doesn't matter if the inode grows another link between the check to 
ensure it is less than 2 and the permissions update, as long as it 
wasn't 2 or more from the start.  We now have protected hard links, but 
we still need to support running without them.

Based on off-list discussions, O_PATH support for the f*xattrat family 
(and fchmod*) is not controversial in itself.  But it's an open question 
if we need new system calls, or if we can just reuse the existing f* 
variants.

Arguments against just making the the f* variants work with O_PATH 
descriptors are:

For fchmodat, POSIX requires that if the descriptor does not refer to a 
directory, an ENOTDIR error is returned.  (O_PATH is outside of POSIX, 
so we might get away with ignoring this, but if we use O_PATH to 
implement O_SEARCH, that would clearly be non-compliant.  Whether that 
matters is a different question).  This wouldn't apply to fchmod.  The 
xattr functions aren't part of POSIX, so these concerns apply over there 
only by analogy.

The other set of arguments are related to security concerns and 
descriptor leaks, e.g. a SUID program applying changes through an O_PATH 
descriptor which the invoking user could not have opened without O_PATH. 
  I tried to find something more concrete int his area, but failed. 
However, POSIX seems to permit fchmod on file descriptors opened 
read-only (and the kernel matches).  If such misbehaving SUID programs 
existed, they could be abused to corrupt /dev/null permissions even 
without O_PATH.  In short, this line of reasoning is a bit dubious.

All existing O_PATH accessors started as the f*at functions with 
AT_EMPTY_PATH, but there has been some movement towards accepting O_PATH 
descriptors in other places, see commits 
9d05746e7b16d8565dddbe3200faa1e669d23bbf and 
55815f70147dcfa3ead5738fd56d3574e2e3c1c2.  But these are reading operations.

Comments?

-- 
Florian Weimer / Red Hat Product Security Team

      reply	other threads:[~2014-02-26 16:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-21 13:51 [PATCH 0/3] Implement the f*xattrat family of functions Florian Weimer
2014-02-26 15:49 ` Florian Weimer [this message]

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=530E0CF8.8040001@redhat.com \
    --to=fweimer@redhat.com \
    --cc=agwa@andrewayer.name \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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.