From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Logan Gunthorpe <logang@deltatee.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] PCI/P2PDMA: Fix undefined behavior bug in struct pci_p2pdma_pagemap
Date: Mon, 2 Oct 2023 20:40:31 +0200 [thread overview]
Message-ID: <734c7fdf-4c41-2890-dbe7-ddb23fd6bcc7@embeddedor.com> (raw)
In-Reply-To: <29da763d-1570-7197-2d5a-03c5659b8b52@deltatee.com>
On 10/2/23 18:07, Logan Gunthorpe wrote:
>
>
> On 2023-10-01 15:08, 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`.
>>
>> 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.
>>
>> Fixes: 0afea3814358 ("PCI/P2PDMA: Add provider's pci_dev to pci_p2pdma_pagemap struct")
>> Fixes: a6e6fe6549f6 ("PCI/P2PDMA: Introduce private pagemap structure")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>
>
> Makes sense to me, thanks.
>
> Although, I'm not sure the fixes tags are appropriate. The
> flexible-array member was introduced in 5.10 (b7b3c01b19) and both the
> "fixed" commits predate that change by a number of releases.
You're right. I'll remove those tags.
>
> Also, it's probably worth noting in the commit message that the p2pdma
> code hardcodes nr_ranges to 1 (in pci_p2pdma_add_resource); so there is
> no way to actually hit any bug with the current code.
Yep. I mention that in this part "This could potentially lead to an
overwrite of the objects following `pgmap` in `struct pci_p2pdma_pagemap`,
when `nr_range > 1`."
>
> I totally agree that the patch should be applied to prevent possible
> bugs being introduced in the future:
>
> Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Thanks for the RB and the feedback. :)
--
Gustavo
next prev parent reply other threads:[~2023-10-02 18:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-01 21:08 [PATCH][next] PCI/P2PDMA: Fix undefined behavior bug in struct pci_p2pdma_pagemap Gustavo A. R. Silva
2023-10-02 16:07 ` Logan Gunthorpe
2023-10-02 18:40 ` Gustavo A. R. Silva [this message]
2023-10-02 18:46 ` Logan Gunthorpe
2023-10-02 19:06 ` Gustavo A. R. Silva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=734c7fdf-4c41-2890-dbe7-ddb23fd6bcc7@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=bhelgaas@google.com \
--cc=gustavoars@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox