Skip to content

Commit 7fa294c

Browse files
committed
userns: Allow chown and setgid preservation
- Allow chown if CAP_CHOWN is present in the current user namespace and the uid of the inode maps into the current user namespace, and the destination uid or gid maps into the current user namespace. - Allow perserving setgid when changing an inode if CAP_FSETID is present in the current user namespace and the owner of the file has a mapping into the current user namespace. Acked-by: Serge E. Hallyn <[email protected]> Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 5eaf563 commit 7fa294c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fs/attr.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr)
4949
/* Make sure a caller can chown. */
5050
if ((ia_valid & ATTR_UID) &&
5151
(!uid_eq(current_fsuid(), inode->i_uid) ||
52-
!uid_eq(attr->ia_uid, inode->i_uid)) && !capable(CAP_CHOWN))
52+
!uid_eq(attr->ia_uid, inode->i_uid)) &&
53+
!inode_capable(inode, CAP_CHOWN))
5354
return -EPERM;
5455

5556
/* Make sure caller can chgrp. */
5657
if ((ia_valid & ATTR_GID) &&
5758
(!uid_eq(current_fsuid(), inode->i_uid) ||
5859
(!in_group_p(attr->ia_gid) && !gid_eq(attr->ia_gid, inode->i_gid))) &&
59-
!capable(CAP_CHOWN))
60+
!inode_capable(inode, CAP_CHOWN))
6061
return -EPERM;
6162

6263
/* Make sure a caller can chmod. */
@@ -65,7 +66,8 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr)
6566
return -EPERM;
6667
/* Also check the setgid bit! */
6768
if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid :
68-
inode->i_gid) && !capable(CAP_FSETID))
69+
inode->i_gid) &&
70+
!inode_capable(inode, CAP_FSETID))
6971
attr->ia_mode &= ~S_ISGID;
7072
}
7173

@@ -157,7 +159,8 @@ void setattr_copy(struct inode *inode, const struct iattr *attr)
157159
if (ia_valid & ATTR_MODE) {
158160
umode_t mode = attr->ia_mode;
159161

160-
if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
162+
if (!in_group_p(inode->i_gid) &&
163+
!inode_capable(inode, CAP_FSETID))
161164
mode &= ~S_ISGID;
162165
inode->i_mode = mode;
163166
}

0 commit comments

Comments
 (0)