Module Name:    src
Committed By:   msaitoh
Date:           Mon Oct 11 15:11:50 UTC 2021

Modified Files:
        src/sys/dev/pci: if_rge.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/pci/if_rge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_rge.c
diff -u src/sys/dev/pci/if_rge.c:1.21 src/sys/dev/pci/if_rge.c:1.22
--- src/sys/dev/pci/if_rge.c:1.21	Mon Oct 11 15:11:07 2021
+++ src/sys/dev/pci/if_rge.c	Mon Oct 11 15:11:49 2021
@@ -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 @@ rge_set_macaddr(struct rge_softc *sc, co
 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

Reply via email to