tools/bootconfig: Report initrd append failures 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. Link: https://lore.kernel.org/all/20261120061917.98169-1-zhujun2@cmss.chinamobile.com/ Fixes: a995e6bc0524 ("tools/bootconfig: Fix to check the write failure correctly") Cc: stable@vger.kernel.org Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index 31af794..c85e58f 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c
@@ -509,14 +509,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);