Skip to content

vfs, afs, bash: Fix miscomparison of foreign user IDs in the VFS

David Howells linux-cifs linux-fsdevel linux-integrity lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2afs, bash: Fix open(O_CREAT) on an extant AFS file in a sticky dirfs/afs/dir.c fs/afs/file.c fs/afs/internal.h +4 more+103 -102 replies
2/2vfs: Fix inode ownership checks with regard to foreign ownershipfs/attr.c fs/coredump.c fs/inode.c +3 more+74 -522 replies

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchJeffrey Altman
1/2
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/2] vfs, afs, bash: Fix miscomparison of foreign user IDs in the VFS

Hi Christian,

Here's a pair of fixes that deal with some places the VFS mishandles foreign user ID checks. By "foreign" I mean that the user IDs from the filesystem do not belong in the same number space as the system's user IDs. Network filesystems are prime examples of this, but it may also impact things like USB drives or cdroms.

Take AFS as example: Whilst each file does have a numeric user ID, the file may be accessed from a world-accessible public-facing server from some other organisation with its own idea of what that user ID refers to. IDs from AFS may also collide with the system's own set of IDs and may also be unrepresentable as a 32-bit UID (in the case of AuriStor servers).

Further, kAFS uses a key containing an authentication token to specify the subject doing an RPC operation to the server - and, as such, this needs to be used instead of current_fsuid() in determining whether the current user has ownership rights over a file.

Additionally, filesystems (CIFS being a notable example) may also have user identifiers that aren't simple integers.

Now the problem in the VFS is that there are a number of places where it assumes it can directly compare i_uid (possibly id-mapped) to either than on another inode or a UID drawn from elsewhere (e.g. current_uid()) - but this doesn't work right.

This causes the write-to-sticky check to work incorrectly for AFS (though this is currently masked by a workaround in bash that is slated to be removed) whereby open(O_CREAT) of such a file will fail when it shouldn't.

Two patches are provided: The first specifically fixes the bash workaround issue, delegating the check as to whether two inodes have the same owner and the check as to whether the current user owns an inode to the filesystem.

AFS then uses the result of a status-fetch with a suitable key to determine file ownership and just compares the 64-bit owner IDs to determine if two inodes have the same ownership.

The second patch expands the use of the VFS helper functions added by the first to other VFS UID checks.

The patches can be found here:

https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=afs-fixes

Thanks,
David

David Howells (2):
afs, bash: Fix open(O_CREAT) on an extant AFS file in a sticky dir
vfs: Fix inode ownership checks with regard to foreign ownership

 fs/afs/dir.c       |  2 ++
 fs/afs/file.c      |  2 ++
 fs/afs/internal.h  |  3 ++
 fs/afs/security.c  | 52 ++++++++++++++++++++++++++++++
 fs/attr.c          | 58 ++++++++++++++++++++-------------
 fs/coredump.c      |  3 +-
 fs/inode.c         |  8 +++--
 fs/internal.h      |  1 +
 fs/locks.c         |  7 ++--
 fs/namei.c         | 80 ++++++++++++++++++++++++++++++++--------------
 fs/remap_range.c   | 20 ++++++------
 include/linux/fs.h |  3 ++
 12 files changed, 177 insertions(+), 62 deletions(-)