From nobody Sun Feb 8 15:58:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D4BD40F8C8 for ; Thu, 22 Jan 2026 15:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769095141; cv=none; b=LuhBnGQnyXL+SF4iwWmGn2Q66YAkW2Fy4Ls41ES1x4oa+3YIxNZ/r0cfRgSlNOvaSjmIcstmS+c4XFWpNIt+3gs6hpkaRSFU0CmPClHNPaYPDQ4X43RyoH+zCDjInlTTzAtJEpXTEewGwlDpnL9+7tU95baij/iiK8b4yusPMTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769095141; c=relaxed/simple; bh=YLJlkAxZgahTe6DNHbxTJdYXwUdyk5vxfIME+2fG3k4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gudmu8nOXSll4eKHHKro11LZJaCsl1N+twSadB1Rsx1PlzWsosMuCI6OE5sXgPUVJztkHnIbQJicganD26a0qgLqnEOg3D40ez2d8QDXZoiS1pwZykuRZhQ6vlV2C5t8l68umfotqPbx0jjihp0McPUaR5fCUUzvXwXzel3kyW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZX7P+4UF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZX7P+4UF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA89BC116C6; Thu, 22 Jan 2026 15:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769095141; bh=YLJlkAxZgahTe6DNHbxTJdYXwUdyk5vxfIME+2fG3k4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZX7P+4UF9IYUrVIBMSwkZXOxFg4C4bYpv88wdSwsODGZatPaTAAHNDBjQn/qZX4N8 13Gtn9SyiPwYl0ljdV4idd1buk9vvd1oFf2hYK+tledpfTNbEMF2CpZh9bVBNMRz0F qEHoKrhq7mSwWDSXkyDEgEyPBHOGJMAVEVS3iDtik76/OupwBO6vfgcm1bRoINpkKv TKi5Ty3kvB4cl4zeyEGirEK77KJjMR1oSpVcws0tbAhnoOZu07x/2sCprKQ/Dugdt3 dJRyQg/FLVKexjSgiDRpxH1tWzst5yL7b3nYixzKI+QqCu0RbX05n82FWjbqFHgkMI SoxcYB7hYnDsw== From: Pratyush Yadav To: Hugh Dickins , Baolin Wang , Andrew Morton , Pasha Tatashin , Mike Rapoport , Pratyush Yadav Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm: memfd_luo: use memfd_alloc_file() instead of shmem_file_setup() Date: Thu, 22 Jan 2026 16:18:40 +0100 Message-ID: <20260122151842.4069702-3-pratyush@kernel.org> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog In-Reply-To: <20260122151842.4069702-1-pratyush@kernel.org> References: <20260122151842.4069702-1-pratyush@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Pratyush Yadav (Google)" 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. Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd") Signed-off-by: Pratyush Yadav (Google) Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pasha Tatashin --- mm/memfd_luo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c index 4f6ba63b4310..01a72e4d3ef6 100644 --- a/mm/memfd_luo.c +++ b/mm/memfd_luo.c @@ -78,6 +78,7 @@ #include #include #include +#include #include "internal.h" =20 static int memfd_luo_preserve_folios(struct file *file, @@ -443,8 +444,7 @@ static int memfd_luo_retrieve(struct liveupdate_file_op= _args *args) if (!ser) return -EINVAL; =20 - file =3D shmem_file_setup("", 0, VM_NORESERVE); - + file =3D memfd_alloc_file("", 0); if (IS_ERR(file)) { pr_err("failed to setup file: %pe\n", file); return PTR_ERR(file); --=20 2.52.0.457.g6b5491de43-goog