Skip to content

Commit a10f289

Browse files
committed
PCI: Don't read past the end of sysfs "driver_override" buffer
[ Upstream commit 4efe874 ] When printing the driver_override parameter when it is 4095 and 4094 bytes long, the printing code would access invalid memory because we need count+1 bytes for printing. Fixes: 782a985 ("PCI: Introduce new device binding path using pci_dev.driver_override") Signed-off-by: Sasha Levin <sasha.levin@oracle.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Alex Williamson <alex.williamson@redhat.com> CC: stable@vger.kernel.org # v3.16+ CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> CC: Alexander Graf <agraf@suse.de> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
1 parent 8941013 commit a10f289

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎drivers/pci/pci-sysfs.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ static ssize_t driver_override_store(struct device *dev,
515515
struct pci_dev *pdev = to_pci_dev(dev);
516516
char *driver_override, *old = pdev->driver_override, *cp;
517517

518-
if (count > PATH_MAX)
518+
/* We need to keep extra room for a newline */
519+
if (count >= (PAGE_SIZE - 1))
519520
return -EINVAL;
520521

521522
driver_override = kstrndup(buf, count, GFP_KERNEL);
@@ -543,7 +544,7 @@ static ssize_t driver_override_show(struct device *dev,
543544
{
544545
struct pci_dev *pdev = to_pci_dev(dev);
545546

546-
return sprintf(buf, "%s\n", pdev->driver_override);
547+
return snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override);
547548
}
548549
static DEVICE_ATTR_RW(driver_override);
549550

0 commit comments

Comments
 (0)