Skip to contentSkip to conversation

netfilter fix (4/7): fix ip6tables alignment (64bit archs)

PATCH New Harald Welte 1 participant 1 message Jun 24, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter fix (4/7): fix ip6tables alignment (64bit archs)

Hi Dave!

Here goes the fourth...

Author: Jakub Bogusz <[email protected]>

The calculated padding used for alignment in struct ip6t_table_info type definition is wrong. char[SMP_ALIGN((NF_IP6_NUMHOOKS*2+2)*sizeof(unsigned int))] has _its size_ (not end address) aligned to cache line size; also note that there are 3 ints, not 2 before arrays. And if whole ip6t_table_info started on address aligned to 8, entries were placed on address not aligned to 8. On some machines (at least ppc - IBM RS/6000) __alignof__(struct ip6t_entry) is 8 - so loading any ip6table_* module failed with "Bad offset".

Probably padding was meant to be something like
char padding[SMP_ALIGN((NF_IP6_NUMHOOKS*2+3)*sizeof(unsigned int)) -

	((NF_IP6_NUMHOOKS*2+3)*sizeof(unsigned int))]

but it's simpler to use gcc's aligned attribute through ____cacheline_aligned macro (just like in ipt_table_info struct in ip_tables module for ipv4/netfilter).

net/ipv6/netfilter/ip6_tables.c +2 -4
diff -Nru --exclude .depend --exclude '*.o' --exclude '*.ver' --exclude '.*.flags' --exclude '*.orig' --exclude '*.rej' --exclude '*~' linux-2.4.21-32cpu/net/ipv6/netfilter/ip6_tables.c linux-2.4.21-ip6t_alignment/net/ipv6/netfilter/ip6_tables.c
@@ -101,10 +101,8 @@
 	unsigned int hook_entry[NF_IP6_NUMHOOKS];
 	unsigned int underflow[NF_IP6_NUMHOOKS];
 
-	char padding[SMP_ALIGN((NF_IP6_NUMHOOKS*2+2)*sizeof(unsigned int))];
-
 	/* ip6t_entry tables: one per CPU */
-	char entries[0];
+	char entries[0] ____cacheline_aligned;
 };
 
 static LIST_HEAD(ip6t_target);
@@ -1450,7 +1448,7 @@
 	int ret;
 	struct ip6t_table_info *newinfo;
 	static struct ip6t_table_info bootstrap
-		= { 0, 0, 0, { 0 }, { 0 }, { }, { } };
+		= { 0, 0, 0, { 0 }, { 0 }, { } };
 
 	MOD_INC_USE_COUNT;
 	newinfo = vmalloc(sizeof(struct ip6t_table_info)

Please apply, thanks.

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie