linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: James Bottomley <jejb@linux.ibm.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
	Finn Thain <fthain@linux-m68k.org>,
	Michael Schmitz <schmitzmic@gmail.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	drew@colorado.edu, Tnx to <Thomas_Roesch@m2.maus.de>,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH 03/10] scsi: NCR5380: Replace snprintf() with the safer scnprintf() variant
Date: Tue, 20 Feb 2024 08:28:16 +0000	[thread overview]
Message-ID: <20240220082816.GI10170@google.com> (raw)
In-Reply-To: <f5bef33da6c50e5fd067577f16f460025fe9a601.camel@linux.ibm.com>

On Mon, 19 Feb 2024, James Bottomley wrote:

> On Mon, 2024-02-19 at 15:23 +0000, Lee Jones wrote:
> > On Sat, 10 Feb 2024, James Bottomley wrote:
> > 
> > > On Thu, 2024-02-08 at 10:29 +0000, Lee Jones wrote:
> > > > On Thu, 08 Feb 2024, Geert Uytterhoeven wrote:
> > > > 
> > > > > Hi Lee,
> > > > > 
> > > > > Thanks for your patch!
> > > > > 
> > > > > On Thu, Feb 8, 2024 at 9:48 AM Lee Jones <lee@kernel.org>
> > > > > wrote:
> > > > > > There is a general misunderstanding amongst engineers that
> > > > > > {v}snprintf() returns the length of the data *actually*
> > > > > > encoded into the destination array.  However, as per the C99
> > > > > > standard {v}snprintf() really returns the length of the data
> > > > > > that *would have been* written if there were enough space for
> > > > > > it.  This misunderstanding has led to buffer-overruns in the
> > > > > > past.  It's generally considered safer to use the
> > > > > > {v}scnprintf() variants in their place (or even sprintf() in
> > > > > > simple cases).  So let's do that.
> > > > > 
> > > > > Confused... The return value is not used at all?
> > > > 
> > > > Future proofing.  The idea of the effort is to rid the use
> > > > entirely.
> > > > 
> > > >  - Usage is inside a sysfs handler passing PAGE_SIZE as the size
> > > >    - s/snprintf/sysfs_emit/
> > > >  - Usage is inside a sysfs handler passing a bespoke value as the
> > > > size
> > > >    - s/snprintf/scnprintf/
> > > >  - Return value used, but does *not* care about overflow
> > > >    - s/snprintf/scnprintf/
> > > >  - Return value used, caller *does* care about overflow
> > > >    - s/snprintf/seq_buf/
> > > >  - Return value not used
> > > >    - s/snprintf/scnprintf/
> > > > 
> > > > This is the final case.
> > > 
> > > To re-ask Geert's question: the last case can't ever lead to a bug
> > > orproblem, what value does churning the kernel to change it
> > > provide? As Finn said, if we want to deprecate it as a future
> > > pattern, put it in checkpatch.
> > 
> > Adding this to checkpatch is a good idea.
> > 
> > What if we also take Kees's suggestion and hit all of these found in
> > SCSI in one patch to keep the churn down to a minimum?
> 
> That doesn't fix the churn problem because you're still changing the
> source.  For ancient drivers, we keep the changes to a minimum to avoid
> introducing inadvertent bugs which aren't discovered until months
> later.  If there's no actual bug in the driver, there's no reason to
> change the code.

Okay, no problem.  Would you like me to drop these from the set and
resubmit or are you happy to cherry-pick the remainder?

-- 
Lee Jones [李琼斯]

  reply	other threads:[~2024-02-20  8:28 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08  8:44 [PATCH 00/10] scsi: Replace {v}snprintf() variants with safer alternatives Lee Jones
2024-02-08  8:44 ` [PATCH 03/10] scsi: NCR5380: Replace snprintf() with the safer scnprintf() variant Lee Jones
2024-02-08 10:22   ` Geert Uytterhoeven
2024-02-08 10:29     ` Lee Jones
2024-02-10  9:32       ` Finn Thain
2024-02-10 12:56       ` James Bottomley
2024-02-19 15:23         ` Lee Jones
2024-02-19 16:25           ` James Bottomley
2024-02-20  8:28             ` Lee Jones [this message]
2024-02-19 21:30           ` Kees Cook
2024-02-20  8:24             ` Lee Jones
2024-02-10  7:14   ` Kees Cook
2024-02-08  8:44 ` [PATCH 04/10] scsi: aacraid: linit: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() Lee Jones
2024-02-10  7:00   ` Kees Cook
2024-02-08  8:44 ` [PATCH 05/10] scsi: aacraid: linit: Replace snprintf() with the safer scnprintf() variant Lee Jones
2024-02-10  7:03   ` Kees Cook
2024-02-08  8:44 ` [PATCH 06/10] scsi: aha1542: " Lee Jones
2024-02-10  7:06   ` Kees Cook
2024-02-08  8:44 ` [PATCH 07/10] scsi: aic7xxx: aicasm: Trivial: Remove trailing whitespace Lee Jones
2024-02-10  6:58   ` Kees Cook
2024-02-08  8:44 ` [PATCH 08/10] scsi: aic7xxx: aicasm: Replace snprintf() with the safer scnprintf() variant Lee Jones
2024-02-10  7:06   ` Kees Cook
2024-02-08  8:44 ` [PATCH 09/10] scsi: aic94xx: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() Lee Jones
2024-02-10  7:13   ` Kees Cook
2024-02-08  8:44 ` [PATCH 10/10] scsi: arcmsr: " Lee Jones
2024-02-10  7:13   ` Kees Cook
2024-02-08 17:40 ` [PATCH 00/10] scsi: Replace {v}snprintf() variants with safer alternatives Bart Van Assche
2024-02-08 17:49   ` Lee Jones

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=20240220082816.GI10170@google.com \
    --to=lee@kernel.org \
    --cc=Thomas_Roesch@m2.maus.de \
    --cc=drew@colorado.edu \
    --cc=fthain@linux-m68k.org \
    --cc=geert@linux-m68k.org \
    --cc=jejb@linux.ibm.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=schmitzmic@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;
as well as URLs for NNTP newsgroup(s).