Re: [PATCH 0/2] scsi: fix 2 cases of -Wfortify-source

Kees Cook
2023-08-29T18:49:45Z

On Tue, Aug 29, 2023 at 09:33:55AM -0700, Nick Desaulniers wrote:
> On Mon, Aug 28, 2023 at 4:41 PM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> >
> > On Mon, Aug 28, 2023 at 3:25 PM Nick Desaulniers
> > <ndesaulniers@google.com> wrote:
> > >
> > > clang-18 has improved its support for detecting operations that will
> > > truncate values at runtime via -wfortify-source resulting in two new
> >
> > ^ -Wfortify-source
> >
> > > warnings (or errors with CONFIG_WERROR=y):
> > >
> > > drivers/scsi/myrb.c:1906:10: warning: 'snprintf' will always be
> > > truncated; specified size is 32, but format string expands to at least
> > > 34 [-Wfortify-source]
> > >
> > > drivers/scsi/myrs.c:1089:10: warning: 'snprintf' will always be
> > > truncated; specified size is 32, but format string expands to at least
> > > 34 [-Wfortify-source]

These should just use sysfs_emit() instead. Then all the bounds checking
against the PAGE_SIZE buffer gets done correctly, etc.

--
Kees Cook