[PATCH 1/2] mm: memfd_luo: pick up seals added after preserve at freeze

From: Long Wei

Date: Sat Nov 28 2026 - 02:27:30 EST


A seal added to a memfd after the memfd was preserved with a
liveupdate session is accepted without any error, but once the kexec
handover is over the retrieved memfd no longer has it: the change
silently disappears instead of being rejected.

memfd_luo_preserve() snapshots the file seals into the serialized
state, but userspace may keep operating on the memfd until the
handover, by design, so the preserve-time snapshot is naturally
incomplete: a seal can be added at any point in the window between
preserve() and kexec. memfd_luo_freeze() only re-read the file
position and retrieve() replays the frozen snapshot, so those window
changes were never picked up. Freeze is the last point before kexec
where they can still be sampled; there is no second chance after it.

Re-read the seals at freeze time, mirroring the file position
handling: freeze is the final snapshot point and changes made after
it are not preserved. The new seal set is only revalidated when it
actually diverged from the preserve-time snapshot, and the validation
must fail here rather than at retrieve(): while the old kernel is
still in control the live update can still be aborted, but after the
handover a seal that memfd_luo_retrieve() cannot replay would already
be past the point of no return.

Fixes: 8a552d68a86e ("mm: memfd_luo: preserve file seals")
Signed-off-by: Long Wei <longwei27@xxxxxxxxxx>
---
mm/memfd_luo.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c
index 6b68220275eb..08524125475e 100644
--- a/mm/memfd_luo.c
+++ b/mm/memfd_luo.c
@@ -54,6 +54,9 @@
* File seals set on the memfd are preserved and re-applied on restore.
* Only seals known to this LUO version (see ``MEMFD_LUO_ALL_SEALS``) may
* be present; preservation fails with ``-EOPNOTSUPP`` otherwise.
+ * Seals added after preserve are picked up when the file is frozen for
+ * kexec. Freeze is the final snapshot point: like the file position,
+ * changes made after it are not preserved.
*
* Restrictions
* ============
@@ -322,7 +325,9 @@ static int memfd_luo_preserve(struct liveupdate_file_op_args *args)

static int memfd_luo_freeze(struct liveupdate_file_op_args *args)
{
+ struct inode *inode = file_inode(args->file);
struct memfd_luo_ser *ser;
+ int seals;

if (WARN_ON_ONCE(!args->serialized_data))
return -EINVAL;
@@ -330,10 +335,28 @@ static int memfd_luo_freeze(struct liveupdate_file_op_args *args)
ser = phys_to_virt(args->serialized_data);

/*
- * The pos might have changed since prepare. Everything else stays the
- * same.
+ * F_ADD_SEALS takes inode_lock, so sample the seals under the same
+ * lock to get a consistent final value. f_pos is sampled here under
+ * the same inode_lock as preserve did; freeze is the last snapshot
+ * point for both.
*/
+ inode_lock(inode);
+ seals = memfd_get_seals(args->file);
+ if (seals < 0) {
+ inode_unlock(inode);
+ return seals;
+ }
+
+ if (seals != ser->seals) {
+ if (seals & ~MEMFD_LUO_ALL_SEALS) {
+ inode_unlock(inode);
+ return -EOPNOTSUPP;
+ }
+ ser->seals = seals;
+ }
+
ser->pos = args->file->f_pos;
+ inode_unlock(inode);

return 0;
}
--
2.43.0