PCI/P2PDMA: Fix potential undefined behavior bug in struct pci_p2pdma_pagemap
Subsystems (2)
PATCH v2 1/1 PCI/P2PDMA: Fix potential undefined behavior bug in struct pci_p2pdma_pagemap
struct dev_pagemap is a flexible structure, which means that it contains a flexible-array member at the bottom. This could potentially lead to an overwrite of the objects following pgmap in struct pci_p2pdma_pagemap, when nr_range > 1. This is currently not the case (notice that nr_range is hardcoded to 1), however as commit b7b3c01b1915 ("mm/memremap_pages: support multiple ranges per invocation") mentions in the subject line, this code can support multiple ranges per invocation. So, we'd better prevent any problems that may arise in the future.
Fix this by placing the declaration of object pgmap at the end of struct pci_p2pdma_pagemap.
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally.
---
Changes in v2:
- Remove Fixes: tags. (Logan Gunthorpe)
- Update changelog text. Make it clear that nr_range is hardcoded to 1 (Logan Gunthorpe)
- Update subject.
- Add Logan's RB.
v1:
drivers/pci/p2pdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/p2pdma.c +1 -1
@@ -28,9 +28,9 @@ struct pci_p2pdma { };struct pci_p2pdma_pagemap { -struct dev_pagemap pgmap;struct pci_dev *provider;u64 bus_offset; +struct dev_pagemap pgmap; };static struct pci_p2pdma_pagemap *to_p2p_pgmap (struct dev_pagemap *pgmap)
Signature · 1 line
2.34.1
Bjorn Helgaas
AppliedQuoted 10 lines · Gustavo A. R. Silva
struct dev_pagemapis a flexible structure, which means that it contains a flexible-array member at the bottom. This could potentially lead to an overwrite of the objects followingpgmapinstruct pci_p2pdma_pagemap, whennr_range > 1. This is currently not the case (notice thatnr_rangeis hardcoded to1), however as commitb7b3c01b1915("mm/memremap_pages: support multiple ranges per invocation") mentions in the subject line, this code cansupport multiple ranges per invocation. So, we'd better prevent any problems that may arise in the future.
Quoted 8 lines
Fix this by placing the declaration of object
pgmapat the end ofstruct pci_p2pdma_pagemap.-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally.
Reviewed-by Logan Gunthorpe <[email protected]>Signed-off-by Gustavo A. R. Silva <[email protected]>
Applied to pci/p2pdma for v6.7. Since it's not a current problem, I assume there's no reason to apply it for v6.6 (or tag it for stable); let me know if otherwise.
Quoted 32 lines
---
Changes in v2:
- RemoveFixes:tags. (Logan Gunthorpe)
- Update changelog text. Make it clear thatnr_rangeis hardcoded to1(Logan Gunthorpe)
- Update subject.
- Add Logan's RB.v1:
drivers/pci/p2pdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/p2pdma.c +1
-1@@ -28,9 +28,9 @@ struct pci_p2pdma { };struct pci_p2pdma_pagemap { -struct dev_pagemap pgmap;struct pci_dev *provider;u64 bus_offset; +struct dev_pagemap pgmap; };static struct pci_p2pdma_pagemap *to_p2p_pgmap (struct dev_pagemap *pgmap)Signature · 1 line
2.34.1