Re: [PATCH v4] lib/bootconfig: guard xbc_node_compose_key_after() buffer size

From
Masami Hiramatsu (Google) <mhiramat@kernel.org>
Date
2026-03-18 00:02:47
Also in
lkml
Reply to
Steven Rostedt, 2026-03-17
On Tue, 17 Mar 2026 19:16:26 -0400
Steven Rostedt [off-list ref] wrote:
On Wed, 18 Mar 2026 08:03:51 +0900
Masami Hiramatsu (Google) [off-list ref] wrote:
quoted
On Tue, 17 Mar 2026 20:44:03 +0000
Josh Law [off-list ref] wrote:
quoted
xbc_node_compose_key_after() passes a size_t buffer length to
snprintf(), but snprintf() returns int. Guard against size values above
INT_MAX before the loop so the existing truncation check can continue to
compare ret against (int)size safely.

Add a small WARN_ON_ONCE shim for the tools/bootconfig userspace build
so the same source continues to build there.  
NACK.

Don't do such over engineering effort.
Hi Masami,

This was somewhat my idea. Why do you think it's over engineering?

This is your code, so you have final say. I'm not going to push it. I'm
just curious to your thoughts.
I sent a mail why I thought this is over engineering. I think this
comes from vsnprintf() interface design. If all user of that needs
to do this, that is not fair. It should be checked in vsnprintf()
and caller should just check the returned error.
It is interesting that snprintf() takes a size_t size, and the iterator
inside is also size_t, but then it returns the value as an int.
Yes, that is checked in vsnprintf(), not its caller.
I think linux kernel should ensure the the return value is smaller
than INT_MAX, and return -EOVERFLOW if not.

Thank you,
That itself just looks wrong (and has nothing to do with your code).

-- Steve

-- 
Masami Hiramatsu (Google) [off-list ref]
Thread (7 messages) 7 messages, 3 authors, last reply 2026-03-18
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help