Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a475acf0 authored by Seth Forshee's avatar Seth Forshee Committed by Eric W. Biederman
Browse files

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: default avatarSeth Forshee <seth.forshee@canonical.com>
Acked-by: default avatarSerge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
parent aad82892
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -255,6 +255,17 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de
	if (!(attr->ia_valid & ~(ATTR_KILL_SUID | ATTR_KILL_SGID)))
	if (!(attr->ia_valid & ~(ATTR_KILL_SUID | ATTR_KILL_SGID)))
		return 0;
		return 0;


	/*
	 * Verify that uid/gid changes are valid in the target
	 * namespace of the superblock.
	 */
	if (ia_valid & ATTR_UID &&
	    !kuid_has_mapping(inode->i_sb->s_user_ns, attr->ia_uid))
		return -EOVERFLOW;
	if (ia_valid & ATTR_GID &&
	    !kgid_has_mapping(inode->i_sb->s_user_ns, attr->ia_gid))
		return -EOVERFLOW;

	error = security_inode_setattr(dentry, attr);
	error = security_inode_setattr(dentry, attr);
	if (error)
	if (error)
		return error;
		return error;