Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Fix kernel panic on arm reported by @furandon_pi...



details:   https://anonhg.NetBSD.org/src/rev/4dbc5a390c5e
branches:  trunk
changeset: 447274:4dbc5a390c5e
user:      rin <rin%NetBSD.org@localhost>
date:      Sun Jan 06 00:39:05 2019 +0000

description:
Fix kernel panic on arm reported by @furandon_pig on Twitter.

Hardware header is 2-byte aligned in RX buffer, not 4-byte.
For some architectures, __builtin_memcpy() of GCC 6 attempts to
copy 4-byte header at once, which results in alignment error.

diffstat:

 sys/dev/usb/if_axe.c |  15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diffs (37 lines):

diff -r bb79bec5c3c0 -r 4dbc5a390c5e sys/dev/usb/if_axe.c
--- a/sys/dev/usb/if_axe.c      Sun Jan 06 00:31:35 2019 +0000
+++ b/sys/dev/usb/if_axe.c      Sun Jan 06 00:39:05 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_axe.c,v 1.93 2018/09/12 21:57:18 christos Exp $     */
+/*     $NetBSD: if_axe.c,v 1.94 2019/01/06 00:39:05 rin Exp $  */
 /*     $OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
 
 /*
@@ -87,7 +87,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.93 2018/09/12 21:57:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.94 2019/01/06 00:39:05 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1271,7 +1271,18 @@
                                goto done;
                        }
 
+#if !defined(__NO_STRICT_ALIGNMENT) && __GNUC_PREREQ__(6, 1)
+                       /*
+                        * XXX hdr is 2-byte aligned in buf, not 4-byte.
+                        * For some architectures, __builtin_memcpy() of
+                        * GCC 6 attempts to copy sizeof(hdr) = 4 bytes
+                        * at onece, which results in alignment error.
+                        */
+                       hdr.len = *(uint16_t *)buf;
+                       hdr.ilen = *(uint16_t *)(buf + sizeof(uint16_t));
+#else
                        memcpy(&hdr, buf, sizeof(hdr));
+#endif
 
                        DPRINTFN(20, "total_len %#jx len %jx ilen %#jx",
                            total_len,



Home | Main Index | Thread Index | Old Index