All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHSET v2 0/3] xfs: fix permission drop and flushing in fallocate
@ 2022-01-30  4:59 Darrick J. Wong
  2022-01-30  4:59 ` [PATCH 1/3] xfs: use vfs helper to update file attributes after fallocate Darrick J. Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Darrick J. Wong @ 2022-01-30  4:59 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, chandan.babu, linux-fsdevel

Hi all,

While auditing the file permission dropping for fallocate, I reached the
conclusion that fallocate can modify file contents, and therefore should
be treated as a file write.  As such, it needs to update the file
modification and file (metadata) change timestamps, and it needs to drop
file privileges such as setuid and capabilities, just like a regular
write.  Moreover, if the inode is configured for synchronous writes,
then all the fallocate changes really ought to be persisted to disk
before fallocate returns to userspace.

Unfortunately, the XFS fallocate implementation doesn't do this
correctly.  setgid without group-exec is a mandatory locking mark and is
left alone by write(), which means that we shouldn't drop it
unconditionally.  Furthermore, file capabilities are another vector for
setuid to be set on a program file, and XFS ignores these.

I also noticed that fallocate doesn't flush the log to disk after
fallocate when the fs is mounted with -o sync or if the DIFLAG_SYNC flag
is set on the inode.

Therefore, refactor the XFS fallocate implementation to use the VFS
helper file_modified to update file metadata instead of open-coding it
incorrectly.  Refactor it further to use xfs_file_sync_writes to decide
if we need to flush the log; and then fix the log flushing so that it
flushes after we've made /all/ the changes.

v2: fix some bisection problems

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=falloc-fix-perm-updates-5.17
---
 fs/xfs/xfs_file.c |   72 ++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 20 deletions(-)


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-02-01 16:37 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-30  4:59 [PATCHSET v2 0/3] xfs: fix permission drop and flushing in fallocate Darrick J. Wong
2022-01-30  4:59 ` [PATCH 1/3] xfs: use vfs helper to update file attributes after fallocate Darrick J. Wong
2022-01-30 22:30   ` Dave Chinner
2022-01-30  4:59 ` [PATCH 2/3] xfs: flush log after fallocate for sync mounts and sync inodes Darrick J. Wong
2022-01-30  4:59 ` [PATCH 3/3] xfs: ensure log flush at the end of a synchronous fallocate call Darrick J. Wong
2022-01-30 21:59   ` Dave Chinner
2022-01-31  6:43 ` [PATCH 0/5] xfs: fallocate() vs xfs_update_prealloc_flags() Dave Chinner
2022-01-31  6:43   ` [PATCH 1/5] xfs: remove XFS_PREALLOC_SYNC Dave Chinner
2022-01-31 17:25     ` Darrick J. Wong
2022-01-31  6:43   ` [PATCH 2/5] xfs: fallocate() should call file_modified() Dave Chinner
2022-01-31 17:27     ` Darrick J. Wong
2022-01-31  6:43   ` [PATCH 3/5] xfs: set prealloc flag in xfs_alloc_file_space() Dave Chinner
2022-01-31  7:02     ` [PATCH v1.1 " Dave Chinner
2022-01-31 17:30       ` Darrick J. Wong
2022-01-31  6:43   ` [PATCH 4/5] xfs: move xfs_update_prealloc_flags() to xfs_pnfs.c Dave Chinner
2022-01-31 17:37     ` Darrick J. Wong
2022-01-31  6:43   ` [PATCH 5/5] xfs: ensure log flush at the end of a synchronous fallocate call Dave Chinner
2022-02-01 16:37     ` Darrick J. Wong

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.