[PATCH] tools/bootconfig: Report initrd append failures
From: Zhu Jun
Date: Fri Nov 20 2026 - 01:19:29 EST
The signed return value of write() is compared against a size_t.
A negative return becomes an unsigned value and bypasses the error
path, so applying a bootconfig can claim success without appending
it. Check for a negative return before comparing the byte count.
Fixes: e1cef2d4c379 ("tools/bootconfig: Align the bootconfig applied initrd image size to 4")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
tools/bootconfig/main.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index a3935e1a8c6b..014fd04d2a61 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -503,14 +503,16 @@ static int apply_xbc(const char *path, const char *xbc_path)
total_size = size + BOOTCONFIG_FOOTER_SIZE;
ret = write(fd, data, total_size);
- if (ret < total_size) {
- if (ret < 0)
- ret = -errno;
+ if (ret < 0) {
+ ret = -errno;
pr_err("Failed to apply a boot config: %d\n", ret);
- if (ret >= 0)
- goto out_rollback;
- } else
- ret = 0;
+ goto out;
+ }
+ if ((size_t)ret != total_size) {
+ pr_err("Failed to apply a boot config: %d\n", ret);
+ goto out_rollback;
+ }
+ ret = 0;
out:
close(fd);