* [PATCH] pci: assert configuration access is within bounds
@ 2020-06-04 11:35 P J P
2020-06-04 11:41 ` Michael S. Tsirkin
2020-06-04 16:36 ` Dr. David Alan Gilbert
0 siblings, 2 replies; 4+ messages in thread
From: P J P @ 2020-06-04 11:35 UTC (permalink / raw)
To: Michael S . Tsirkin
Cc: Peter Maydell, Daniel P . Berrangé,
Prasad J Pandit, QEMU Developers, Gerd Hoffmann,
Philippe Mathieu-Daudé
From: Prasad J Pandit <pjp@fedoraproject.org>
While accessing PCI configuration bytes, assert that
'address + len' is within PCI configuration space.
Generally it is within bounds. This is more of a defensive
assert, in case a buggy device was to send 'address' which
may go out of bounds.
Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
hw/pci/pci.c | 4 ++++
1 file changed, 4 insertions(+)
Update v1: defensive assert as separate patch
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00957.html
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00960.html
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 70c66965f5..7bf2ae6d92 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1381,6 +1381,8 @@ uint32_t pci_default_read_config(PCIDevice *d,
{
uint32_t val = 0;
+ assert(address + len <= pci_config_size(d));
+
if (pci_is_express_downstream_port(d) &&
ranges_overlap(address, len, d->exp.exp_cap + PCI_EXP_LNKSTA, 2)) {
pcie_sync_bridge_lnk(d);
@@ -1394,6 +1396,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, int
int i, was_irq_disabled = pci_irq_disabled(d);
uint32_t val = val_in;
+ assert(addr + l <= pci_config_size(d));
+
for (i = 0; i < l; val >>= 8, ++i) {
uint8_t wmask = d->wmask[addr + i];
uint8_t w1cmask = d->w1cmask[addr + i];
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] pci: assert configuration access is within bounds
2020-06-04 11:35 [PATCH] pci: assert configuration access is within bounds P J P
@ 2020-06-04 11:41 ` Michael S. Tsirkin
2020-06-04 16:36 ` Dr. David Alan Gilbert
1 sibling, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2020-06-04 11:41 UTC (permalink / raw)
To: P J P
Cc: Peter Maydell, Daniel P . Berrangé,
Prasad J Pandit, QEMU Developers, Gerd Hoffmann,
Philippe Mathieu-Daudé
On Thu, Jun 04, 2020 at 05:05:25PM +0530, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> While accessing PCI configuration bytes, assert that
> 'address + len' is within PCI configuration space.
>
> Generally it is within bounds. This is more of a defensive
> assert, in case a buggy device was to send 'address' which
> may go out of bounds.
>
> Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> hw/pci/pci.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> Update v1: defensive assert as separate patch
> -> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00957.html
> -> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00960.html
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 70c66965f5..7bf2ae6d92 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1381,6 +1381,8 @@ uint32_t pci_default_read_config(PCIDevice *d,
> {
> uint32_t val = 0;
>
> + assert(address + len <= pci_config_size(d));
> +
> if (pci_is_express_downstream_port(d) &&
> ranges_overlap(address, len, d->exp.exp_cap + PCI_EXP_LNKSTA, 2)) {
> pcie_sync_bridge_lnk(d);
> @@ -1394,6 +1396,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, int
> int i, was_irq_disabled = pci_irq_disabled(d);
> uint32_t val = val_in;
>
> + assert(addr + l <= pci_config_size(d));
> +
> for (i = 0; i < l; val >>= 8, ++i) {
> uint8_t wmask = d->wmask[addr + i];
> uint8_t w1cmask = d->w1cmask[addr + i];
> --
> 2.26.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] pci: assert configuration access is within bounds
2020-06-04 11:35 [PATCH] pci: assert configuration access is within bounds P J P
2020-06-04 11:41 ` Michael S. Tsirkin
@ 2020-06-04 16:36 ` Dr. David Alan Gilbert
2020-06-09 15:30 ` Michael S. Tsirkin
1 sibling, 1 reply; 4+ messages in thread
From: Dr. David Alan Gilbert @ 2020-06-04 16:36 UTC (permalink / raw)
To: P J P
Cc: Peter Maydell, Daniel P . Berrangé,
Prasad J Pandit, Michael S . Tsirkin, QEMU Developers,
Gerd Hoffmann, Philippe Mathieu-Daudé
* P J P (ppandit@redhat.com) wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> While accessing PCI configuration bytes, assert that
> 'address + len' is within PCI configuration space.
>
> Generally it is within bounds. This is more of a defensive
> assert, in case a buggy device was to send 'address' which
> may go out of bounds.
Can a guest trigger this assert?
Dave
> Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
> hw/pci/pci.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> Update v1: defensive assert as separate patch
> -> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00957.html
> -> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00960.html
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 70c66965f5..7bf2ae6d92 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1381,6 +1381,8 @@ uint32_t pci_default_read_config(PCIDevice *d,
> {
> uint32_t val = 0;
>
> + assert(address + len <= pci_config_size(d));
> +
> if (pci_is_express_downstream_port(d) &&
> ranges_overlap(address, len, d->exp.exp_cap + PCI_EXP_LNKSTA, 2)) {
> pcie_sync_bridge_lnk(d);
> @@ -1394,6 +1396,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, int
> int i, was_irq_disabled = pci_irq_disabled(d);
> uint32_t val = val_in;
>
> + assert(addr + l <= pci_config_size(d));
> +
> for (i = 0; i < l; val >>= 8, ++i) {
> uint8_t wmask = d->wmask[addr + i];
> uint8_t w1cmask = d->w1cmask[addr + i];
> --
> 2.26.2
>
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] pci: assert configuration access is within bounds
2020-06-04 16:36 ` Dr. David Alan Gilbert
@ 2020-06-09 15:30 ` Michael S. Tsirkin
0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2020-06-09 15:30 UTC (permalink / raw)
To: Dr. David Alan Gilbert
Cc: Peter Maydell, Daniel P . Berrangé,
Prasad J Pandit, QEMU Developers, P J P, Gerd Hoffmann,
Philippe Mathieu-Daudé
On Thu, Jun 04, 2020 at 05:36:31PM +0100, Dr. David Alan Gilbert wrote:
> * P J P (ppandit@redhat.com) wrote:
> > From: Prasad J Pandit <pjp@fedoraproject.org>
> >
> > While accessing PCI configuration bytes, assert that
> > 'address + len' is within PCI configuration space.
> >
> > Generally it is within bounds. This is more of a defensive
> > assert, in case a buggy device was to send 'address' which
> > may go out of bounds.
>
> Can a guest trigger this assert?
>
> Dave
Shouldn't be able to, no.
> > Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> > ---
> > hw/pci/pci.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > Update v1: defensive assert as separate patch
> > -> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00957.html
> > -> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00960.html
> >
> > diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> > index 70c66965f5..7bf2ae6d92 100644
> > --- a/hw/pci/pci.c
> > +++ b/hw/pci/pci.c
> > @@ -1381,6 +1381,8 @@ uint32_t pci_default_read_config(PCIDevice *d,
> > {
> > uint32_t val = 0;
> >
> > + assert(address + len <= pci_config_size(d));
> > +
> > if (pci_is_express_downstream_port(d) &&
> > ranges_overlap(address, len, d->exp.exp_cap + PCI_EXP_LNKSTA, 2)) {
> > pcie_sync_bridge_lnk(d);
> > @@ -1394,6 +1396,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, int
> > int i, was_irq_disabled = pci_irq_disabled(d);
> > uint32_t val = val_in;
> >
> > + assert(addr + l <= pci_config_size(d));
> > +
> > for (i = 0; i < l; val >>= 8, ++i) {
> > uint8_t wmask = d->wmask[addr + i];
> > uint8_t w1cmask = d->w1cmask[addr + i];
> > --
> > 2.26.2
> >
> >
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-09 15:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-04 11:35 [PATCH] pci: assert configuration access is within bounds P J P
2020-06-04 11:41 ` Michael S. Tsirkin
2020-06-04 16:36 ` Dr. David Alan Gilbert
2020-06-09 15:30 ` Michael S. Tsirkin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.