Skip to content

Commit 5133bee

Browse files
MaxKellermanngregkh
authored andcommitted
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 <[email protected]> Acked-by: Tejun Heo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fe3de01 commit 5133bee

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

fs/kernfs/dir.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,18 @@ struct kernfs_node *kernfs_new_node(struct kernfs_node *parent,
676676
{
677677
struct kernfs_node *kn;
678678

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+
679691
kn = __kernfs_new_node(kernfs_root(parent), parent,
680692
name, mode, uid, gid, flags);
681693
if (kn) {

0 commit comments

Comments
 (0)