Skip to contentSkip to conversation

PCI: mt7621: Fix possible string truncation in snprintf

PATCH Applied Sergio Paracuellos 3 participants 6 messages Jan 11, 2024 – May 17, 2024

Subsystems (4)
lore
Share & tools
lore

Sergio Paracuellos

author maintainer
#0 lore raw

PATCH 1/1 PCI: mt7621: Fix possible string truncation in snprintf

The following warning appears when driver is compiled with W=1.

CC drivers/pci/controller/pcie-mt7621.o
drivers/pci/controller/pcie-mt7621.c: In function ‘mt7621_pcie_probe’:
drivers/pci/controller/pcie-mt7621.c:228:49: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
228 | snprintf(name, sizeof(name), "pcie-phy%d", slot);
| ^
drivers/pci/controller/pcie-mt7621.c:228:9: note: ‘snprintf’ output between 10 and 11 bytes into a destination of size 10

228 |         snprintf(name, sizeof(name), "pcie-phy%d", slot);
    |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Clean this up increasing destination buffer one byte.

---
 drivers/pci/controller/pcie-mt7621.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pcie-mt7621.c +1 -1
index 79e225edb42a..d97b956e6e57 100644
@@ -202,7 +202,7 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie,
 	struct mt7621_pcie_port *port;
 	struct device *dev = pcie->dev;
 	struct platform_device *pdev = to_platform_device(dev);
-	char name[10];
+	char name[11];
 	int err;
 
 	port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

Hi,

Quoted 37 lines · Sergio Paracuellos

The following warning appears when driver is compiled with W=1.

CC drivers/pci/controller/pcie-mt7621.o
drivers/pci/controller/pcie-mt7621.c: In function ‘mt7621_pcie_probe’:
drivers/pci/controller/pcie-mt7621.c:228:49: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
228 | snprintf(name, sizeof(name), "pcie-phy%d", slot);
| ^
drivers/pci/controller/pcie-mt7621.c:228:9: note: ‘snprintf’ output between 10 and 11 bytes into a destination of size 10

228 |         snprintf(name, sizeof(name), "pcie-phy%d", slot);
    |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Clean this up increasing destination buffer one byte.

---
 drivers/pci/controller/pcie-mt7621.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pcie-mt7621.c +1 -2
index 79e225edb42a..d97b956e6e57 100644
@@ -202,7 +202,7 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie,
        struct mt7621_pcie_port *port;
        struct device *dev = pcie->dev;
        struct platform_device *pdev = to_platform_device(dev);
-       char name[10];
+       char name[11];
        int err;
 
        port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
--
Quoted 2 lines

2.25.1

Gentle ping on this patch :)

Thanks,
Sergio Paracuellos

author maintainer
#2 lore raw

Hi,

Quoted 40 lines · Sergio Paracuellos

Hi,

Quoted 35 lines · Sergio Paracuellos

The following warning appears when driver is compiled with W=1.

CC drivers/pci/controller/pcie-mt7621.o
drivers/pci/controller/pcie-mt7621.c: In function ‘mt7621_pcie_probe’:
drivers/pci/controller/pcie-mt7621.c:228:49: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
228 | snprintf(name, sizeof(name), "pcie-phy%d", slot);
| ^
drivers/pci/controller/pcie-mt7621.c:228:9: note: ‘snprintf’ output between 10 and 11 bytes into a destination of size 10

228 |         snprintf(name, sizeof(name), "pcie-phy%d", slot);
    |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Clean this up increasing destination buffer one byte.

---
 drivers/pci/controller/pcie-mt7621.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pcie-mt7621.c +1 -1
index 79e225edb42a..d97b956e6e57 100644
@@ -202,7 +202,7 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie,
        struct mt7621_pcie_port *port;
        struct device *dev = pcie->dev;
        struct platform_device *pdev = to_platform_device(dev);
-       char name[10];
+       char name[11];
        int err;
 
Quoted 6 lines
Quoted 4 lines
drivers/pci/controller/pcie-mt7621.c +0 -1
        port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
--

2.25.1

Gentle ping on this patch :)

Another gentle ping on this patch :)

Thanks,
Sergio Paracuellos

#3 lore raw
In reply to Sergio Paracuellos
Quoted 10 lines · Sergio Paracuellos

The following warning appears when driver is compiled with W=1.

CC drivers/pci/controller/pcie-mt7621.o
drivers/pci/controller/pcie-mt7621.c: In function ‘mt7621_pcie_probe’:
drivers/pci/controller/pcie-mt7621.c:228:49: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
228 | snprintf(name, sizeof(name), "pcie-phy%d", slot);
| ^
drivers/pci/controller/pcie-mt7621.c:228:9: note: ‘snprintf’ output between 10 and 11 bytes into a destination of size 10

Quoted 8 lines
228 |         snprintf(name, sizeof(name), "pcie-phy%d", slot);
    |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Clean this up increasing destination buffer one byte.

Krzysztof applied this to pci/controller/mt7621 for v6.10, thanks! I just pulled that branch into "next", so it should appear in the next linux-next.

Quoted 20 lines
---
 drivers/pci/controller/pcie-mt7621.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pcie-mt7621.c +1 -1
index 79e225edb42a..d97b956e6e57 100644
@@ -202,7 +202,7 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie,
 	struct mt7621_pcie_port *port;
 	struct device *dev = pcie->dev;
 	struct platform_device *pdev = to_platform_device(dev);
-	char name[10];
+	char name[11];
 	int err;
 
 	port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
Signature · 1 line
2.25.1
author maintainer
#4 lore raw
Quoted 17 lines · Bjorn Helgaas
Quoted 15 lines · Sergio Paracuellos

The following warning appears when driver is compiled with W=1.

CC drivers/pci/controller/pcie-mt7621.o
drivers/pci/controller/pcie-mt7621.c: In function ‘mt7621_pcie_probe’:
drivers/pci/controller/pcie-mt7621.c:228:49: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
228 | snprintf(name, sizeof(name), "pcie-phy%d", slot);
| ^
drivers/pci/controller/pcie-mt7621.c:228:9: note: ‘snprintf’ output between 10 and 11 bytes into a destination of size 10

228 |         snprintf(name, sizeof(name), "pcie-phy%d", slot);
    |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Clean this up increasing destination buffer one byte.

Quoted 7 lines
Quoted 3 lines

Krzysztof applied this to pci/controller/mt7621 for v6.10, thanks! I just pulled that branch into "next", so it should appear in the next linux-next.

Awesome. Thanks for letting me know.

Best regards,
Sergio Paracuellos

#5 lore raw
In reply to Sergio Paracuellos

Hello,

Quoted 10 lines

The following warning appears when driver is compiled with W=1.

CC drivers/pci/controller/pcie-mt7621.o
drivers/pci/controller/pcie-mt7621.c: In function ‘mt7621_pcie_probe’:
drivers/pci/controller/pcie-mt7621.c:228:49: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
228 | snprintf(name, sizeof(name), "pcie-phy%d", slot);
| ^
drivers/pci/controller/pcie-mt7621.c:228:9: note: ‘snprintf’ output between 10 and 11 bytes into a destination of size 10

Quoted 4 lines
228 |         snprintf(name, sizeof(name), "pcie-phy%d", slot);
    |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Clean this up increasing destination buffer one byte.

Applied to controller/mt7621, thank you!

[1/1] PCI: mt7621: Fix string truncation in mt7621_pcie_parse_port()

      https://git.kernel.org/pci/pci/c/fd6eb49a84a8

	Krzysztof