From: Kees Cook <kees@kernel.org>
To: David Laight <david.laight.linux@gmail.com>,
Mariia Nikitash <nikitash.mariiaw@gmail.com>
Cc: Alejandro Colomar <alx+linux-hardening@kernel.org>,
mchehab@kernel.org, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
justinstitt@google.com, morbo@google.com
Subject: Re: [PATCH] media: siano: Replace strlcat() with snprintf() in sms_ir_init()
Date: Fri, 06 Nov 2026 08:06:02 -0800 [thread overview]
Message-ID: <1EAA42AE-92F8-4CB7-B490-CDB6DA9FFCE9@kernel.org> (raw)
In-Reply-To: <20261106102723.1cc4d350@pumpkin>
On November 6, 2026 2:27:23 AM PST, David Laight <david.laight.linux@gmail.com> wrote:
>On Thu, 5 Nov 2026 17:44:00 -0800
>Mariia Nikitash <nikitash.mariiaw@gmail.com> wrote:
>
>> On Thu, Nov 5, 2026 at 3:32 AM David Laight <david.laight.linux@gmail.com>
>> wrote:
>> >
>> > On Wed, 4 Nov 2026 12:25:17 +0100
>> > Alejandro Colomar <alx+linux-hardening@kernel.org> wrote:
>> >
>> > > Hi Mariia,
>> > >
>> > > > Date: 2026-11-04 01:02:39-0800
>> > > > From: Mariia Nikitash <nikitash.mariiaw@gmail.com>
>> > > >
>> > > > In preparation for removing the deprecated strlcat() API[1],
>> > > > replace the strscpy() and strlcat() calls with a single snprintf()
>> > > > call to construct the IR device path.
>> > > >
>> > > > Both the source and destination buffers have the same capacity,
>> > >
>> > > The line above seems irrelevant, and potentially confusing.
>> > > The size of the input is not important, because since we're appending
>> > > stuff after it, truncation may actually happen.
>> >
>> > And gcc's stupid format overflow check is going to complain.
>>
>> Thanks for pointing this out! I initially tested with Clang, but reproduced
>> the warning with GCC. I've switched to seq_buf for v3.
>
>That is entirely OTT.
>Currently scnprintf() doesn't complain.
What does GCC say about it? Is it mad about src >= dest length but the format adds chars?
I agree that seq_buf isn't needed here; that's really only for complicated cases where the simpler solutions don't fit. (In this case, snprintf-like is best.)
Both seq_buf and scnprintf avoid the warning because GCC just happens to not recognize the pattern when using those helpers, so this is just silencing the warning, much like strlcat() did too.
Truncation was the norm already, so scnprintf is probably the best fit, but I think it may be worth looking at the surrounding code and conventions to decide if truncation should be communicated upward to the caller (i.e. fail), or if the structures involved should be adjusted to avoid truncation chance, etc etc. If possible we should avoid the weakness, but if not, just use the minimal solution here, which is scnprintf, though that kicks the warning down the road...
-Kees
--
Kees Cook
next prev parent reply other threads:[~2026-11-06 16:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 9:02 Mariia Nikitash
2026-11-04 11:25 ` Alejandro Colomar
2026-11-04 19:01 ` Mariia Nikitash
2026-11-05 11:32 ` David Laight
2026-11-06 4:08 ` Mariia Nikitash
[not found] ` <CAPDEY+X7q2yeWaa7J=Nre+pQqUa2C760Hh9NovdGNSQ=VsEr8w@mail.gmail.com>
2026-11-06 10:27 ` David Laight
2026-11-06 16:06 ` Kees Cook [this message]
2026-11-04 16:33 ` Shihuang Liu
2026-11-04 18:50 ` [PATCH v2] " Mariia Nikitash
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=1EAA42AE-92F8-4CB7-B490-CDB6DA9FFCE9@kernel.org \
--to=kees@kernel.org \
--cc=alx+linux-hardening@kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=justinstitt@google.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=morbo@google.com \
--cc=nikitash.mariiaw@gmail.com \
/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
all inboxes | Powered by JetHome®