[CRIU] APPLIED[F]: [SRU][F][G][H][PATCH] UBUNTU: SAUCE: overlayfs: fix incorrect mnt_id of files opened from map_files

Kelsey Skunberg kelsey.skunberg at canonical.com
Sat May 8 03:54:10 MSK 2021


Applied to F/master-next. thank you! 

-Kelsey

On 2021-04-26 10:55:10 , alexander at mihalicyn.com wrote:
> From: Alexander Mikhalitsyn <alexander at mihalicyn.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1857257
> 
> The hack was introduced in ("UBUNTU: SAUCE: overlayfs: allow with
> shiftfs as underlay") and it broke checkpoint/restore of docker
> contains:
> https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1857257
> 
> The following script can be used to trigger the issue:
>   #!/bin/bash
> 
>   cat > test.py << EOF
>   import sys
> 
>   f = open("/proc/self/maps")
> 
>   for l in f.readlines():
>     if "python" not in l:
>       continue
>     print(l)
>     s = l.split()
>     start, end = s[0].split("-")
>     fname = s[-1]
>     print(start, end, fname)
>     break
>   else:
>     sys.exit(1)
> 
>   test_file1 = open(fname)
>   test_file2 = open("/proc/self/map_files/%s-%s" % (start, end))
> 
>   fdinfo1 = open("/proc/self/fdinfo/%d" % test_file1.fileno()).read()
>   fdinfo2 = open("/proc/self/fdinfo/%d" % test_file2.fileno()).read()
> 
>   if fdinfo1 != fdinfo2:
>     print("FAIL")
>     print(test_file1)
>     print(fdinfo1)
>     print(test_file2)
>     print(fdinfo2)
>     sys.exit(1)
>   print("PASS")
>   EOF
>   sudo docker run -it --privileged --rm -v `pwd`:/mnt python python /mnt/test.py
> 
> Thanks to Andrei Vagin for the reproducer and investigation of this problem.
> 
> Cc: Andrei Vagin <avagin at gmail.com>
> Cc: Adrian Reber <areber at redhat.com>
> Cc: Christian Brauner <christian.brauner at ubuntu.com>
> Cc: Stefan Bader <stefan.bader at canonical.com>
> Cc: Kleber Sacilotto de Souza <kleber.souza at canonical.com>
> 
> Fixes: d24b8a5 ("UBUNTU: SAUCE: overlayfs: allow with shiftfs as underlay")
> Signed-off-by: Alexander Mikhalitsyn <alexander at mihalicyn.com>
> ---
>  fs/overlayfs/file.c      | 17 +++++++++++++++++
>  fs/overlayfs/overlayfs.h | 12 ++++++++++++
>  2 files changed, 29 insertions(+)
> 
> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
> index 0d3ea0cf3e98..7e63eb52bb0d 100644
> --- a/fs/overlayfs/file.c
> +++ b/fs/overlayfs/file.c
> @@ -351,6 +351,23 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
>  		vma->vm_file = file;
>  		fput(realfile);
>  	} else {
> +		/*
> +		 * In map_files_get_link() (fs/proc/base.c)
> +		 * we need to determine correct path from overlayfs.
> +		 * But real_mount(realfile->f_path.mnt) may be not
> +		 * equal to real_mount(file->f_path.mnt). In such case
> +		 * fdinfo of the same file which was opened from
> +		 * /proc/<pid>/map_files/... and "usual" path
> +		 * will show different mnt_id.
> +		 *
> +		 * We solve issue like in aufs by using additional
> +		 * field on struct vm_area_struct called "vm_prfile"
> +		 * which is used only for fdinfo/"printing" needs.
> +		 *
> +		 * See also mm/prfile.c
> +		 */
> +		ovl_vm_prfile_set(vma, file);
> +
>  		/* Drop reference count from previous vm_file value */
>  		fput(file);
>  	}
> diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
> index 5f0188807666..a4e6023b4fdb 100644
> --- a/fs/overlayfs/overlayfs.h
> +++ b/fs/overlayfs/overlayfs.h
> @@ -442,3 +442,15 @@ int ovl_set_origin(struct dentry *dentry, struct dentry *lower,
>  
>  /* export.c */
>  extern const struct export_operations ovl_export_operations;
> +
> +/* handle vma->vm_prfile */
> +static inline void ovl_vm_prfile_set(struct vm_area_struct *vma,
> +				    struct file *file)
> +{
> +	get_file(file);
> +	vma->vm_prfile = file;
> +#ifndef CONFIG_MMU
> +	get_file(file);
> +	vma->vm_region->vm_prfile = file;
> +#endif
> +}
> -- 
> 2.30.2
> 
> 
> -- 
> kernel-team mailing list
> kernel-team at lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team


More information about the CRIU mailing list