Avoid unaligned fetch in ladr_match()
authorNick Briggs <nicholas.h.briggs@gmail.com>
Thu, 1 Feb 2024 18:11:17 +0000 (10:11 -0800)
committerJason Wang <jasowang@redhat.com>
Tue, 12 Mar 2024 11:28:32 +0000 (19:28 +0800)
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>
hw/net/pcnet.c

index 494eab84791953740fe8fff5c5bf608a9c2010e5..ad675ab29d4d275409bd889ec9990b7c4811d86f 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,