[Patch] 64bit unaligned access

Bryan Phillippe bp at darkforest.org
Wed Aug 31 14:11:59 EDT 2011


This patch fixes an unaligned access for IPv6.  On systems with strict alignment requirements, the unaligned access will either result in garbage data or a crash.

Index: /home/bp/P4/UTM-mainline/tps/libnl/3.0/mainline/src/lib/route/link/inet6.c
===================================================================
--- /home/bp/P4/UTM-mainline/tps/libnl/3.0/mainline/src/lib/route/link/inet6.c.orig
+++ /home/bp/P4/UTM-mainline/tps/libnl/3.0/mainline/src/lib/route/link/inet6.c
@@ -70,26 +70,37 @@ static int inet6_parse_protinfo(struct r
 
 	if (tb[IFLA_INET6_CONF])
 		nla_memcpy(&i6->i6_conf, tb[IFLA_INET6_CONF],
 			   sizeof(i6->i6_conf));
 
+	/*
+	 * Due to 32bit data alignment, these addresses must be copied to an
+	 * aligned location prior to access.
+	 */
+
 	if (tb[IFLA_INET6_STATS]) {
-		uint64_t *cnt = nla_data(tb[IFLA_INET6_STATS]);
+		unsigned char *cnt = nla_data(tb[IFLA_INET6_STATS]);
+		uint64_t stat;
 		int i;
 
-		for (i = 1; i < __IPSTATS_MIB_MAX; i++)
+		for (i = 1; i < __IPSTATS_MIB_MAX; i++) {
+			memcpy(&stat, &cnt[i * sizeof(stat)], sizeof(stat));
 			rtnl_link_set_stat(link, RTNL_LINK_IP6_INPKTS + i - 1,
-					   cnt[i]);
+					   stat);
+		}
 	}
 
 	if (tb[IFLA_INET6_ICMP6STATS]) {
-		uint64_t *cnt = nla_data(tb[IFLA_INET6_ICMP6STATS]);
+		unsigned char *cnt = nla_data(tb[IFLA_INET6_ICMP6STATS]);
+		uint64_t stat;
 		int i;
 
-		for (i = 1; i < __ICMP6_MIB_MAX; i++)
+		for (i = 1; i < __ICMP6_MIB_MAX; i++) {
+			memcpy(&stat, &cnt[i * sizeof(stat)], sizeof(stat));
 			rtnl_link_set_stat(link, RTNL_LINK_ICMP6_INMSGS + i - 1,
-					   cnt[i]);
+					   stat);
+		}
 	}
 
 	return 0;
 }

Thanks,
--
-bp

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: libnl.unaligned.patch.txt
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20110831/d7339971/attachment.txt>
-------------- next part --------------




More information about the libnl mailing list