* [PATCH v2][next] PCI/P2PDMA: Fix potential undefined behavior bug in struct pci_p2pdma_pagemap
@ 2023-10-02 19:04 Gustavo A. R. Silva
2023-10-03 22:30 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2023-10-02 19:04 UTC (permalink / raw)
To: Bjorn Helgaas, Logan Gunthorpe
Cc: linux-pci, linux-kernel, Gustavo A. R. Silva, linux-hardening
`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.
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
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:
Link: https://lore.kernel.org/linux-hardening/ZRnf6wVOu0IJQ2Ok@work/
drivers/pci/p2pdma.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index fa7370f9561a..ab34d3d36a64 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -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)
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2][next] PCI/P2PDMA: Fix potential undefined behavior bug in struct pci_p2pdma_pagemap
2023-10-02 19:04 [PATCH v2][next] PCI/P2PDMA: Fix potential undefined behavior bug in struct pci_p2pdma_pagemap Gustavo A. R. Silva
@ 2023-10-03 22:30 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2023-10-03 22:30 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Bjorn Helgaas, Logan Gunthorpe, linux-pci, linux-kernel,
linux-hardening
On Mon, Oct 02, 2023 at 09:04:15PM +0200, Gustavo A. R. Silva wrote:
> `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.
>
> Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
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.
> ---
> 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:
> Link: https://lore.kernel.org/linux-hardening/ZRnf6wVOu0IJQ2Ok@work/
>
> drivers/pci/p2pdma.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
> index fa7370f9561a..ab34d3d36a64 100644
> --- a/drivers/pci/p2pdma.c
> +++ b/drivers/pci/p2pdma.c
> @@ -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)
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-03 22:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-02 19:04 [PATCH v2][next] PCI/P2PDMA: Fix potential undefined behavior bug in struct pci_p2pdma_pagemap Gustavo A. R. Silva
2023-10-03 22:30 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).