Commit 963f8a06 authored by Jamie Liu's avatar Jamie Liu Committed by Pavel Emelyanov

files-reg: fix "criu: fix filemap open permissions"

Fixes two issues with efe594f8 "criu: fix filemap open permissions":

- Permissions on files with both open file descriptors and mappings.

- Restore compatibility with dumps created by previous versions of criu.
Signed-off-by: 's avatarJamie Liu <jamieliu@google.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 4848ef66
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <sys/mman.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/vfs.h> #include <sys/vfs.h>
...@@ -656,11 +657,12 @@ int open_path(struct file_desc *d, ...@@ -656,11 +657,12 @@ int open_path(struct file_desc *d,
return tmp; return tmp;
} }
static int do_open_reg_noseek(struct reg_file_info *rfi, void *arg) static int do_open_reg_noseek_flags(struct reg_file_info *rfi, void *arg)
{ {
u32 flags = *(u32 *)arg;
int fd; int fd;
fd = open(rfi->path, rfi->rfe->flags); fd = open(rfi->path, flags);
if (fd < 0) { if (fd < 0) {
pr_perror("Can't open file %s on restore", rfi->path); pr_perror("Can't open file %s on restore", rfi->path);
return fd; return fd;
...@@ -669,6 +671,11 @@ static int do_open_reg_noseek(struct reg_file_info *rfi, void *arg) ...@@ -669,6 +671,11 @@ static int do_open_reg_noseek(struct reg_file_info *rfi, void *arg)
return fd; return fd;
} }
static int do_open_reg_noseek(struct reg_file_info *rfi, void *arg)
{
return do_open_reg_noseek_flags(rfi, &rfi->rfe->flags);
}
static int do_open_reg(struct reg_file_info *rfi, void *arg) static int do_open_reg(struct reg_file_info *rfi, void *arg)
{ {
int fd; int fd;
...@@ -708,7 +715,7 @@ int open_reg_by_id(u32 id) ...@@ -708,7 +715,7 @@ int open_reg_by_id(u32 id)
int get_filemap_fd(struct vma_area *vma) int get_filemap_fd(struct vma_area *vma)
{ {
struct reg_file_info *rfi; u32 flags;
/* /*
* Thevma->fd should have been assigned in collect_filemap * Thevma->fd should have been assigned in collect_filemap
...@@ -717,14 +724,15 @@ int get_filemap_fd(struct vma_area *vma) ...@@ -717,14 +724,15 @@ int get_filemap_fd(struct vma_area *vma)
*/ */
BUG_ON(vma->fd == NULL); BUG_ON(vma->fd == NULL);
rfi = container_of(vma->fd, struct reg_file_info, d);
if (vma->e->has_fdflags) if (vma->e->has_fdflags)
rfi->rfe->flags = vma->e->fdflags; flags = vma->e->fdflags;
else { else if ((vma->e->prot & PROT_WRITE) &&
pr_err("vma %#lx missing fdflags", vma->e->start); vma_area_is(vma, VMA_FILE_SHARED))
return -1; flags = O_RDWR;
} else
return open_path(vma->fd, do_open_reg_noseek, NULL); flags = O_RDONLY;
return open_path(vma->fd, do_open_reg_noseek_flags, &flags);
} }
static void remap_get(struct file_desc *fdesc, char typ) static void remap_get(struct file_desc *fdesc, char typ)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment