Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Avoid unaligned access in rge_get_macaddr(). Fou...



details:   https://anonhg.NetBSD.org/src/rev/1be27c51c13a
branches:  trunk
changeset: 989090:1be27c51c13a
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon Oct 11 15:11:49 2021 +0000

description:
Avoid unaligned access in rge_get_macaddr(). Found by kUBSan.

diffstat:

 sys/dev/pci/if_rge.c |  10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diffs (31 lines):

diff -r 41d1ad9567b8 -r 1be27c51c13a sys/dev/pci/if_rge.c
--- a/sys/dev/pci/if_rge.c      Mon Oct 11 15:11:07 2021 +0000
+++ b/sys/dev/pci/if_rge.c      Mon Oct 11 15:11:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_rge.c,v 1.21 2021/10/11 15:11:07 msaitoh Exp $      */
+/*     $NetBSD: if_rge.c,v 1.22 2021/10/11 15:11:49 msaitoh Exp $      */
 /*     $OpenBSD: if_rge.c,v 1.9 2020/12/12 11:48:53 jan Exp $  */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_rge.c,v 1.21 2021/10/11 15:11:07 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_rge.c,v 1.22 2021/10/11 15:11:49 msaitoh Exp $");
 
 #include <sys/types.h>
 
@@ -2077,8 +2077,10 @@
 void
 rge_get_macaddr(struct rge_softc *sc, uint8_t *addr)
 {
-       *(uint32_t *)&addr[0] = RGE_READ_4(sc, RGE_ADDR0);
-       *(uint16_t *)&addr[4] = RGE_READ_2(sc, RGE_ADDR1);
+       int i;
+
+       for (i = 0; i < ETHER_ADDR_LEN; i++)
+               addr[i] = RGE_READ_1(sc, RGE_ADDR0 + i);
 }
 
 void



Home | Main Index | Thread Index | Old Index