[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 27/35] hw/net/msf2-emac: Don't modify descriptor in-place in emac_
From: |
Peter Maydell |
Subject: |
[PULL 27/35] hw/net/msf2-emac: Don't modify descriptor in-place in emac_store_desc() |
Date: |
Tue, 2 May 2023 13:14:51 +0100 |
The msf2-emac ethernet controller has functions emac_load_desc() and
emac_store_desc() which read and write the in-memory descriptor
blocks and handle conversion between guest and host endianness.
As currently written, emac_store_desc() does the endianness
conversion in-place; this means that it effectively consumes the
input EmacDesc struct, because on a big-endian host the fields will
be overwritten with the little-endian versions of their values.
Unfortunately, in all the callsites the code continues to access
fields in the EmacDesc struct after it has called emac_store_desc()
-- specifically, it looks at the d.next field.
The effect of this is that on a big-endian host networking doesn't
work because the address of the next descriptor is corrupted.
We could fix this by making the callsite avoid using the struct; but
it's more robust to have emac_store_desc() leave its input alone.
(emac_load_desc() also does an in-place conversion, but here this is
fine, because the function is supposed to be initializing the
struct.)
Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-id: 20230424151919.1333299-1-peter.maydell@linaro.org
---
hw/net/msf2-emac.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/hw/net/msf2-emac.c b/hw/net/msf2-emac.c
index 7ccd3e51427..db3a04deb19 100644
--- a/hw/net/msf2-emac.c
+++ b/hw/net/msf2-emac.c
@@ -118,14 +118,18 @@ static void emac_load_desc(MSF2EmacState *s, EmacDesc *d,
hwaddr desc)
d->next = le32_to_cpu(d->next);
}
-static void emac_store_desc(MSF2EmacState *s, EmacDesc *d, hwaddr desc)
+static void emac_store_desc(MSF2EmacState *s, const EmacDesc *d, hwaddr desc)
{
- /* Convert from host endianness into LE. */
- d->pktaddr = cpu_to_le32(d->pktaddr);
- d->pktsize = cpu_to_le32(d->pktsize);
- d->next = cpu_to_le32(d->next);
+ EmacDesc outd;
+ /*
+ * Convert from host endianness into LE. We use a local struct because
+ * calling code may still want to look at the fields afterwards.
+ */
+ outd.pktaddr = cpu_to_le32(d->pktaddr);
+ outd.pktsize = cpu_to_le32(d->pktsize);
+ outd.next = cpu_to_le32(d->next);
- address_space_write(&s->dma_as, desc, MEMTXATTRS_UNSPECIFIED, d, sizeof
*d);
+ address_space_write(&s->dma_as, desc, MEMTXATTRS_UNSPECIFIED, &outd,
sizeof outd);
}
static void msf2_dma_tx(MSF2EmacState *s)
--
2.34.1
- [PULL 01/35] target/arm: Move cortex sysregs into a separate file, (continued)
- [PULL 01/35] target/arm: Move cortex sysregs into a separate file, Peter Maydell, 2023/05/02
- [PULL 02/35] target/arm: Remove dead code from cpu_max_set_sve_max_vq, Peter Maydell, 2023/05/02
- [PULL 09/35] tests/avocado: Pass parameters to migration test, Peter Maydell, 2023/05/02
- [PULL 03/35] target/arm: Extract TCG -cpu max code into a function, Peter Maydell, 2023/05/02
- [PULL 04/35] target/arm: Do not expose all -cpu max features to qtests, Peter Maydell, 2023/05/02
- [PULL 15/35] hw/arm/bcm2835_property: Implement "get command line" message, Peter Maydell, 2023/05/02
- [PULL 28/35] hw/arm/boot: Make write_bootloader() public as arm_write_bootloader(), Peter Maydell, 2023/05/02
- [PULL 26/35] docs/about/deprecated.rst: Add "since 7.1" tag to dtb-kaslr-seed deprecation, Peter Maydell, 2023/05/02
- [PULL 25/35] qmp: Deprecate 'singlestep' member of StatusInfo, Peter Maydell, 2023/05/02
- [PULL 14/35] hw/net: npcm7xx_emc: set MAC in register space, Peter Maydell, 2023/05/02
- [PULL 27/35] hw/net/msf2-emac: Don't modify descriptor in-place in emac_store_desc(),
Peter Maydell <=
- [PULL 23/35] hmp: Add 'one-insn-per-tb' command equivalent to 'singlestep', Peter Maydell, 2023/05/02
- [PULL 16/35] make one-insn-per-tb an accel option, Peter Maydell, 2023/05/02
- [PULL 31/35] hw/intc/allwinner-a10-pic: Don't use set_bit()/clear_bit(), Peter Maydell, 2023/05/02
- [PULL 33/35] target/arm: Add compile time asserts to load/store_cpu_field macros, Peter Maydell, 2023/05/02
- [PULL 24/35] qapi/run-state.json: Fix missing newline at end of file, Peter Maydell, 2023/05/02
- [PULL 32/35] target/arm: Define and use new load_cpu_field_low32(), Peter Maydell, 2023/05/02
- [PULL 05/35] target/arm: Move 64-bit TCG CPUs into tcg/, Peter Maydell, 2023/05/02
- [PULL 22/35] accel/tcg: Report one-insn-per-tb in 'info jit', not 'info status', Peter Maydell, 2023/05/02
- [PULL 10/35] arm/Kconfig: Always select SEMIHOSTING when TCG is present, Peter Maydell, 2023/05/02
- [PULL 06/35] tests/qtest: Adjust and document query-cpu-model-expansion test for arm, Peter Maydell, 2023/05/02