Skip to content

Commit a475acf

Browse files
Seth Forsheeebiederm
authored andcommitted
fs: Refuse uid/gid changes which don't map into s_user_ns
Add checks to notify_change to verify that uid and gid changes will map into the superblock's user namespace. If they do not fail with -EOVERFLOW. This is mandatory so that fileystems don't have to even think of dealing with ia_uid and ia_gid that --EWB Moved the test from inode_change_ok to notify_change Signed-off-by: Seth Forshee <[email protected]> Acked-by: Serge Hallyn <[email protected]> Signed-off-by: Eric W. Biederman <[email protected]>
1 parent aad8289 commit a475acf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fs/attr.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de
255255
if (!(attr->ia_valid & ~(ATTR_KILL_SUID | ATTR_KILL_SGID)))
256256
return 0;
257257

258+
/*
259+
* Verify that uid/gid changes are valid in the target
260+
* namespace of the superblock.
261+
*/
262+
if (ia_valid & ATTR_UID &&
263+
!kuid_has_mapping(inode->i_sb->s_user_ns, attr->ia_uid))
264+
return -EOVERFLOW;
265+
if (ia_valid & ATTR_GID &&
266+
!kgid_has_mapping(inode->i_sb->s_user_ns, attr->ia_gid))
267+
return -EOVERFLOW;
268+
258269
error = security_inode_setattr(dentry, attr);
259270
if (error)
260271
return error;

0 commit comments

Comments
 (0)