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

From: Masami Hiramatsu (Google)

Date: Tue Nov 24 2026 - 16:55:29 EST


On Fri, 20 Nov 2026 14:19:12 +0800, Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx> wrote:
> 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>

OK, this looks good to me.

Thanks!

> ---
> 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;
>

--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>