From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
To: Ard Biesheuvel <ardb@kernel.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Josh Law <objecting@objecting.org>,
Andrew Morton <akpm@linux-foundation.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/1] lib/vsprintf: Limit the returning size to INT_MAX
Date: Wed, 18 Mar 2026 10:19:56 +0900 [thread overview]
Message-ID: <177379679625.535490.15253547806594621828.stgit@devnote2> (raw)
In-Reply-To: <177379678638.535490.18200744206158553364.stgit@devnote2>
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
There seems a design flaw of vsnprintf() whose return value can
overflow the INT_MAX even on 32bit arch, because the buffer size is
passed by 'size_t' but it returns the printed or required size in 'int'.
The size_t is unsigned long, thus the caller can pass bigger than INT_MAX
as the size of buffer (that is OK). But even the vsnprintf calculates
the required/printed length correctly, if it overflows the INT_MAX,
it can not return the size correctly by int.
This should never happen but it should be checked and limited.
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
drivers/firmware/efi/libstub/vsprintf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/firmware/efi/libstub/vsprintf.c b/drivers/firmware/efi/libstub/vsprintf.c
index 71c71c222346..1713cacecc25 100644
--- a/drivers/firmware/efi/libstub/vsprintf.c
+++ b/drivers/firmware/efi/libstub/vsprintf.c
@@ -549,7 +549,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list ap)
if (size)
buf[min(pos, size-1)] = '\0';
- return pos;
+ return (pos > INT_MAX) ? INT_MAX : pos;
}
int snprintf(char *buf, size_t size, const char *fmt, ...)
next prev parent reply other threads:[~2026-03-18 1:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 1:19 [RFC PATCH 0/1] lib/vsnprintf: Limit the returning size to INT_MAX Masami Hiramatsu (Google)
2026-03-18 1:19 ` Masami Hiramatsu (Google) [this message]
2026-03-18 13:47 ` [RFC PATCH 1/1] lib/vsprintf: " Steven Rostedt
2026-03-18 15:12 ` David Laight
2026-03-19 0:07 ` Masami Hiramatsu
2026-03-18 23:50 ` Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=177379679625.535490.15253547806594621828.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=objecting@objecting.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox