filelocks: use mount idmapping for setlease permission check
authorSeth Forshee <sforshee@kernel.org>
Thu, 9 Mar 2023 20:39:09 +0000 (14:39 -0600)
committerChristian Brauner (Microsoft) <brauner@kernel.org>
Thu, 9 Mar 2023 21:36:12 +0000 (22:36 +0100)
A user should be allowed to take out a lease via an idmapped mount if
the fsuid matches the mapped uid of the inode. generic_setlease() is
checking the unmapped inode uid, causing these operations to be denied.

Fix this by comparing against the mapped inode uid instead of the
unmapped uid.

Fixes: 9caccd41541a ("fs: introduce MOUNT_ATTR_IDMAP")
Cc: stable@vger.kernel.org
Signed-off-by: Seth Forshee (DigitalOcean) <sforshee@kernel.org>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
fs/locks.c

index d82c4cacdfb9fd6bf872e3b8b3f044357991902a..df8b26a425248ac4aa87a4ef9772b9700b417209 100644 (file)
@@ -1863,9 +1863,10 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp,
                        void **priv)
 {
        struct inode *inode = file_inode(filp);
+       vfsuid_t vfsuid = i_uid_into_vfsuid(file_mnt_idmap(filp), inode);
        int error;
 
-       if ((!uid_eq(current_fsuid(), inode->i_uid)) && !capable(CAP_LEASE))
+       if ((!vfsuid_eq_kuid(vfsuid, current_fsuid())) && !capable(CAP_LEASE))
                return -EACCES;
        if (!S_ISREG(inode->i_mode))
                return -EINVAL;