Subject: Re: alignment crash in v6 ipfilter when receiving on gif
To: None <darrenr@netbsd.org>
From: Greg Troxel <gdt@ir.bbn.com>
List: port-sparc64
Date: 07/19/2007 10:30:24
I've committed the change I posted earlier, minus the comment, plus
removing the cast to i6addr_t * in fil.c - it seems unnecessary and is
unsafe from a strict viewpoint.
I'll request a pullup to netbsd-4 later today unless there any
objections.
Index: sys/dist/ipf/netinet/fil.c
===================================================================
RCS file: /cvsroot/src/sys/dist/ipf/netinet/fil.c,v
retrieving revision 1.38
diff -u -p -r1.38 fil.c
--- sys/dist/ipf/netinet/fil.c 24 Jun 2007 22:16:35 -0000 1.38
+++ sys/dist/ipf/netinet/fil.c 18 Jul 2007 16:22:54 -0000
@@ -771,7 +771,7 @@ fr_info_t *fin;
icmp6 = fin->fin_dp;
ip6 = (ip6_t *)((char *)icmp6 + ICMPERR_ICMPHLEN);
if (IP6_NEQ(&fin->fin_fi.fi_dst,
- (i6addr_t *)&ip6->ip6_src))
+ &ip6->ip6_src))
fin->fin_flx |= FI_BAD;
minicmpsz = ICMP6ERR_IPICMPHLEN - sizeof(ip6_t);
Index: sys/dist/ipf/netinet/ip_fil.h
===================================================================
RCS file: /cvsroot/src/sys/dist/ipf/netinet/ip_fil.h,v
retrieving revision 1.13
diff -u -p -r1.13 ip_fil.h
--- sys/dist/ipf/netinet/ip_fil.h 16 Jun 2007 10:52:27 -0000 1.13
+++ sys/dist/ipf/netinet/ip_fil.h 18 Jul 2007 16:22:54 -0000
@@ -158,14 +158,15 @@ typedef union i6addr {
#define iplookupptr vptr[0]
#define iplookupfunc lptr[1]
-#define I60(x) (((i6addr_t *)(x))->i6[0])
-#define I61(x) (((i6addr_t *)(x))->i6[1])
-#define I62(x) (((i6addr_t *)(x))->i6[2])
-#define I63(x) (((i6addr_t *)(x))->i6[3])
-#define HI60(x) ntohl(((i6addr_t *)(x))->i6[0])
-#define HI61(x) ntohl(((i6addr_t *)(x))->i6[1])
-#define HI62(x) ntohl(((i6addr_t *)(x))->i6[2])
-#define HI63(x) ntohl(((i6addr_t *)(x))->i6[3])
+/* Avoid casting to a type presuming 64-bit alignment. */
+#define I60(x) (((u_32_t *)(x))[0])
+#define I61(x) (((u_32_t *)(x))[1])
+#define I62(x) (((u_32_t *)(x))[2])
+#define I63(x) (((u_32_t *)(x))[3])
+#define HI60(x) ntohl(((u_32_t *)(x))[0])
+#define HI61(x) ntohl(((u_32_t *)(x))[1])
+#define HI62(x) ntohl(((u_32_t *)(x))[2])
+#define HI63(x) ntohl(((u_32_t *)(x))[3])
#define IP6_EQ(a,b) ((I63(a) == I63(b)) && (I62(a) == I62(b)) && \
(I61(a) == I61(b)) && (I60(a) == I60(b)))