mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tools/bootconfig: Fix integer overflow in size check
@ 2026-09-10  0:30 Masami Hiramatsu (Google)
  2026-09-10  0:34 ` Masami Hiramatsu
  0 siblings, 1 reply; 2+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-09-10  0:30 UTC (permalink / raw)
  To: Andrew Morton, Masami Hiramatsu
  Cc: linux-kernel, linux-trace-kernel, Sang-Heon Jeon

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Sashiko reported that on 32-bit systems, if the size in the bootconfig
footer is corrupted such that adding BOOTCONFIG_FOOTER_SIZE wraps
around (for instance, if size is 0xFFFFFFFF), the size check in
load_xbc_from_initrd() can be bypassed:

    if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
        pr_err("bootconfig size is too big\n");
        return -E2BIG;
    }

This would lead to load_xbc_fd() being called with a negative size,
resulting in an undersized allocation, heap overflow on read, and
out-of-bounds write on the terminating null byte.

Avoid the integer overflow by checking whether size is greater than
stat.st_size - BOOTCONFIG_FOOTER_SIZE. Since stat.st_size is already
verified to be at least BOOTCONFIG_FOOTER_SIZE earlier in the function,
this subtraction will never underflow.

Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/20260909161113.16C691F00A3A@smtp.kernel.org/
Assisted-by: Antigravity:gemini-3.8-flash
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 tools/bootconfig/main.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 7dc9fff9b637..b380ad6777fa 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -218,7 +218,7 @@ static int load_xbc_from_initrd(int fd, char **buf)
 	csum = le32toh(csum);
 
 	/* Wrong size error  */
-	if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
+	if (size > stat.st_size - BOOTCONFIG_FOOTER_SIZE) {
 		pr_err("bootconfig size is too big\n");
 		return -E2BIG;
 	}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] tools/bootconfig: Fix integer overflow in size check
  2026-09-10  0:30 [PATCH] tools/bootconfig: Fix integer overflow in size check Masami Hiramatsu (Google)
@ 2026-09-10  0:34 ` Masami Hiramatsu
  0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2026-09-10  0:34 UTC (permalink / raw)
  To: Masami Hiramatsu (Google)
  Cc: Andrew Morton, linux-kernel, linux-trace-kernel, Sang-Heon Jeon, stable

On Thu, 10 Sep 2026 09:30:46 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Sashiko reported that on 32-bit systems, if the size in the bootconfig
> footer is corrupted such that adding BOOTCONFIG_FOOTER_SIZE wraps
> around (for instance, if size is 0xFFFFFFFF), the size check in
> load_xbc_from_initrd() can be bypassed:
> 
>     if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
>         pr_err("bootconfig size is too big\n");
>         return -E2BIG;
>     }
> 
> This would lead to load_xbc_fd() being called with a negative size,
> resulting in an undersized allocation, heap overflow on read, and
> out-of-bounds write on the terminating null byte.
> 
> Avoid the integer overflow by checking whether size is greater than
> stat.st_size - BOOTCONFIG_FOOTER_SIZE. Since stat.st_size is already
> verified to be at least BOOTCONFIG_FOOTER_SIZE earlier in the function,
> this subtraction will never underflow.
> 
> Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://lore.kernel.org/all/20260909161113.16C691F00A3A@smtp.kernel.org/
> Assisted-by: Antigravity:gemini-3.8-flash

OOps, I forgot to add:

Cc: stable@vger.kernel.org

Thanks,

> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
>  tools/bootconfig/main.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
> index 7dc9fff9b637..b380ad6777fa 100644
> --- a/tools/bootconfig/main.c
> +++ b/tools/bootconfig/main.c
> @@ -218,7 +218,7 @@ static int load_xbc_from_initrd(int fd, char **buf)
>  	csum = le32toh(csum);
>  
>  	/* Wrong size error  */
> -	if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
> +	if (size > stat.st_size - BOOTCONFIG_FOOTER_SIZE) {
>  		pr_err("bootconfig size is too big\n");
>  		return -E2BIG;
>  	}
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-10  0:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-10  0:30 [PATCH] tools/bootconfig: Fix integer overflow in size check Masami Hiramatsu (Google)
2026-09-10  0:34 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®