[PATCH v5 06/18] liveupdate: Don't WARN if tracking a retrieved file fails
From: David Matlack
Date: Mon Nov 23 2026 - 18:39:55 EST
Handle a failure to add a retrieved file to luo_preserved_files instead
of triggering a WARN_ON(). Make the failure permanent, and keep the file
until the file set is finished, like any other retrieved file. Only warn
if the file is already tracked (-EBUSY), which would be a kernel bug,
since a retrieved file is always a new file.
xa_insert() can fail with -ENOMEM, and userspace can trigger that with
LIVEUPDATE_SESSION_RETRIEVE_FD, so warning about it lets userspace crash
systems with panic_on_warn.
The handler has already consumed the preserved state when this happens,
so the retrieve can't be retried. Keeping the file ensures that its
resources are not released before the file set is finished. When
finishing the file set, only erase successfully retrieved files from
luo_preserved_files, so that the id of a file that was never added
doesn't erase the entry of another file.
Fixes: 00d0b372374f ("liveupdate: prevent double management of files")
Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
Acked-by: Pasha Tatashin <pasha.tatashin@xxxxxxxxxx>
Reviewed-by: Pratyush Yadav (Google) <pratyush@xxxxxxxxxx>
---
kernel/liveupdate/luo_file.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
index 9d98438b0166..0755a6478aec 100644
--- a/kernel/liveupdate/luo_file.c
+++ b/kernel/liveupdate/luo_file.c
@@ -675,14 +675,28 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
return err;
}
+ err = xa_insert(&luo_preserved_files,
+ luo_get_id(luo_file->fh, args.file), args.file,
+ GFP_KERNEL);
+ if (err) {
+ /* A retrieved file is new, so it can't be tracked already. */
+ WARN_ON_ONCE(err == -EBUSY);
+
+ /*
+ * The handler has consumed the preserved state, so the retrieve
+ * can't be retried. Keep the file until the file set is
+ * finished, so that its resources are released at the same
+ * time as those of other retrieved files.
+ */
+ luo_file->file = args.file;
+ luo_file->retrieve_status = err;
+ return err;
+ }
+
luo_file->file = args.file;
/* Get reference so we can keep this file in LUO until finish */
get_file(luo_file->file);
- WARN_ON(xa_insert(&luo_preserved_files,
- luo_get_id(luo_file->fh, luo_file->file),
- luo_file->file, GFP_KERNEL));
-
*filep = luo_file->file;
luo_file->retrieve_status = 1;
@@ -780,11 +794,12 @@ int luo_file_finish(struct luo_file_set *file_set)
luo_file_finish_one(file_set, luo_file);
- if (luo_file->file) {
+ /* Only a successfully retrieved file was tracked. */
+ if (luo_file->retrieve_status > 0)
xa_erase(&luo_preserved_files,
luo_get_id(luo_file->fh, luo_file->file));
+ if (luo_file->file)
fput(luo_file->file);
- }
module_put(luo_file->fh->ops->owner);
list_del(&luo_file->list);
file_set->count--;
--
2.56.1.809.ga0b61035b5-goog