public inbox for linux-efi@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] lib/vsnprintf: Limit the returning size to INT_MAX
@ 2026-03-18  1:19 Masami Hiramatsu (Google)
  2026-03-18  1:19 ` [RFC PATCH 1/1] lib/vsprintf: " Masami Hiramatsu (Google)
  0 siblings, 1 reply; 6+ messages in thread
From: Masami Hiramatsu (Google) @ 2026-03-18  1:19 UTC (permalink / raw)
  To: Ard Biesheuvel, Ilias Apalodimas
  Cc: Steven Rostedt, Josh Law, Andrew Morton, Masami Hiramatsu,
	linux-efi, linux-kernel

Hi,

Recently we discussed snprintf() usage in bootconfig and found snprintf()
design has a problem[1]. It returns the required or printed size in 'int'
but the maxlen is passed by 'size_t'. If the maxlen is bigger than INT_MAX
(this should never happen), it can not return the size correctly, that
becomes negative value or very shorter than it has actually done.

I think it should not be handled by caller side, instead, vsnprintf()
should handle it. This is an extremely unlikely input, and if we need to
address it, I think we should keep the fix to a minimum (in performance
point of view).

Thus I just limited the returning size to INT_MAX. If caller sees the
*printf() returns INT_MAX, it can handle it as an error or use strlen()
to get real printed size (but I don't recommend it.)

IMHO, this input is basically impossible unless done intentionally,
so I think it's a form of over-engineering. Therefore, this is an
RFC patch.

A question is that we should use WARN_ON() when the return size is over
INT_MAX. Currently this just returns INT_MAX (no warning) because this is
a library function, which can be called from anywhere.

[1] https://lore.kernel.org/all/20260317121507.30735331@gandalf.local.home/

Thank you,

---

Masami Hiramatsu (Google) (1):
      lib/vsprintf: Limit the returning size to INT_MAX


 drivers/firmware/efi/libstub/vsprintf.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

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

end of thread, other threads:[~2026-03-19  0:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [RFC PATCH 1/1] lib/vsprintf: " Masami Hiramatsu (Google)
2026-03-18 13:47   ` Steven Rostedt
2026-03-18 15:12     ` David Laight
2026-03-19  0:07       ` Masami Hiramatsu
2026-03-18 23:50   ` Masami Hiramatsu

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