Skip to content

Commit 02e117b

Browse files
prati0100akpm00
authored andcommitted
mm: memfd_luo: use memfd_alloc_file() instead of shmem_file_setup()
When restoring a memfd, the file is created using shmem_file_setup(). While memfd creation also calls this function to get the file, it also does other things: 1. The O_LARGEFILE flag is set on the file. If this is not done, writes on the memfd exceeding 2 GiB fail. 2. FMODE_LSEEK, FMODE_PREAD, and FMODE_PWRITE are set on the file. This makes sure the file is seekable and can be used with pread() and pwrite(). 3. Initializes the security field for the inode and makes sure that inode creation is permitted by the security module. Currently, none of those things are done. This means writes above 2 GiB fail, pread(), and pwrite() fail, and so on. lseek() happens to work because file_init_path() sets it because shmem defines fop->llseek. Fix this by using memfd_alloc_file() to get the file to make sure the initialization sequence for normal and preserved memfd is the same. Link: https://lkml.kernel.org/r/20260122151842.4069702-3-pratyush@kernel.org Fixes: b3749f1 ("mm: memfd_luo: allow preserving memfd") Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 71e2b5e commit 02e117b

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

mm/memfd_luo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include <linux/liveupdate.h>
7979
#include <linux/shmem_fs.h>
8080
#include <linux/vmalloc.h>
81+
#include <linux/memfd.h>
8182
#include "internal.h"
8283

8384
static int memfd_luo_preserve_folios(struct file *file,
@@ -443,8 +444,7 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)
443444
if (!ser)
444445
return -EINVAL;
445446

446-
file = shmem_file_setup("", 0, VM_NORESERVE);
447-
447+
file = memfd_alloc_file("", 0);
448448
if (IS_ERR(file)) {
449449
pr_err("failed to setup file: %pe\n", file);
450450
return PTR_ERR(file);

0 commit comments

Comments
 (0)