[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 37/55] pci: Sanity check mask argument to pci_set_*_by_mask()
From: |
Michael S. Tsirkin |
Subject: |
[PULL 37/55] pci: Sanity check mask argument to pci_set_*_by_mask() |
Date: |
Mon, 10 Oct 2022 13:31:23 -0400 |
From: Peter Maydell <peter.maydell@linaro.org>
Coverity complains that in functions like pci_set_word_by_mask()
we might end up shifting by more than 31 bits. This is true,
but only if the caller passes in a zero mask. Help Coverity out
by asserting that the mask argument is valid.
Fixes: CID 1487168
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20220818135421.2515257-3-peter.maydell@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/hw/pci/pci.h | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index c79144bc5e..97937cc922 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -688,7 +688,10 @@ static inline void
pci_set_byte_by_mask(uint8_t *config, uint8_t mask, uint8_t reg)
{
uint8_t val = pci_get_byte(config);
- uint8_t rval = reg << ctz32(mask);
+ uint8_t rval;
+
+ assert(mask);
+ rval = reg << ctz32(mask);
pci_set_byte(config, (~mask & val) | (mask & rval));
}
@@ -696,7 +699,10 @@ static inline void
pci_set_word_by_mask(uint8_t *config, uint16_t mask, uint16_t reg)
{
uint16_t val = pci_get_word(config);
- uint16_t rval = reg << ctz32(mask);
+ uint16_t rval;
+
+ assert(mask);
+ rval = reg << ctz32(mask);
pci_set_word(config, (~mask & val) | (mask & rval));
}
@@ -704,7 +710,10 @@ static inline void
pci_set_long_by_mask(uint8_t *config, uint32_t mask, uint32_t reg)
{
uint32_t val = pci_get_long(config);
- uint32_t rval = reg << ctz32(mask);
+ uint32_t rval;
+
+ assert(mask);
+ rval = reg << ctz32(mask);
pci_set_long(config, (~mask & val) | (mask & rval));
}
@@ -712,7 +721,10 @@ static inline void
pci_set_quad_by_mask(uint8_t *config, uint64_t mask, uint64_t reg)
{
uint64_t val = pci_get_quad(config);
- uint64_t rval = reg << ctz32(mask);
+ uint64_t rval;
+
+ assert(mask);
+ rval = reg << ctz32(mask);
pci_set_quad(config, (~mask & val) | (mask & rval));
}
--
MST
- Re: [PULL 29/55] Revert "intel_iommu: Fix irqchip / X2APIC configuration checks", (continued)
[PULL 31/55] qmp: add QMP command x-query-virtio-status, Michael S. Tsirkin, 2022/10/10
[PULL 30/55] qmp: add QMP command x-query-virtio, Michael S. Tsirkin, 2022/10/10
[PULL 33/55] qmp: add QMP commands for virtio/vhost queue-status, Michael S. Tsirkin, 2022/10/10
[PULL 32/55] qmp: decode feature & status bits in virtio-status, Michael S. Tsirkin, 2022/10/10
[PULL 34/55] qmp: add QMP command x-query-virtio-queue-element, Michael S. Tsirkin, 2022/10/10
[PULL 35/55] hmp: add virtio commands, Michael S. Tsirkin, 2022/10/10
[PULL 36/55] pci: Remove unused pci_get_*_by_mask() functions, Michael S. Tsirkin, 2022/10/10
[PULL 37/55] pci: Sanity check mask argument to pci_set_*_by_mask(),
Michael S. Tsirkin <=
[PULL 38/55] hw/smbios: support for type 8 (port connector), Michael S. Tsirkin, 2022/10/10
[PULL 39/55] tests: acpi: whitelist pc/q35 DSDT due to HPET AML move, Michael S. Tsirkin, 2022/10/10
[PULL 40/55] acpi: x86: deduplicate HPET AML building, Michael S. Tsirkin, 2022/10/10
[PULL 41/55] tests: acpi: update expected blobs after HPET move, Michael S. Tsirkin, 2022/10/10
[PULL 43/55] acpi: x86: refactor PDSM method to reduce nesting, Michael S. Tsirkin, 2022/10/10
[PULL 42/55] tests: acpi: whitelist pc/q35 DSDT due to HPET AML move, Michael S. Tsirkin, 2022/10/10
[PULL 44/55] x86: acpi: _DSM: use Package to pass parameters, Michael S. Tsirkin, 2022/10/10
[PULL 45/55] tests: acpi: update expected blobs, Michael S. Tsirkin, 2022/10/10
[PULL 46/55] tests: acpi: whitelist pc/q35 DSDT before switching _DSM to use ASUN, Michael S. Tsirkin, 2022/10/10
[PULL 47/55] x86: acpi: cleanup PCI device _DSM duplication, Michael S. Tsirkin, 2022/10/10