From: Dave Chinner <david@fromorbit.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: Ruoxin Jiang <rj2394@columbia.edu>,
linux-xfs@vger.kernel.org, Suman Jana <sumanj@gmail.com>
Subject: Re: XFS Bug Report
Date: Wed, 23 Aug 2017 09:28:31 +1000 [thread overview]
Message-ID: <20170822232831.GY21024@dastard> (raw)
In-Reply-To: <ad807068-5de9-3200-68ef-de9e42401a5a@sandeen.net>
On Tue, Aug 22, 2017 at 05:33:24PM -0500, Eric Sandeen wrote:
> On 8/22/17 4:10 PM, Ruoxin Jiang wrote:
> > Hello,
> >
> > We are researchers from Columbia University, New York. As part of our
> > current research we have run into some issues using xfs filesystem.
> > For example, we encountered a case where the setuid bit of a modified
> > executable was not removed as desired.
>
> Thanks for the reports.
>
> For case 1:
>
> > * In xfs, function `xfs_file_aio_write_checks` calls `file_remove_privs` which
> > removes special file priviledges when the executable is written to or truncated.
> >
> > * If an DIO write is not aligned to device logical sector size, the syscall
> > fails with EINVAL` before `xfs_file_aio_write_checks` is called. Thus the setuid
> > bit will not be removed from the modified executable.
>
> If the write did not happen, why should the setuid bit be removed?
> The write failed and the file's contents were not modified. It seems
> like xfs's behavior makes sense; is there a posix specification that
> indicates the behavior should be different?
>
> Case 2 does look problematic (failed mmap write extending the file EOF)
mmap should not be able to extend the file at all. It should segv
if an attempt to write past EOF occurs.
> Case 3 seems to show xfs violating this rule, I guess?
>
> When the owner or group of an executable file are changed by a
> non-superuser, the S_ISUID and S_ISGID mode bits are cleared.
> POSIX does not specify whether this also should happen when root
> does the chown(); the Linux behavior depends on the kernel ver-
> sion. In case of a non-group-executable file (i.e., one for
> which the S_IXGRP bit is not set) the S_ISGID bit indicates
> mandatory locking, and is not cleared by a chown().
>
> I thought this was all handled at the vfs, though, odd.
xfs_setattr_nonsize() does:
/*
* CAP_FSETID overrides the following restrictions:
*
* The set-user-ID and set-group-ID bits of a file will be
* cleared upon successful return from chown()
*/
if ((inode->i_mode & (S_ISUID|S_ISGID)) &&
!capable(CAP_FSETID))
inode->i_mode &= ~(S_ISUID|S_ISGID);
Whereas the VFS has this check in should_remove_suid():
/*
* sgid without any exec bits is just a mandatory locking mark; leave
* it alone. If some exec bits are set, it's a real sgid; kill it.
*/
if (unlikely((mode & S_ISGID) && (mode & S_IXGRP)))
kill |= ATTR_KILL_SGID;
if (unlikely(kill && !capable(CAP_FSETID) && S_ISREG(mode)))
return kill;
So the VFS is doing the right thing but the XFS code does it's own
thing for reasons I don't remember. Given the VFS handles this, maybe
we should finally remove it from the XFS code?
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2017-08-22 23:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-22 21:10 XFS Bug Report Ruoxin Jiang
2017-08-22 22:33 ` Eric Sandeen
2017-08-22 22:43 ` Eric Sandeen
2017-08-22 23:28 ` Dave Chinner [this message]
2017-08-23 2:20 ` Eric Sandeen
2017-08-23 16:35 ` Darrick J. Wong
2017-08-23 23:59 ` Dave Chinner
2017-08-24 0:26 ` Darrick J. Wong
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=20170822232831.GY21024@dastard \
--to=david@fromorbit.com \
--cc=linux-xfs@vger.kernel.org \
--cc=rj2394@columbia.edu \
--cc=sandeen@sandeen.net \
--cc=sumanj@gmail.com \
/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).