Skip to contentSkip to conversation

PCI: quirks: Fix out-of-bounds MMIO read in nvme_disable_and_flr()

PATCH Applied Mohamad Raizudeen 4 participants 5 messages Sep 3 – Oct 14 PCI

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 PCI: quirks: Fix out-of-bounds MMIO read in nvme_disable_and_flr()

In nvme_disable_and_flr(), the PCI bar is mapped using NVME_REG_CC + sizeof(cfg) which is (0x14 + 4 = 0x18 bytes)

However, the function later reads the controller status from NVME_REG_CSTS - offset 0x1C, which is outside the mapped 0x18 byte boundary. This violates the API contract.

Fix this by increasing the mapping size to include NVME_REG_CSTS. Also change sizeof(cfg) to sizeof(u32) to make the intent clearer.

Fixes ffb0863426eb9 ("PCI: Disable Samsung SM961/PM961 NVMe before FLR")

---
Changes in v3:
- Changed sizeof(cfg) to sizeof(u32) to decouple it from the mapping size as suggested by Alex Williamson.
- Updated the commit message to use "violates the API contract" instead of "undefined behavior" to avoid overstating the risk.

Link for v1: https://lore.kernel.org/all/[email protected]/T/
Link for v2: https://lore.kernel.org/all/[email protected]/T/

 drivers/pci/quirks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/quirks.c +1 -1
index b09f27f7846f..06436a96db30 100644
@@ -4090,7 +4090,7 @@ static int nvme_disable_and_flr(struct pci_dev *dev, bool probe)
 	if (probe)
 		return 0;
 
-	bar = pci_iomap(dev, 0, NVME_REG_CC + sizeof(cfg));
+	bar = pci_iomap(dev, 0, NVME_REG_CSTS + sizeof(u32));
 	if (!bar)
 		return -ENOTTY;
 
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

In nvme_disable_and_flr(), the PCI bar is mapped using NVME_REG_CC + sizeof(cfg) which is (0x14 + 4 = 0x18 bytes)

However, the function later reads the controller status from NVME_REG_CSTS - offset 0x1C, which is outside the mapped 0x18 byte boundary. This violates the API contract.

Quoted 5 lines

Fix this by increasing the mapping size to include NVME_REG_CSTS. Also change sizeof(cfg) to sizeof(u32) to make the intent clearer.

Fixes ffb0863426eb9 ("PCI: Disable Samsung SM961/PM961 NVMe before FLR")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v3 1/1
#2 lore raw
In reply to Mohamad Raizudeen
Quoted 30 lines · On Thu, 3 Sep 2026 22:16:15 +0530 Mohamad Raizudeen…

In nvme_disable_and_flr(), the PCI bar is mapped using NVME_REG_CC + sizeof(cfg) which is (0x14 + 4 = 0x18 bytes)

However, the function later reads the controller status from NVME_REG_CSTS - offset 0x1C, which is outside the mapped 0x18 byte boundary. This violates the API contract.

Fix this by increasing the mapping size to include NVME_REG_CSTS. Also change sizeof(cfg) to sizeof(u32) to make the intent clearer.

Fixes ffb0863426eb9 ("PCI: Disable Samsung SM961/PM961 NVMe before FLR")

---
Changes in v3:
- Changed sizeof(cfg) to sizeof(u32) to decouple it from the mapping size as suggested by Alex Williamson.
- Updated the commit message to use "violates the API contract" instead of "undefined behavior" to avoid overstating the risk.

Link for v1: https://lore.kernel.org/all/[email protected]/T/
Link for v2: https://lore.kernel.org/all/[email protected]/T/

 drivers/pci/quirks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/quirks.c +0 -0
index b09f27f7846f..06436a96db30 100644

drivers/pci/quirks.c static int nvme_disable_and_flr(struct pci_dev *dev, bool probe) · line 4096

Quoted 8 lines
drivers/pci/quirks.c +1 -1
@@ -4090,7 +4090,7 @@ static int nvme_disable_and_flr(struct pci_dev *dev, bool probe)
 	if (probe)
 		return 0;
 
