linux/kernel/liveupdate
Breno Leitao 9ec9532989 kho: fix error handling in kho_add_subtree()
Fix two error handling issues in kho_add_subtree(), where it doesn't
handle the error path correctly.

1. If fdt_setprop() fails after the subnode has been created, the
   subnode is not removed. This leaves an incomplete node in the FDT
   (missing "preserved-data" or "blob-size" properties).

2. The fdt_setprop() return value (an FDT error code) is stored
   directly in err and returned to the caller, which expects -errno.

Fix both by storing fdt_setprop() results in fdt_err, jumping to a new
out_del_node label that removes the subnode on failure, and only setting
err = 0 on the success path, otherwise returning -ENOMEM (instead of
FDT_ERR_ errors that would come from fdt_setprop).

No user-visible changes.  This patch fixes error handling in the KHO
(Kexec HandOver) subsystem, which is used to preserve data across kexec
reboots.  The fix only affects a rare failure path during kexec
preparation — specifically when the kernel runs out of space in the
Flattened Device Tree buffer while registering preserved memory regions.

In the unlikely event that this error path was triggered, the old code
would leave a malformed node in the device tree and return an incorrect
error code to the calling subsystem, which could lead to confusing log
messages or incorrect recovery decisions.  With this fix, the incomplete
node is properly cleaned up and the appropriate errno value is propagated,
this error code is not returned to the user.

Link: https://lore.kernel.org/20260410-kho_fix_send-v2-1-1b4debf7ee08@debian.org
Fixes: 3dc92c3114 ("kexec: add Kexec HandOver (KHO) generation helpers")
Signed-off-by: Breno Leitao <leitao@debian.org>
Suggested-by: Pratyush Yadav <pratyush@kernel.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Cc: Alexander Graf <graf@amazon.com>
Cc: Breno Leitao <leitao@debian.org>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2026-04-27 05:54:23 -07:00
..
Kconfig liveupdate: separate memfd support into LIVEUPDATE_MEMFD 2026-01-26 19:07:10 -08:00
Makefile liveupdate: luo_flb: introduce File-Lifecycle-Bound global state 2026-02-08 00:13:33 -08:00
kexec_handover.c kho: fix error handling in kho_add_subtree() 2026-04-27 05:54:23 -07:00
kexec_handover_debug.c
kexec_handover_debugfs.c kho: fix kho_in_debugfs_init() to handle non-FDT blobs 2026-04-18 00:10:48 -07:00
kexec_handover_internal.h kho: rename fdt parameter to blob in kho_add/remove_subtree() 2026-04-18 00:10:48 -07:00
luo_core.c liveupdate: protect file handler list with rwsem 2026-04-18 00:10:49 -07:00
luo_file.c liveupdate: defer file handler module refcounting to active sessions 2026-04-18 00:10:50 -07:00
luo_flb.c liveupdate: make unregister functions return void 2026-04-18 00:10:50 -07:00
luo_internal.h liveupdate: remove liveupdate_test_unregister() 2026-04-18 00:10:50 -07:00
luo_session.c liveupdate: fix return value on session allocation failure 2026-04-27 05:54:23 -07:00