linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: "Alexey V. Vissarionov" <gremlin@altlinux.org>
Cc: "Krzysztof Wilczyński" <kw@linux.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Jesse Barnes" <jbarnes@virtuousgeek.org>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Yu Zhao" <yu.zhao@intel.com>,
	linux-pci@vger.kernel.org, lvc-project@linuxtesting.org
Subject: Re: [PATCH] PCI/IOV: "virtfn4294967295\0" requires 17 bytes
Date: Thu, 12 Jan 2023 17:00:18 -0600	[thread overview]
Message-ID: <20230112230018.GA1800747@bhelgaas> (raw)
In-Reply-To: <20221218122139.GA1182@altlinux.org>

On Sun, Dec 18, 2022 at 03:21:39PM +0300, Alexey V. Vissarionov wrote:
> On 2022-12-18 19:57:02 +0900, Krzysztof Wilczyński wrote:
> 
>  > Thank you for sending the patch over! However, if possible,
>  > can you send it as plain text without any multi-part MIME
>  > involved?
> 
> ACK.
> 
>  > If possible, it would be nice to mention that this needed
>  > to make sure that there is enough space to correctly
>  > NULL-terminate the ID string.
> 
> ACK.
> 
> So, here goes the corrected text:
> 
> Although unlikely, the 'id' value may be as big as 4294967295
> (uint32_max) and "virtfn4294967295\0" would require 17 bytes
> instead of 16 to make sure that buffer has enough space to
> properly NULL-terminate the ID string.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: dd7cc44d0 ("PCI: add SR-IOV API for Physical Function driver")
> Signed-off-by: Alexey V. Vissarionov <gremlin@altlinux.org>

I collected this up and applied to pci/iov for v6.3 as below.  I agree
this is probably only a theoretical issue, but it's easier to spend a
byte of stack space than to prove that we don't need to.

Bjorn


commit 58d4c63d0a27 ("PCI/IOV: Enlarge virtfn sysfs name buffer")
parent 1b929c02afd3
Author: Alexey V. Vissarionov <gremlin@altlinux.org>
Date:   Sun Dec 18 06:33:47 2022 +0300

    PCI/IOV: Enlarge virtfn sysfs name buffer
    
    The sysfs link name "virtfn%u" constructed by pci_iov_sysfs_link() requires
    17 bytes to contain the longest possible string.  Increase VIRTFN_ID_LEN to
    accommodate that.
    
    Found by Linux Verification Center (linuxtesting.org) with SVACE.
    
    [bhelgaas: commit log, comment at #define]
    Fixes: dd7cc44d0 ("PCI: add SR-IOV API for Physical Function driver")
    Link: https://lore.kernel.org/r/20221218033347.23743-1-gremlin@altlinux.org
    Signed-off-by: Alexey V. Vissarionov <gremlin@altlinux.org>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 952217572113..b2e8322755c1 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -14,7 +14,7 @@
 #include <linux/delay.h>
 #include "pci.h"
 
-#define VIRTFN_ID_LEN	16
+#define VIRTFN_ID_LEN	17	/* "virtfn%u\0" for 2^32 - 1 */
 
 int pci_iov_virtfn_bus(struct pci_dev *dev, int vf_id)
 {

      parent reply	other threads:[~2023-01-12 23:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-18  3:33 [PATCH] PCI/IOV: "virtfn4294967295\0" requires 17 bytes Alexey V. Vissarionov
2022-12-18 10:57 ` Krzysztof Wilczyński
2022-12-18 12:21   ` Alexey V. Vissarionov
2022-12-18 22:19     ` Matthew Wilcox
2022-12-18 23:24       ` Alexey V. Vissarionov
2022-12-19 10:16       ` Niklas Schnelle
2022-12-29 18:12       ` Bjorn Helgaas
2022-12-29 21:09         ` Matthew Wilcox
2023-01-12 23:00     ` Bjorn Helgaas [this message]

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=20230112230018.GA1800747@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=alex.williamson@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=gremlin@altlinux.org \
    --cc=jbarnes@virtuousgeek.org \
    --cc=kw@linux.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=willy@infradead.org \
    --cc=yu.zhao@intel.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).