Skip to content

Commit

Permalink
memfd: reopen only with non-default flags
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Mirosław <[email protected]>
  • Loading branch information
osctobe committed Aug 9, 2023
1 parent 29387d3 commit cb86d77
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions criu/memfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,23 @@ int memfd_open(struct file_desc *d, u32 *fdflags)

/* Reopen the fd with original permissions */
flags = fdflags ? *fdflags : mfe->flags;
/*
* Ideally we should call compat version open() to not force the
* O_LARGEFILE file flag with regular open(). It doesn't seem that
* important though.
*/
_fd = __open_proc(PROC_SELF, 0, flags, "fd/%d", fd);
if (_fd < 0) {
pr_perror("Can't reopen memfd id=%d", mfe->id);
if ((flags & O_ACCMODE) != O_RDWR) {
/*
* Ideally we should call compat version open() to not force the
* O_LARGEFILE file flag with regular open(). It doesn't seem that
* important though.
*/
_fd = __open_proc(PROC_SELF, 0, flags, "fd/%d", fd);
if (_fd < 0) {
pr_perror("Can't reopen memfd id=%d", mfe->id);
goto err;
}
close(fd);
fd = _fd;
} else if (fcntl(fd, F_SETFL, flags)) {
pr_perror("Can't change fd flags to %#o for memfd id=%d", flags, mfe->id);
goto err;
}
close(fd);
fd = _fd;

return fd;

Expand Down

0 comments on commit cb86d77

Please sign in to comment.