softmmu: Use memmove in flatview_write_continue
commit4a73aee88140fe7e4930375d3c786b10b2b5d447
authorAkihiko Odaki <akihiko.odaki@daynix.com>
Tue, 31 Jan 2023 03:01:55 +0000 (31 12:01 +0900)
committerRichard Henderson <richard.henderson@linaro.org>
Tue, 28 Feb 2023 20:32:31 +0000 (28 10:32 -1000)
tree6507b1009a4eb2ac98ec85df0eec15f35ca218fd
parent0c4d7ddbd38038aa2aff6a3a61996ef8d6b1f559
softmmu: Use memmove in flatview_write_continue

We found a case where the source passed to flatview_write_continue() may
overlap with the destination when fuzzing igb, a new proposed network
device with sanitizers.

igb uses pci_dma_map() to get Tx packet, and pci_dma_write() to write Rx
buffer. While pci_dma_write() is usually used to write data from
memory not mapped to the guest, if igb is configured to perform
loopback, the data will be sourced from the guest memory. The source and
destination can overlap and the usage of memcpy() will be invalid in
such a case.

While we do not really have to deal with such an invalid request for
igb, detecting the overlap in igb code beforehand requires complex code,
and only covers this specific case. Instead, just replace memcpy() with
memmove() to tolerate overlaps. Using memmove() will slightly damage the
performance as it will need to check overlaps before using SIMD
instructions for copying, but the cost should be negligible, considering
the inherent complexity of flatview_write_continue().

The test cases generated by the fuzzer is available at:
https://patchew.org/QEMU/20230129053316.1071513-1-alxndr@bu.edu/

The fixed test case is:
fuzz/crash_47dfe62d9f911bf523ff48cd441b61c0013ed805

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Acked-by: Alexander Bulekov <alxndr@bu.edu>
Acked-by: David Hildenbrand <david@redhat.com>
Message-Id: <20230131030155.18932-1-akihiko.odaki@daynix.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
softmmu/physmem.c