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

From: Kees Cook
Date: Tue Aug 29 2023 - 14:49:45 EST


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@xxxxxxxxxx> wrote:
> >
> > On Mon, Aug 28, 2023 at 3:25 PM Nick Desaulniers
> > <ndesaulniers@xxxxxxxxxx> 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