Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs/kernfs/dir: obey S_ISGID

Handling of S_ISGID is usually done by inode_init_owner() in all other
filesystems, but kernfs doesn't use that function. In kernfs, struct
kernfs_node is the primary data structure, and struct inode is only
created from it on demand. Therefore, inode_init_owner() can't be
used and we need to imitate its behavior.

S_ISGID support is useful for the cgroup filesystem; it allows
subtrees managed by an unprivileged process to retain a certain owner
gid, which then enables sharing access to the subtree with another
unprivileged process.

--
v1 -> v2: minor coding style fix (comment)

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20231208093310.297233-2-max.kellermann@ionos.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Max Kellermann and committed by
Greg Kroah-Hartman
5133bee6 fe3de010

+12
+12
fs/kernfs/dir.c
··· 676 676 { 677 677 struct kernfs_node *kn; 678 678 679 + if (parent->mode & S_ISGID) { 680 + /* this code block imitates inode_init_owner() for 681 + * kernfs 682 + */ 683 + 684 + if (parent->iattr) 685 + gid = parent->iattr->ia_gid; 686 + 687 + if (flags & KERNFS_DIR) 688 + mode |= S_ISGID; 689 + } 690 + 679 691 kn = __kernfs_new_node(kernfs_root(parent), parent, 680 692 name, mode, uid, gid, flags); 681 693 if (kn) {