Skip to content

Commit 4a7ce83

Browse files
GustavoARSilvabjorn-helgaas
authored andcommitted
PCI/P2PDMA: Fix undefined behavior bug in struct pci_p2pdma_pagemap
Struct dev_pagemap is a flexible structure, which means that it contains a flexible-array member. If dev_pagemap.nr_range > 1, the memory following the dev_pagemap could be overwritten. This is currently not an issue because pci_p2pdma_pagemap is not exposed outside p2pdma.c, and p2pdma.c only sets dev_pagemap.nr_range to 1. To prevent problems if p2pdma.c ever uses nr_range > 1, move the flexible struct dev_pagemap to 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. Link: https://lore.kernel.org/r/ZRsUL/hATNruwtla@work Signed-off-by: "Gustavo A. R. Silva" <[email protected]> [bhelgaas: commit log] Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Logan Gunthorpe <[email protected]>
1 parent 0bb80ec commit 4a7ce83

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/pci/p2pdma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ struct pci_p2pdma {
2828
};
2929

3030
struct pci_p2pdma_pagemap {
31-
struct dev_pagemap pgmap;
3231
struct pci_dev *provider;
3332
u64 bus_offset;
33+
struct dev_pagemap pgmap;
3434
};
3535

3636
static struct pci_p2pdma_pagemap *to_p2p_pgmap(struct dev_pagemap *pgmap)

0 commit comments

Comments
 (0)