Skip to contentSkip to conversation

mm-memfd_luo-use-memfd_alloc_file-instead-of-shmem_file_setup.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message Jan 27

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm: memfd_luo: use memfd_alloc_file() instead of shmem_file_setup()
has been removed from the -mm tree. Its filename was
mm-memfd_luo-use-memfd_alloc_file-instead-of-shmem_file_setup.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: "Pratyush Yadav (Google)" <[email protected]>
Subject: mm: memfd_luo: use memfd_alloc_file() instead of shmem_file_setup()
Date: Thu, 22 Jan 2026 16:18:40 +0100

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.

---

 mm/memfd_luo.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memfd_luo.c renamed from mm/memfd_luo.c~mm-memfd_luo-use-memfd_alloc_file-instead-of-shmem_file_setup +2 -2
@@ -78,6 +78,7 @@
 #include <linux/liveupdate.h>
 #include <linux/shmem_fs.h>
 #include <linux/vmalloc.h>
+#include <linux/memfd.h>
 #include "internal.h"
 
 static int memfd_luo_preserve_folios(struct file *file,
@@ -443,8 +444,7 @@ static int memfd_luo_retrieve(struct liv
 	if (!ser)
 		return -EINVAL;
 
-	file = shmem_file_setup("", 0, VM_NORESERVE);
-
+	file = memfd_alloc_file("", 0);
 	if (IS_ERR(file)) {
 		pr_err("failed to setup file: %pe\n", file);
 		return PTR_ERR(file);

_

Patches currently in -mm which might be from [email protected] are

liveupdate-luo_file-do-not-clear-serialized_data-on-unfreeze.patch liveupdate-luo_file-remember-retrieve-status.patch memfd-export-memfd_addget_seals.patch mm-memfd_luo-preserve-file-seals.patch kho-use-unsigned-long-for-nr_pages.patch kho-simplify-page-initialization-in-kho_restore_page.patch