Fix up non-directory creation in SGID directories
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 4 Jul 2018 00:10:19 +0000 (17:10 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 17 Jul 2018 09:37:53 +0000 (11:37 +0200)
commitd2c7c52431819aa05d76fae77bb3f95dd0955da1
tree3551b7921cfcd834471b1bfde1d3cb5210345c48
parent16387eb51caa0828de1d78e605523a6d738a7f3f
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>
fs/inode.c