Skip to content

Commit

Permalink
Fix dumping hugetlb-based memfd on kernels < 4.16.
Browse files Browse the repository at this point in the history
4.15-based kernels don't allow F_*SEAL for memfds created with MFD_HUGETLB.
Since seals are not possible in this case, fake F_GETSEALS result as if it
was queried for a non-sealing-enabled memfd.

Signed-off-by: Michał Mirosław <emmir@google.com>
  • Loading branch information
osctobe authored and avagin committed Jun 15, 2023
1 parent 4d137b8 commit af0e413
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions criu/memfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,17 @@ static int dump_memfd_inode(int fd, struct memfd_dump_inode *inode, const char *
}

mie.seals = fcntl(fd, F_GET_SEALS);
if (mie.seals == -1)
goto out;
if (mie.seals == -1) {
if (errno != EINVAL || ~mie.hugetlb_flag & MFD_HUGETLB) {
pr_perror("fcntl(F_GET_SEALS)");
goto out;
}
/* Kernels before 4.16 don't allow MFD_HUGETLB |
* MFD_ALLOW_SEALING and return EINVAL for
* fcntl(MFD_HUGETLB-enabled fd).
*/
mie.seals = F_SEAL_SEAL;
}

if (pb_write_one(img_from_set(glob_imgset, CR_FD_MEMFD_INODE), &mie, PB_MEMFD_INODE))
goto out;
Expand Down

0 comments on commit af0e413

Please sign in to comment.