]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ovl: remove privs in ovl_fallocate()
authorAmir Goldstein <amir73il@gmail.com>
Mon, 17 Oct 2022 15:06:39 +0000 (17:06 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Feb 2023 11:55:55 +0000 (12:55 +0100)
commit 23a8ce16419a3066829ad4a8b7032a75817af65b upstream.

Underlying fs doesn't remove privs because fallocate is called with
privileged mounter credentials.

This fixes some failure in fstests generic/683..687.

Fixes: aab8848cee5e ("ovl: add ovl_fallocate()")
Acked-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/overlayfs/file.c

index 259b2d41b70737e0c7d57f7c48b812163fd57cda..0e734c8b4dfa202c87d9adba602ef11374d9eaf0 100644 (file)
@@ -531,9 +531,16 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
        const struct cred *old_cred;
        int ret;
 
+       inode_lock(inode);
+       /* Update mode */
+       ovl_copyattr(ovl_inode_real(inode), inode);
+       ret = file_remove_privs(file);
+       if (ret)
+               goto out_unlock;
+
        ret = ovl_real_fdget(file, &real);
        if (ret)
-               return ret;
+               goto out_unlock;
 
        old_cred = ovl_override_creds(file_inode(file)->i_sb);
        ret = vfs_fallocate(real.file, mode, offset, len);
@@ -544,6 +551,9 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
 
        fdput(real);
 
+out_unlock:
+       inode_unlock(inode);
+
        return ret;
 }