-	bar = pci_iomap(dev, 0, NVME_REG_CC + sizeof(cfg));
+	bar = pci_iomap(dev, 0, NVME_REG_CSTS + sizeof(u32));
 	if (!bar)
 		return -ENOTTY;
 

Thanks!

#3 lore raw
In reply to Mohamad Raizudeen
Quoted 41 lines · Mohamad Raizudeen

In nvme_disable_and_flr(), the PCI bar is mapped using NVME_REG_CC + sizeof(cfg) which is (0x14 + 4 = 0x18 bytes)

However, the function later reads the controller status from NVME_REG_CSTS - offset 0x1C, which is outside the mapped 0x18 byte boundary. This violates the API contract.

Fix this by increasing the mapping size to include NVME_REG_CSTS. Also change sizeof(cfg) to sizeof(u32) to make the intent clearer.

Fixes ffb0863426eb9 ("PCI: Disable Samsung SM961/PM961 NVMe before FLR")

---
Changes in v3:
- Changed sizeof(cfg) to sizeof(u32) to decouple it from the mapping size as suggested by Alex Williamson.
- Updated the commit message to use "violates the API contract" instead of "undefined behavior" to avoid overstating the risk.

Link for v1: https://lore.kernel.org/all/[email protected]/T/
Link for v2: https://lore.kernel.org/all/[email protected]/T/

 drivers/pci/quirks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/quirks.c +1 -1
index b09f27f7846f..06436a96db30 100644
@@ -4090,7 +4090,7 @@ static int nvme_disable_and_flr(struct pci_dev *dev, bool probe)
 	if (probe)
 		return 0;
 
-	bar = pci_iomap(dev, 0, NVME_REG_CC + sizeof(cfg));
+	bar = pci_iomap(dev, 0, NVME_REG_CSTS + sizeof(u32));
 	if (!bar)
 		return -ENOTTY;
 
Signature · 1 line
2.53.0

Gentle ping on this patch. It received a Reviewed-by from Alex a month ago, but I didn't see it queued or applied in the PCI tree yet. Just wanted to check if there is anything else needed from my side, or if it is pending for the next merge window.

Thanks,
Mohamad Raizudeen

#4 lore raw
In reply to Mohamad Raizudeen
Quoted 7 lines · Mohamad Raizudeen

In nvme_disable_and_flr(), the PCI bar is mapped using NVME_REG_CC + sizeof(cfg) which is (0x14 + 4 = 0x18 bytes)

However, the function later reads the controller status from NVME_REG_CSTS - offset 0x1C, which is outside the mapped 0x18 byte boundary. This violates the API contract.

Quoted 5 lines

Fix this by increasing the mapping size to include NVME_REG_CSTS. Also change sizeof(cfg) to sizeof(u32) to make the intent clearer.

Fixes ffb0863426eb9 ("PCI: Disable Samsung SM961/PM961 NVMe before FLR")

Applied to pci/misc for v7.4, thanks for the reminder!

Quoted 29 lines

---
Changes in v3:
- Changed sizeof(cfg) to sizeof(u32) to decouple it from the mapping size as suggested by Alex Williamson.
- Updated the commit message to use "violates the API contract" instead of "undefined behavior" to avoid overstating the risk.

Link for v1: https://lore.kernel.org/all/[email protected]/T/
Link for v2: https://lore.kernel.org/all/[email protected]/T/

 drivers/pci/quirks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/quirks.c +1 -1
index b09f27f7846f..06436a96db30 100644
@@ -4090,7 +4090,7 @@ static int nvme_disable_and_flr(struct pci_dev *dev, bool probe)
 	if (probe)
 		return 0;
 
-	bar = pci_iomap(dev, 0, NVME_REG_CC + sizeof(cfg));
+	bar = pci_iomap(dev, 0, NVME_REG_CSTS + sizeof(u32));
 	if (!bar)
 		return -ENOTTY;
 
Signature · 1 line
2.53.0