]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
Avoid unaligned fetch in ladr_match()
authorNick Briggs <nicholas.h.briggs@gmail.com>
Thu, 1 Feb 2024 18:11:17 +0000 (10:11 -0800)
committerMichael Tokarev <mjt@tls.msk.ru>
Wed, 13 Mar 2024 20:09:00 +0000 (23:09 +0300)
There is no guarantee that the PCNetState is allocated such that
csr[8] is allocated on an 8-byte boundary.  Since not all hosts are
capable of unaligned fetches the 16-bit elements need to be fetched
individually to avoid a potential fault.  Closes issue #2143

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2143
Signed-off-by: Nick Briggs <nicholas.h.briggs@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
(cherry picked from commit 6a5287ce80470bb8df95901d73ee779a64e70c3a)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
hw/net/pcnet.c

index 56c3d14ad6ad212ee3e1ff74697dd40b8289d935..05ce8310ef23ad7ee29488c77398b4af82841044 100644 (file)
@@ -632,7 +632,7 @@ static inline int ladr_match(PCNetState *s, const uint8_t *buf, int size)
 {
     struct qemu_ether_header *hdr = (void *)buf;
     if ((*(hdr->ether_dhost)&0x01) &&
-        ((uint64_t *)&s->csr[8])[0] != 0LL) {
+        (s->csr[8] | s->csr[9] | s->csr[10] | s->csr[11]) != 0) {
         uint8_t ladr[8] = {
             s->csr[8] & 0xff, s->csr[8] >> 8,
             s->csr[9] & 0xff, s->csr[9] >> 8,