All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Dave Chinner <david@fromorbit.com>
Cc: Eric Sandeen <sandeen@sandeen.net>,
	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 17:26:44 -0700	[thread overview]
Message-ID: <20170824002644.GC4796@magnolia> (raw)
In-Reply-To: <20170823235946.GA21024@dastard>

On Thu, Aug 24, 2017 at 09:59:46AM +1000, Dave Chinner wrote:
> On Wed, Aug 23, 2017 at 09:35:43AM -0700, Darrick J. Wong wrote:
> > On Wed, Aug 23, 2017 at 09:28:31AM +1000, Dave Chinner wrote:
> > > 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.
> 
> ....
> > Create a 48k mapping at 0x20000000 to some anonymous memory... with
> > PROT_NONE.
> > 
> >   r[5] = syscall(__NR_write, r[0], 0x2000b000ul, 0x1ul, 0, 0, 0, 0, 0, 0);
> >   printf("write()=%ld, errno=%d\n", r[5], errno);
> > 
> > Then try to write 1 byte to r0 (whose pos is 10) from this anonymous
> > region, which bails out with EFAULT because the region is PROT_NONE.
> > This is effectively pwrite(r[0], <unreadable>, 1, 10);
> 
> My bad - I didn't look at the code for that case, I was just
> commenting on Eric's statement about mmap extending the file.
> 
> > Therefore, it's not an mmap write that extends the file length, it's the
> > write call that moves out EOF in preparation for the write, only to have
> > the buffered write fail because the process doesn't have read access to
> > the memory buffer.
> > 
> > Not sure what to do about this corner case, though -- I guess you could
> > check that at least the first byte of the write will succeed, and only
> > then call xfs_zero_eof.  Could still be a TOCTOU race though.
> > 
> > Thoughts?
> 
> The zeroing succeeded, yes? So there's no stale data exposure at
> all?

Correct.

> Given it's such a whacky corner case, do we really care what
> happens to the file size on error as long as we don't expose stale
> data?

I'd just as soon focus on sharper problems, so I'll just throw out the
usual "patches welcomed" and see if anyone feels motivated to fix this.

:)

--D

> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

      reply	other threads:[~2017-08-24  0:27 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
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 [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=20170824002644.GC4796@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=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 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.