diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-07-04 03:10:19 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-07-17 12:39:27 +0300 |
commit | 298243a5fb640f018e2fae22c0c895f1b27f0963 (patch) | |
tree | b5605da8d6fad6259c4e8cca09ef0426a28fe0d0 | |
parent | a6d26649fda0274b54fde2b84e61c09dca73e934 (diff) | |
download | linux-298243a5fb640f018e2fae22c0c895f1b27f0963.tar.xz |
Fix up non-directory creation in SGID directories
commit 0fa3ecd87848c9c93c2c828ef4c3a8ca36ce46c7 upstream.
sgid directories have special semantics, making newly created files in
the directory belong to the group of the directory, and newly created
subdirectories will also become sgid. This is historically used for
group-shared directories.
But group directories writable by non-group members should not imply
that such non-group members can magically join the group, so make sure
to clear the sgid bit on non-directories for non-members (but remember
that sgid without group execute means "mandatory locking", just to
confuse things even more).
Reported-by: Jann Horn <jannh@google.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | fs/inode.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/fs/inode.c b/fs/inode.c index e07b3e1f5970..cfc36d11bcb3 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2006,8 +2006,14 @@ void inode_init_owner(struct inode *inode, const struct inode *dir, inode->i_uid = current_fsuid(); if (dir && dir->i_mode & S_ISGID) { inode->i_gid = dir->i_gid; + + /* Directories are special, and always inherit S_ISGID */ if (S_ISDIR(mode)) mode |= S_ISGID; + else if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP) && + !in_group_p(inode->i_gid) && + !capable_wrt_inode_uidgid(dir, CAP_FSETID)) + mode &= ~S_ISGID; } else inode->i_gid = current_fsgid(); inode->i_mode = mode; |