mm: memfd_luo: pick up seals added after preserve at freeze
Subsystems (4)
cover mm: memfd_luo: pick up seals added after preserve at freeze
A seal added to a memfd after the memfd was preserved with a liveupdate session is accepted without any error, but the seal is silently gone once the kexec handover is over: the retrieved memfd no longer has it.
memfd_luo_preserve() snapshots the file seals, but userspace may keep operating on the memfd until the handover, so the preserve-time snapshot is naturally incomplete. memfd_luo_freeze() never re-read the seals and memfd_luo_retrieve() replays the stale snapshot, so seals added in the window between preserve() and kexec were dropped without any notice.
Patch 1 re-reads the seals at freeze time, mirroring the file position
handling: freeze is the last snapshot point before kexec and the only place where the final value can still be sampled and, when it diverged from the preserve-time snapshot, validated while the live update can still be aborted.
Patch 2 adds a kexec round-trip selftest that adds F_SEAL_GROW after preserve and asserts that the seal survives the handover.
Tested on arm64 and x86_64 with two consecutive kexec handovers each:
with the fix the seal survives and dmesg stays free of new warnings.
This series applies on the current next branch of liveupdate.git, where the file is still named memfd_luo.c. I am aware of the pending "mm: Rename memfd_luo to shmem_luo" series. If that series lands first, a trivial s/memfd_luo/shmem_luo/ rebase will be needed, which I am happy to provide.
Long Wei (2):
mm: memfd_luo: pick up seals added after preserve at freeze selftests/liveupdate: add seal-after-preserve kexec test
mm/memfd_luo.c | 27 ++- tools/testing/selftests/liveupdate/Makefile | 1 + .../liveupdate/luo_seal_after_preserve.c | 170 ++++++++++++++++++ .../selftests/liveupdate/run-vmtests.sh | 1 + 4 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/liveupdate/luo_seal_after_preserve.c
Signature · 1 line
2.43.0
PATCH 1/2 mm: memfd_luo: pick up seals added after preserve at freeze
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.
--- mm/memfd_luo.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
mm/memfd_luo.c +25 -2
@@ -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 ; }
Signature · 1 line
2.43.0
PATCH 2/2 selftests/liveupdate: add seal-after-preserve kexec test
In reply to Long WeiAdd luo_seal_after_preserve, a kexec test that preserves an unsealed memfd, adds F_SEAL_GROW *after* the preserve (which used to be silently lost across the handover), and verifies after the kexec reboot that both the data and the seal survived.
The test creates its own memfd instead of using the create_and_preserve_memfd() helper because the helper creates the memfd without MFD_ALLOW_SEALING, which makes it unsealable forever. It is registered in TEST_GEN_PROGS_EXTENDED and TEST_NAMES so it runs in the vmtest CI.
--- tools/testing/selftests/liveupdate/Makefile | 1 + .../liveupdate/luo_seal_after_preserve.c | 170 ++++++++++++++++++ .../selftests/liveupdate/run-vmtests.sh | 1 + 3 files changed, 172 insertions(+) create mode 100644 tools/testing/selftests/liveupdate/luo_seal_after_preserve.c
tools/testing/selftests/liveupdate/Makefile +1 -0
@@ -6,6 +6,7 @@ TEST_GEN_PROGS_EXTENDED += luo_kexec_simple TEST_GEN_PROGS_EXTENDED += luo_multi_session TEST_GEN_PROGS_EXTENDED += luo_stress_sessions TEST_GEN_PROGS_EXTENDED += luo_stress_files +TEST_GEN_PROGS_EXTENDED += luo_seal_after_preserve TEST_FILES += do_kexec.sh
tools/testing/selftests/liveupdate/luo_seal_after_preserve.c new file +170 -0
170 lines not on this page · raw message
tools/testing/selftests/liveupdate/run-vmtests.sh +1 -0
@@ -20,6 +20,7 @@ TEST_NAMES=( "luo_multi_session" "luo_stress_files" "luo_stress_sessions" + "luo_seal_after_preserve" ) function usage() {
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 2/2] selftests/liveupdate: add seal-after-preserve kexec test
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] selftests/liveupdate: missing __NR_fcntl64 fallback in LUO_FCNTL_NR --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] selftests/liveupdate: missing __NR_fcntl64 fallback in LUO_FCNTL_NR
--
commit b099e7f10e3cdd248ce57bd488ae708e0afbe3d7
Author: Long Wei <[email protected]>
selftests/liveupdate: add seal-after-preserve kexec test
This commit adds a kexec selftest that preserves an unsealed memfd, adds F_SEAL_GROW after preservation, and verifies that both the memfd contents and the seal survive across a kexec reboot.
Quoted 6 lines
tools/testing/selftests/liveupdate/luo_seal_after_preserve.c new file +0
-0@@ -0,0 +1,170 @@
[ ... ]
tools/testing/selftests/liveupdate/luo_seal_after_preserve.c line 46
Quoted 9 lines
tools/testing/selftests/liveupdate/luo_seal_after_preserve.c new file +9
-0+/* +* Prefer SYS_fcntl when the libc defines it (glibc, musl); fall back to +* __NR_fcntl which is the only name nolibc provides. +*/ +#ifdef SYS_fcntl +#define LUO_FCNTL_NR SYS_fcntl +#else +#define LUO_FCNTL_NR __NR_fcntl +#endif
[Severity: Medium]
Does LUO_FCNTL_NR fail to compile on 32-bit architectures that use the generic syscall table?
In include/uapi/asm-generic/unistd.h, __NR_fcntl is only defined when __BITS_PER_LONG == 64; 32-bit targets such as riscv32 only define __NR_fcntl64 (and SYS_fcntl64 in libc), as seen in tools/include/nolibc/sys.h:_sys_dup2(). Without falling back to SYS_fcntl64 or __NR_fcntl64, building kselftests on those architectures fails with an undeclared __NR_fcntl identifier.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/2] selftests/liveupdate: add seal-after-preserve kexec test
Thanks for the review. This is a valid point — 32-bit architectures using the generic syscall table (riscv32, csky, nios2, ...) only define __NR_fcntl64, not __NR_fcntl. I'll send a v2 of this selftest patch with the fcntl64 fallback added.
Quoted 43 lines · 在 2026/11/29 15:27, [email protected] 写道:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] selftests/liveupdate: missing__NR_fcntl64fallback inLUO_FCNTL_NR
--commit
b099e7f10e3cdd248ce57bd488ae708e0afbe3d7
Author: Long Wei <[email protected]>selftests/liveupdate: add seal-after-preserve kexec test
This commit adds a kexec selftest that preserves an unsealed memfd, adds
F_SEAL_GROWafter preservation, and verifies that both the memfd contents and the seal survive across a kexec reboot.Quoted 6 lines
tools/testing/selftests/liveupdate/luo_seal_after_preserve.c new file +0
-0@@ -0,0 +1,170 @@[ ... ]
tools/testing/selftests/liveupdate/luo_seal_after_preserve.c line 46
Quoted 9 lines
tools/testing/selftests/liveupdate/luo_seal_after_preserve.c new file +9
-0+/* +* Prefer SYS_fcntl when the libc defines it (glibc, musl); fall back to +* __NR_fcntl which is the only name nolibc provides. +*/ +#ifdef SYS_fcntl +#define LUO_FCNTL_NR SYS_fcntl +#else +#define LUO_FCNTL_NR __NR_fcntl +#endif [Severity: Medium]
DoesLUO_FCNTL_NRfail to compile on 32-bit architectures that use the generic syscall table?In
include/uapi/asm-generic/unistd.h,__NR_fcntlis only defined when__BITS_PER_LONG== 64; 32-bit targets such as riscv32 only define__NR_fcntl64(andSYS_fcntl64in libc), as seen in tools/include/nolibc/sys.h:_sys_dup2(). Without falling back toSYS_fcntl64or__NR_fcntl64, building kselftests on those architectures fails with an undeclared__NR_fcntlidentifier.
[email protected]
AI reviewSashiko has finished reviewing this 2-patch series:
Sashiko has finished reviewing this 2-patch series:
- Patch 1: no issues found.
- Patch 2 ("selftests/liveupdate: add seal-after-preserve kexec..."): 1 potential issue (1 Medium)
A detailed review has been sent as a separate reply to patch 2.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]