ip6tables: 32bit userspace doesn't work with 64bit kernel
Subsystems (2)
Hello,
I just found out that 32bit (x86) ip6tables does not work with a 64bit kernel. I'm currenly using 2.6.24-rc4-g94545bad, but the structures involved haven't been touched recently.
Before you read on: I see that IPv6 code is missing compat* stuff, so is this configuration supported?
A simple "ip6tables -L" fails with:
ip6tables v1.3.8: can't initialize ip6tables table `filter': Bad file descriptor
kernel says:get_entries: 892 != 896 (this is do_ip6t_get_ctl)
The problem is that GCC changes the layout of a couple of structures when compiling 64bit code.
Compiler version - in case it started doing this recently - is:
gcc (GCC) 4.2.2 (Debian 4.2.2-1)
This is what userspace (32bit) is using:
sizeof(struct ip6t_entry) = 164
ipv6 0
nfcache 136
target_offset 140
next_offset 142
comefrom 144
counters 148
elems 164
sizeof(struct ip6t_get_entries) = 36
name 0
size 32
entrytable 36sizeof(struct xt_counters) = 16
And this is what the kernel (64bit) expects:
sizeof(struct ip6t_entry) = 168
ipv6 0
nfcache 136
target_offset 140
next_offset 142
comefrom 144
counters 152 <--- ouch
elems 168
sizeof(struct ip6t_get_entries) = 40
name 0
size 32
entrytable 40sizeof(struct xt_counters) = 16
It seems that the compiler - in 64 bit mode - goes for 8 bytes alignment for "counters" (which contains a couple of int64); I guess that ip6t_get_entries is changed to keep the very same field (in entrytable) aligned.
Luca
Signature · 2 lines
The trouble with computers is that they do what you tell them, not what you want.
Quoted 7 lines · Luca Tettamanti
Hello,
I just found out that 32bit (x86) ip6tables does not work with a 64bit kernel. I'm currenly using 2.6.24-rc4-g94545bad, but the structures involved haven't been touched recently.Before you read on: I see that IPv6 code is missing compat* stuff, so is this configuration supported?
Not yet, thanks for pointing this out, I completely forgot about that :) I'll put it on my todo list, with some luck I can still finish it in time for the 2.6.25 merge window.
Quoted 6 lines · Patrick McHardy
Quoted 5 lines · Luca Tettamanti
Hello,
I just found out that 32bit (x86) ip6tables does not work with a 64bit kernel. I'm currenly using 2.6.24-rc4-g94545bad, but the structures involved haven't been touched recently.
Quoted 6 lines
Quoted 2 lines
Before you read on: I see that IPv6 code is missing compat* stuff, so is this configuration supported?
Not yet, thanks for pointing this out, I completely forgot about that :) I'll put it on my todo list, with some luck I can still finish it in time for the 2.6.25 merge window.
Ok, feel free to throw patches this way for testing ;-)
Luca
Quoted 7 lines · Luca Tettamanti
Quoted 6 lines · Patrick McHardy
Quoted 5 lines · Luca Tettamanti
Hello,
I just found out that 32bit (x86) ip6tables does not work with a 64bit kernel. I'm currenly using 2.6.24-rc4-g94545bad, but the structures involved haven't been touched recently.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Before you read on: I see that IPv6 code is missing compat* stuff, so is this configuration supported?
Not yet, thanks for pointing this out, I completely forgot about that :) I'll put it on my todo list, with some luck I can still finish it in time for the 2.6.25 merge window.
Ok, feel free to throw patches this way for testing ;-)
I've completed the compat support, but its about 25 patches - do you want me to start throwing? :) Otherwise just wait for a few days, I'll send them upstream as soon as the iptables compat fix is in net-2.6.25 since they depend on that one.
Quoted 9 lines · Patrick McHardy
Quoted 1 line · Luca Tettamanti
Ok, feel free to throw patches this way for testing ;-)
I've completed the compat support, but its about 25 patches - do you want me to start throwing? :) Otherwise just wait for a few days, I'll send them upstream as soon as the iptables compat fix is in net-2.6.25 since they depend on that one.
I figured out how to tell git to export them all as one big patch, so if you want to do some testing, please go ahead. Might apply to Linus' current -git tree, otherwise please use net-2.6.25.
include/linux/netfilter/x_tables.h | 47 + include/linux/netfilter_arp/arp_tables.h | 17 include/linux/netfilter_ipv4/ip_tables.h | 76 - include/linux/netfilter_ipv6/ip6_tables.h | 73 - net/compat.c | 106 -- net/ipv4/netfilter/ip_tables.c | 321 +++---- net/ipv6/netfilter/ip6_tables.c | 1204 ++++++++++++++++++++++++------ net/netfilter/x_tables.c | 5 net/netfilter/xt_CONNMARK.c | 5 net/netfilter/xt_MARK.c | 15 net/netfilter/xt_connmark.c | 5 net/netfilter/xt_limit.c | 5 net/netfilter/xt_mark.c | 5 13 files changed, 1299 insertions(+), 585 deletions(-)
include/linux/netfilter/x_tables.h +45 -2
@@ -318,6 +318,49 @@ extern void xt_proto_fini(int af);extern struct xt_table_info *xt_alloc_table_info (unsigned int size);extern void xt_free_table_info (struct xt_table_info *info); +/* fn returns 0 to continue iteration */ +#define XT_MATCH_ITERATE(type, e, fn, args...) \ +({ \ + unsigned int __i; \ + int __ret = 0; \ + struct xt_entry_match *__m; \ + \ + for (__i = sizeof(type); \ + __i < (e)->target_offset; \ + __i += __m->u.match_size) { \ + __m = (void *)e + __i; \ + \ + __ret = fn(__m , ## args); \ + if (__ret != 0) \ + break; \ + } \ + __ret; \ +}) + +/* fn returns 0 to continue iteration */ +#define XT_ENTRY_ITERATE_CONTINUE(type, entries, size, n, fn, args...) \ +({ \ + unsigned int __i, __n; \ + int __ret = 0; \ + type *__entry; \ + \ + for (__i = 0, __n = 0; __i < (size); \ + __i += __entry->next_offset, __n++) { \ + __entry = (void *)(entries) + __i; \ + if (__n < n) \ + continue; \ + \ + __ret = fn(__entry , ## args); \ + if (__ret != 0) \ + break; \ + } \ + __ret; \ +}) + +/* fn returns 0 to continue iteration */ +#define XT_ENTRY_ITERATE(type, entries, size, fn, args...) \ + XT_ENTRY_ITERATE_CONTINUE(type, entries, size, 0, fn, args) +#ifdef CONFIG_COMPAT #include <net/compat.h>
@@ -382,8 +425,8 @@ extern void xt_compat_lock(int af);extern void xt_compat_unlock (int af);extern int xt_compat_match_offset (struct xt_match *match); -extern void xt_compat_match_from_user (struct xt_entry_match *m, -void **dstptr,int *size); +extern int xt_compat_match_from_user (struct xt_entry_match *m, +void **dstptr,int *size);extern int xt_compat_match_to_user (struct xt_entry_match *m,void __user **dstptr,int *size);
include/linux/netfilter_arp/arp_tables.h +2 -15
@@ -217,21 +217,8 @@ static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *e }/* fn returns 0 to continue iteration */ -#define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \ -({ \ - unsigned int __i; \ - int __ret = 0; \ - struct arpt_entry *__entry; \ - \ - for (__i = 0; __i < (size); __i += __entry->next_offset) { \ - __entry = (void *)(entries) + __i; \ - \ - __ret = fn(__entry , ## args); \ - if (__ret != 0) \ - break; \ - } \ - __ret; \ -}) +#define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \ + XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args)/* * Main firewall chains definitions and global var's definitions.
include/linux/netfilter_ipv4/ip_tables.h +24 -52
92 lines not on this page · raw message
include/linux/netfilter_ipv6/ip6_tables.h +40 -33
87 lines not on this page · raw message
net/compat.c +0 -106
124 lines not on this page · raw message
net/ipv4/netfilter/ip_tables.c +148 -173
793 lines not on this page · raw message
net/ipv6/netfilter/ip6_tables.c +1002 -202
1,528 lines not on this page · raw message
net/netfilter/x_tables.c +3 -2
@@ -342,8 +342,8 @@ int xt_compat_match_offset(struct xt_match *match) }EXPORT_SYMBOL_GPL (xt_compat_match_offset); -void xt_compat_match_from_user (struct xt_entry_match *m,void **dstptr, -int *size) +int xt_compat_match_from_user (struct xt_entry_match *m,void **dstptr, +int *size) {struct xt_match *match = m->u.kernel.match;struct compat_xt_entry_match *cm = (struct compat_xt_entry_match *)m;
@@ -365,6 +365,7 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr, *size += off; *dstptr += msize; +return 0 ; }EXPORT_SYMBOL_GPL (xt_compat_match_from_user);
net/netfilter/xt_CONNMARK.c +5 -0
@@ -160,6 +160,11 @@ static struct xt_target connmark_tg_reg[] __read_mostly = { .destroy = connmark_tg_destroy, .target = connmark_tg, .targetsize = sizeof(struct xt_connmark_target_info), +#ifdef CONFIG_COMPAT + .compatsize = sizeof(struct compat_xt_connmark_target_info), + .compat_from_user = connmark_tg_compat_from_user, + .compat_to_user = connmark_tg_compat_to_user, +#endif .me =THIS_MODULE }, };
net/netfilter/xt_MARK.c +15 -0
@@ -158,6 +158,21 @@ static struct xt_target mark_tg_reg[] __read_mostly = { .table = "mangle", .me = THIS_MODULE, }, + { + .name = "MARK", + .family = AF_INET6, + .revision = 1, + .checkentry = mark_tg_check, + .target = mark_tg, + .targetsize =sizeof (struct xt_mark_target_info_v1 ), +#ifdef CONFIG_COMPAT + .compatsize =sizeof (struct compat_xt_mark_target_info_v1 ), + .compat_from_user = mark_tg_compat_from_user, + .compat_to_user = mark_tg_compat_to_user, +#endif + .table ="mangle" , + .me = THIS_MODULE, + }, };static int __init mark_tg_init (void )
net/netfilter/xt_connmark.c +5 -0
@@ -126,6 +126,11 @@ static struct xt_match connmark_mt_reg[] __read_mostly = { .match = connmark_mt, .destroy = connmark_mt_destroy, .matchsize = sizeof(struct xt_connmark_info), +#ifdef CONFIG_COMPAT + .compatsize = sizeof(struct compat_xt_connmark_info), + .compat_from_user = connmark_mt_compat_from_user, + .compat_to_user = connmark_mt_compat_to_user, +#endif .me =THIS_MODULE }, };
net/netfilter/xt_limit.c +5 -0
@@ -187,6 +187,11 @@ static struct xt_match limit_mt_reg[] __read_mostly = { .checkentry = limit_mt_check, .match = limit_mt, .matchsize = sizeof(struct xt_rateinfo), +#ifdef CONFIG_COMPAT + .compatsize = sizeof(struct compat_xt_rateinfo), + .compat_from_user = limit_mt_compat_from_user, + .compat_to_user = limit_mt_compat_to_user, +#endif .me = THIS_MODULE, }, };
net/netfilter/xt_mark.c +5 -0
@@ -94,6 +94,11 @@ static struct xt_match mark_mt_reg[] __read_mostly = { .checkentry = mark_mt_check, .match = mark_mt, .matchsize = sizeof(struct xt_mark_info), +#ifdef CONFIG_COMPAT + .compatsize = sizeof(struct compat_xt_mark_info), + .compat_from_user = mark_mt_compat_from_user, + .compat_to_user = mark_mt_compat_to_user, +#endif .me = THIS_MODULE, }, };
Quoted 11 lines · Patrick McHardy
Quoted 8 lines · Patrick McHardy
Quoted 1 line · Luca Tettamanti
Ok, feel free to throw patches this way for testing ;-)
I've completed the compat support, but its about 25 patches - do you want me to start throwing? :) Otherwise just wait for a few days, I'll send them upstream as soon as the iptables compat fix is in net-2.6.25 since they depend on that one.
Quoted 4 lines
I figured out how to tell git to export them all as one big patch, so if you want to do some testing, please go ahead. Might apply to Linus' current -git tree, otherwise please use net-2.6.25.
I'm currently running net-2.6.25 plus the patch (plus trivial mergin):
so far so good :)
thanks,
Luca