From nobody Thu Mar 5 06:30:49 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 9E51B2E9749 for ; Mon, 16 Feb 2026 19:00: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=1771268401; cv=none; b=MuhdN3RUbPDq6J+zOAboS8brBhRxyWPzbt8OCK3QFoNwGh3eCSS9BikdlunXHNu+iG1gLFNkPy6F+5q8lyYvz2o6gSxKsQ1iMSEPso9nrH6LYsXx55naOsMbbM5GY4WQfTw4L1/UQEi/Hk+Jtv3qVXFoktlqQOXQ4l1OasdDp/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771268401; c=relaxed/simple; bh=6Hh3KYw2Jyb1btkJg7DMiLM+J1fGkbsEdPXZYlYEctY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G9xjnmhJweQtbEx0vc85dhigfExYkRUeMNLBvgVTFQhopWLHeJlRUMNZPJAE3g76n6kLCsTLvdWxQX1nmiOsKKEfCFtF2L2/Pmf0bawrMRNfGK91nlPZ/5UtVhaDy+zkVVPvhfRjMzOfnun/Zfig+6UT3phszg985CgDyftQV5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OhrvYoaV; 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="OhrvYoaV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44499C19422; Mon, 16 Feb 2026 18:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771268401; bh=6Hh3KYw2Jyb1btkJg7DMiLM+J1fGkbsEdPXZYlYEctY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OhrvYoaV8utxpqTBno7SbwJVX0AU+R7vbcXf+xXIJS/M7LfbjsrGjyg7hefx912jU h7aAkI7h2dJTIHUkFGciVaMnHvtGJnHwex2MjrPSU0A8PLd+lFsmTPGBVh5aoKsZUH g17wZ0SmTm+fvGPCvJ6XZlkUx4KTWjNK/ktTwNTvRRtGxbf4e4cOrFaxWT92RWogmt CXyjVnEnhA4+I4jMzg6zzL1snyXnjK9e8V3QWjI1JGPZIKaPNvK3/RDDRgoCHgHmPj ZzJxAo0ixeA0nQFity8fNEte4xt0YGsiS9B0R/ZJ3mwnclbsdMGvOXlnalX4FdMYmD +35c/JPjEJUxA== From: Pratyush Yadav To: Alexander Graf , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Hugh Dickins , Baolin Wang , Andrew Morton Cc: Jason Gunthorpe , Samiullah Khawaja , kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] memfd: export memfd_{add,get}_seals() Date: Mon, 16 Feb 2026 19:59:32 +0100 Message-ID: <20260216185946.1215770-2-pratyush@kernel.org> X-Mailer: git-send-email 2.53.0.335.g19a08e0c02-goog In-Reply-To: <20260216185946.1215770-1-pratyush@kernel.org> References: <20260216185946.1215770-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)" Support for preserving file seals will be added to memfd preservation using the Live Update Orchestrator (LUO). Export memfd_{add,get}_seals)() so memfd_luo can use them to manipulate the seals. Signed-off-by: Pratyush Yadav (Google) Acked-by: Mike Rapoport (Microsoft) Tested-by: Samiullah Khawaja --- include/linux/memfd.h | 12 ++++++++++++ mm/memfd.c | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/linux/memfd.h b/include/linux/memfd.h index c328a7b356d0..b4fda09dab9f 100644 --- a/include/linux/memfd.h +++ b/include/linux/memfd.h @@ -18,6 +18,8 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff= _t idx); */ int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr); struct file *memfd_alloc_file(const char *name, unsigned int flags); +int memfd_get_seals(struct file *file); +int memfd_add_seals(struct file *file, unsigned int seals); #else static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned in= t a) { @@ -37,6 +39,16 @@ static inline struct file *memfd_alloc_file(const char *= name, unsigned int flags { return ERR_PTR(-EINVAL); } + +static inline int memfd_get_seals(struct file *file) +{ + return -EINVAL; +} + +static inline int memfd_add_seals(struct file *file, unsigned int seals) +{ + return -EINVAL; +} #endif =20 #endif /* __LINUX_MEMFD_H */ diff --git a/mm/memfd.c b/mm/memfd.c index f032c6052926..46c5508beea4 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -228,7 +228,7 @@ static unsigned int *memfd_file_seals_ptr(struct file *= file) F_SEAL_WRITE | \ F_SEAL_FUTURE_WRITE) =20 -static int memfd_add_seals(struct file *file, unsigned int seals) +int memfd_add_seals(struct file *file, unsigned int seals) { struct inode *inode =3D file_inode(file); unsigned int *file_seals; @@ -310,7 +310,7 @@ static int memfd_add_seals(struct file *file, unsigned = int seals) return error; } =20 -static int memfd_get_seals(struct file *file) +int memfd_get_seals(struct file *file) { unsigned int *seals =3D memfd_file_seals_ptr(file); =20 --=20 2.53.0.335.g19a08e0c02-goog From nobody Thu Mar 5 06:30:49 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 A05FE2E03F1 for ; Mon, 16 Feb 2026 19:00:04 +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=1771268404; cv=none; b=OXPHCyLTYoxjYTsoniSemZywMtJ7SsAJac7y+xNuRe2qkaLRRhfrkzhzDrYW/A395fCM1U+kxHllKRKcE/+Moit6OzMHO6pN3JUMU7+IX1oUa/gOUA7duBbjrP/ANk8oUOvzswWKiNTbP6BZiSdmW9SMKyk63xFQpR2GqN3Mk9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771268404; c=relaxed/simple; bh=rDOaaAXfsrj1RbVbSoaAqlUcovoTYZIHYJI6Tev+jiM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UpNPMLMdTAenP32vh2oujw1LYCYXOKDBf5qxcwU1vrykqjxYkJU7klO8cVA3t8Gky0OxQQbzOBkJ8PqE1ImQztcxkJjQD5rwfR6R8Ui3/e3BPz66chI05z6ZoVBb7JxRjoH2dB2kwXC9KjVOM2fNOOxQn0nvDUZIpSmbE0zATHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WB0rrATC; 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="WB0rrATC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C246C2BC86; Mon, 16 Feb 2026 19:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771268404; bh=rDOaaAXfsrj1RbVbSoaAqlUcovoTYZIHYJI6Tev+jiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WB0rrATCc8Fbi5vyGG8WQkNokaNW1LgErS/3q32Ighfuf0ahEGDeJY9f6O/Se2cuo CTXwAVY4Vkd/yhyQ2LEo6iz/dKeafOBFuVBLApOwWRxwHSl33QfG4qtG4p5X8Lnddp FAUbjSrRxJYtpGjrWOqXZY4PgvloHvg2jOJi7QmIDacsAbydDVEzAnXxchRaIKA+ic AcU+782hhuzKCsU8YUzWUFxtx+nhsTeRVpsk02QNYKk824asOqIshbCZzjqs453VAg QzObg1aBpfVZZ5ma2OyOlf0j1dj+bJXM07jn1t/05mbhcQBsJlcOwK/jen7HfOkUgk w0Az9nnUvBxmQ== From: Pratyush Yadav To: Alexander Graf , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Hugh Dickins , Baolin Wang , Andrew Morton Cc: Jason Gunthorpe , Samiullah Khawaja , kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] mm: memfd_luo: preserve file seals Date: Mon, 16 Feb 2026 19:59:33 +0100 Message-ID: <20260216185946.1215770-3-pratyush@kernel.org> X-Mailer: git-send-email 2.53.0.335.g19a08e0c02-goog In-Reply-To: <20260216185946.1215770-1-pratyush@kernel.org> References: <20260216185946.1215770-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)" File seals are used on memfd for making shared memory communication with untrusted peers safer and simpler. Seals provide a guarantee that certain operations won't be allowed on the file such as writes or truncations. Maintaining these guarantees across a live update will help keeping such use cases secure. These guarantees will also be needed for IOMMUFD preservation with LUO. Normally when IOMMUFD maps a memfd, it pins all its pages to make sure any truncation operations on the memfd don't lead to IOMMUFD using freed memory. This doesn't work with LUO since the preserved memfd might have completely different pages after a live update, and mapping them back to the IOMMUFD will cause all sorts of problems. Using and preserving the seals allows IOMMUFD preservation logic to trust the memfd. Since the uABI defines seals as an int, preserve them by introducing a new u32 field. There are currently only 6 possible seals, so the extra bits are unused and provide room for future expansion. Since the seals are uABI, it is safe to use them directly in the ABI. While at it, also add a u32 flags field. It makes sure the struct is nicely aligned, and can be used later to support things like MFD_CLOEXEC. Since the serialization structure is changed, bump the version number to "memfd-v2". It is important to note that the memfd-v2 version only supports seals that existed when this version was defined. This set is defined by MEMFD_LUO_ALL_SEALS. Any new seal might bring a completely different semantic with it and the parser for memfd-v2 cannot be expected to deal with that. If there are any future seals added, they will need another version bump. Signed-off-by: Pratyush Yadav (Google) Tested-by: Samiullah Khawaja --- include/linux/kho/abi/memfd.h | 18 +++++++++++++++++- mm/memfd_luo.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/include/linux/kho/abi/memfd.h b/include/linux/kho/abi/memfd.h index 68cb6303b846..08b10fea2afc 100644 --- a/include/linux/kho/abi/memfd.h +++ b/include/linux/kho/abi/memfd.h @@ -56,10 +56,24 @@ struct memfd_luo_folio_ser { u64 index; } __packed; =20 +/* + * The set of seals this version supports preserving. If support for any n= ew + * seals is needed, add it here and bump version. + */ +#define MEMFD_LUO_ALL_SEALS (F_SEAL_SEAL | \ + F_SEAL_SHRINK | \ + F_SEAL_GROW | \ + F_SEAL_WRITE | \ + F_SEAL_FUTURE_WRITE | \ + F_SEAL_EXEC) + /** * struct memfd_luo_ser - Main serialization structure for a memfd. * @pos: The file's current position (f_pos). * @size: The total size of the file in bytes (i_size). + * @seals: The seals present on the memfd. The seals are uABI so it is= safe + * to directly use them in the ABI. + * @flags: Flags for the file. Unused flag bits must be set to 0. * @nr_folios: Number of folios in the folios array. * @folios: KHO vmalloc descriptor pointing to the array of * struct memfd_luo_folio_ser. @@ -67,11 +81,13 @@ struct memfd_luo_folio_ser { struct memfd_luo_ser { u64 pos; u64 size; + u32 seals; + u32 flags; u64 nr_folios; struct kho_vmalloc folios; } __packed; =20 /* The compatibility string for memfd file handler */ -#define MEMFD_LUO_FH_COMPATIBLE "memfd-v1" +#define MEMFD_LUO_FH_COMPATIBLE "memfd-v2" =20 #endif /* _LINUX_KHO_ABI_MEMFD_H */ diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c index a34fccc23b6a..1089dbcf5ca6 100644 --- a/mm/memfd_luo.c +++ b/mm/memfd_luo.c @@ -79,6 +79,8 @@ #include #include #include +#include + #include "internal.h" =20 static int memfd_luo_preserve_folios(struct file *file, @@ -222,7 +224,7 @@ static int memfd_luo_preserve(struct liveupdate_file_op= _args *args) struct memfd_luo_folio_ser *folios_ser; struct memfd_luo_ser *ser; u64 nr_folios; - int err =3D 0; + int err =3D 0, seals; =20 inode_lock(inode); shmem_freeze(inode, true); @@ -234,8 +236,21 @@ static int memfd_luo_preserve(struct liveupdate_file_o= p_args *args) goto err_unlock; } =20 + seals =3D memfd_get_seals(args->file); + if (seals < 0) { + err =3D seals; + goto err_free_ser; + } + + /* Make sure the file only has the seals supported by this version. */ + if (seals & ~MEMFD_LUO_ALL_SEALS) { + err =3D -EOPNOTSUPP; + goto err_free_ser; + } + ser->pos =3D args->file->f_pos; ser->size =3D i_size_read(inode); + ser->seals =3D seals; =20 err =3D memfd_luo_preserve_folios(args->file, &ser->folios, &folios_ser, &nr_folios); @@ -444,13 +459,29 @@ static int memfd_luo_retrieve(struct liveupdate_file_= op_args *args) if (!ser) return -EINVAL; =20 - file =3D memfd_alloc_file("", 0); + /* Make sure the file only has seals supported by this version. */ + if (ser->seals & ~MEMFD_LUO_ALL_SEALS) { + err =3D -EOPNOTSUPP; + goto free_ser; + } + + /* + * The seals are preserved. Allow sealing here so they can be added + * later. + */ + file =3D memfd_alloc_file("", MFD_ALLOW_SEALING); if (IS_ERR(file)) { pr_err("failed to setup file: %pe\n", file); err =3D PTR_ERR(file); goto free_ser; } =20 + err =3D memfd_add_seals(file, ser->seals); + if (err) { + pr_err("failed to add seals: %pe\n", ERR_PTR(err)); + goto put_file; + } + vfs_setpos(file, ser->pos, MAX_LFS_FILESIZE); file->f_inode->i_size =3D ser->size; =20 --=20 2.53.0.335.g19a08e0c02-goog