public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Nicolai Stange <nstange@suse.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Adrian Salido <salidoa@google.com>,
	Sasha Levin <sasha.levin@oracle.com>,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH 2/3] PCI: don't use snprintf() in driver_override_show()
Date: Mon, 11 Sep 2017 04:55:11 -0700	[thread overview]
Message-ID: <20170911115511.GB16198@kroah.com> (raw)
In-Reply-To: <20170911074542.16777-3-nstange@suse.de>

On Mon, Sep 11, 2017 at 09:45:41AM +0200, Nicolai Stange wrote:
> Quote from Documentation/filesystems/sysfs.txt:
> 
>   show() must not use snprintf() when formatting the value to be
>   returned to user space. If you can guarantee that an overflow
>   will never happen you can use sprintf() otherwise you must use
>   scnprintf().
> 
> Commit 4efe874aace5 ("PCI: Don't read past the end of sysfs
> "driver_override" buffer") introduced such a snprintf() usage from
> driver_override_show() while at the same time tweaking
> driver_override_store() such that the write buffer can't ever get
> overflowed.
> 
> Reasoning:
> Since aforementioned commit, driver_override_store() only accepts to be
> written buffers less than PAGE_SIZE - 1 in size.
> 
> The then kstrndup()'ed driver_override string will be at most PAGE_SIZE - 1
> in length, including the trailing '\0'.
> 
> After the addition of a '\n' in driver_override_show(), the result won't
> exceed PAGE_SIZE characters in length, again including the trailing '\0'.
> 
> Hence, snprintf(buf, PAGE_SIZE, ...) and sprintf(buf, ...) are equivalent
> at this point.
> 
> Replace the former by the latter in order to adhere to the rules in
> Documentation/filesystems/sysfs.txt.
> 
> This is a style fix only and there's no change in functionality.
> 
> Signed-off-by: Nicolai Stange <nstange@suse.de>
> ---
>  drivers/pci/pci-sysfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index 8e075ea2743e..43f7fbede448 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -722,7 +722,7 @@ static ssize_t driver_override_show(struct device *dev,
>  	ssize_t len;
>  
>  	device_lock(dev);
> -	len = snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override);
> +	len = sprintf(buf, "%s\n", pdev->driver_override);

While I'm all for changes like this, it's an uphill battle to change
them, usually it's best to just catch them before they go into the tree.

Anyway, nice summary, very good job with that.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

  reply	other threads:[~2017-09-11 11:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-11  7:45 [PATCH 0/3] make PCI's and platform's driver_override_store()/show() converge Nicolai Stange
2017-09-11  7:45 ` [PATCH 1/3] PCI: fix race condition with driver_override Nicolai Stange
2017-09-25 23:44   ` Bjorn Helgaas
2017-09-11  7:45 ` [PATCH 2/3] PCI: don't use snprintf() in driver_override_show() Nicolai Stange
2017-09-11 11:55   ` Greg Kroah-Hartman [this message]
2017-09-25 23:48     ` Bjorn Helgaas
2017-09-26  6:36       ` Nicolai Stange
2017-09-26 20:02         ` Bjorn Helgaas
2017-09-11  7:45 ` [PATCH 3/3] driver core: platform: Don't read past the end of "driver_override" buffer Nicolai Stange
2017-09-25 23:50   ` Bjorn Helgaas
2017-09-26  6:51     ` Greg Kroah-Hartman

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=20170911115511.GB16198@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=nstange@suse.de \
    --cc=salidoa@google.com \
    --cc=sasha.levin@oracle.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