usb: gadget: fsl_qe_udc: off by one in setup_received_handle()
[cascardo/linux.git] / fs / attr.c
index 25b24d0..42bb42b 100644 (file)
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -255,6 +255,25 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de
        if (!(attr->ia_valid & ~(ATTR_KILL_SUID | ATTR_KILL_SGID)))
                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;
+
+       /* Don't allow modifications of files with invalid uids or
+        * gids unless those uids & gids are being made valid.
+        */
+       if (!(ia_valid & ATTR_UID) && !uid_valid(inode->i_uid))
+               return -EOVERFLOW;
+       if (!(ia_valid & ATTR_GID) && !gid_valid(inode->i_gid))
+               return -EOVERFLOW;
+
        error = security_inode_setattr(dentry, attr);
        if (error)
                return error;