[PATCH] tools/bootconfig: Reject short reads of configuration data

From: Zhu Jun

Date: Fri Nov 20 2026 - 01:19:24 EST


load_xbc_fd() places the terminator at the requested size even when
read() returns less. Its initrd caller then computes a checksum over
bytes that were never read, while the plain file callers can parse a
partial configuration. Reject a short read and release the allocated
buffer on both read failure paths.

Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
tools/bootconfig/main.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index d3f840c5adce..a3935e1a8c6b 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -190,8 +190,12 @@ static int load_xbc_fd(int fd, char **buf, int size)
return -ENOMEM;

ret = read(fd, *buf, size);
- if (ret < 0)
- return -errno;
+ if (ret != size) {
+ ret = ret < 0 ? -errno : -EIO;
+ free(*buf);
+ *buf = NULL;
+ return ret;
+ }
(*buf)[size] = '\0';

return ret;