Source-Changes-HG archive

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

[src/trunk]: src/sys if_arp: Ensure that arphdr is aligned



details:   https://anonhg.NetBSD.org/src/rev/bdc0f8686c12
branches:  trunk
changeset: 952331:bdc0f8686c12
user:      roy <roy%NetBSD.org@localhost>
date:      Sat Feb 13 07:57:09 2021 +0000

description:
if_arp: Ensure that arphdr is aligned

diffstat:

 sys/net/if_arp.h     |   7 ++++++-
 sys/netinet/if_arp.c |  20 +++++++++++++++-----
 2 files changed, 21 insertions(+), 6 deletions(-)

diffs (62 lines):

diff -r 839c4436dc5d -r bdc0f8686c12 sys/net/if_arp.h
--- a/sys/net/if_arp.h  Sat Feb 13 07:32:19 2021 +0000
+++ b/sys/net/if_arp.h  Sat Feb 13 07:57:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.h,v 1.37 2021/02/03 18:13:13 roy Exp $  */
+/*     $NetBSD: if_arp.h,v 1.38 2021/02/13 07:57:09 roy Exp $  */
 
 /*
  * Copyright (c) 1986, 1993
@@ -72,6 +72,11 @@
        uint8_t  ar_tpa[];      /* target protocol address */
 #endif
 };
+#ifdef __NO_STRICT_ALIGNMENT
+#define        ARP_HDR_ALIGNED_P(ah)   1
+#else
+#define        ARP_HDR_ALIGNED_P(ah)   ((((vaddr_t) (ah)) & 3) == 0)
+#endif
 #ifdef __CTASSERT
 __CTASSERT(sizeof(struct arphdr) == 8);
 #endif
diff -r 839c4436dc5d -r bdc0f8686c12 sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c      Sat Feb 13 07:32:19 2021 +0000
+++ b/sys/netinet/if_arp.c      Sat Feb 13 07:57:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.c,v 1.298 2021/02/02 10:48:33 yamt Exp $        */
+/*     $NetBSD: if_arp.c,v 1.299 2021/02/13 07:57:09 roy Exp $ */
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.298 2021/02/02 10:48:33 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.299 2021/02/13 07:57:09 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -700,9 +700,19 @@
                MCLAIM(m, &arpdomain.dom_mowner);
                ARP_STATINC(ARP_STAT_RCVTOTAL);
 
-               arplen = sizeof(struct arphdr);
-               if (m->m_len < arplen && (m = m_pullup(m, arplen)) == NULL)
-                       goto badlen;
+               /* If the ARP header is not aligned, slurp it up into a new
+                * mbuf with space for link headers, in the event we forward
+                * it.  Otherwise, if it is aligned, make sure the entire
+                * base ARP header is in the first mbuf of the chain.
+                */
+               if (ARP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
+                       if ((m = m_copyup(m, sizeof(*ar),
+                           (max_linkhdr + 3) & ~3)) == NULL)
+                               goto badlen;
+               } else if (__predict_false(m->m_len < sizeof(*ar))) {
+                       if ((m = m_pullup(m, sizeof(*ar))) == NULL)
+                               goto badlen;
+               }
                ar = mtod(m, struct arphdr *);
 
                rcvif = m_get_rcvif(m, &s);



Home | Main Index | Thread Index | Old Index