fs: add mode_strip_sgid() helper
authorYang Xu <xuyang2018.jy@fujitsu.com>
Thu, 14 Jul 2022 06:11:25 +0000 (14:11 +0800)
committerChristian Brauner (Microsoft) <brauner@kernel.org>
Tue, 19 Jul 2022 13:13:02 +0000 (15:13 +0200)
commit2b3416ceff5e6bd4922f6d1c61fb68113dd82302
tree864514aa9a715b130d2162333656679cec33b23d
parentff6992735ade75aae3e35d16b17da1008d753d28
fs: add mode_strip_sgid() helper

Add a dedicated helper to handle the setgid bit when creating a new file
in a setgid directory. This is a preparatory patch for moving setgid
stripping into the vfs. The patch contains no functional changes.

Currently the setgid stripping logic is open-coded directly in
inode_init_owner() and the individual filesystems are responsible for
handling setgid inheritance. Since this has proven to be brittle as
evidenced by old issues we uncovered over the last months (see [1] to
[3] below) we will try to move this logic into the vfs.

Link: e014f37db1a2 ("xfs: use setattr_copy to set vfs inode attributes") [1]
Link: 01ea173e103e ("xfs: fix up non-directory creation in SGID directories") [2]
Link: fd84bfdddd16 ("ceph: fix up non-directory creation in SGID directories") [3]
Link: https://lore.kernel.org/r/1657779088-2242-1-git-send-email-xuyang2018.jy@fujitsu.com
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Reviewed-and-Tested-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
fs/inode.c
include/linux/fs.h