Skip to contentSkip to conversation

iptables 32bit compat layer

PATCH In review Mishin Dmitry 7 participants 23 messages Feb 20, 2006 – Mar 29, 2006

Subsystems (7)
Networking netfilter IPv4/IPv6 TCP +3 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 iptables 32bit compat layer

Hello,

This patch set extends current iptables compatibility layer in order to get 32bit iptables to work on 64bit kernel. Current layer is insufficient due to alignment checks both in kernel and user space tools.

This patch introduces base compatibility interface for other ip_tables modules

Signature · 2 lines
Thanks,
Dmitry.
include/linux/netfilter/x_tables.h renamed from include/linux/netfilter/x_tables.h.iptcompat +43 -0
@@ -80,12 +80,19 @@ struct xt_counters_info
 
 #ifdef __KERNEL__
 
+#include <linux/config.h>
 #include <linux/netdevice.h>
 
 #define ASSERT_READ_LOCK(x)
 #define ASSERT_WRITE_LOCK(x)
 #include <linux/netfilter_ipv4/listhelp.h>
 
+#ifdef CONFIG_COMPAT
+#define COMPAT_TO_USER		1
+#define COMPAT_FROM_USER	-1
+#define COMPAT_CALC_SIZE	0
+#endif
+
 struct xt_match
 {
 	struct list_head list;
@@ -118,6 +125,10 @@ struct xt_match
 	/* Called when entry of this type deleted. */
 	void (*destroy)(void *matchinfo, unsigned int matchinfosize);
 
+#ifdef CONFIG_COMPAT
+	/* Called when userspace align differs from kernel space one */
+	int (*compat)(void *match, void **dstptr, int *size, int convert);
+#endif
 	/* Set this to THIS_MODULE if you are a module, otherwise NULL */
 	struct module *me;
 };
@@ -154,6 +165,10 @@ struct xt_target
 	/* Called when entry of this type deleted. */
 	void (*destroy)(void *targinfo, unsigned int targinfosize);
 
+#ifdef CONFIG_COMPAT
+	/* Called when userspace align differs from kernel space one */
+	int (*compat)(void *target, void **dstptr, int *size, int convert);
+#endif
 	/* Set this to THIS_MODULE if you are a module, otherwise NULL */
 	struct module *me;
 };
@@ -233,6 +248,34 @@ 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);
 
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>
+
+/* FIXME: this works only on 32 bit tasks
+ * need to change whole approach in order to calculate align as function of
+ * current task alignment */
+
+struct compat_xt_counters
+{
+	u_int32_t cnt[4];
+};
+
+struct compat_xt_counters_info
+{
+	char name[XT_TABLE_MAXNAMELEN];
+	compat_uint_t num_counters;
+	struct compat_xt_counters counters[0];
+};
+
+#define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \
+		& ~(__alignof__(struct compat_xt_counters)-1))
+
+extern int ipt_match_align_compat(void *match, void **dstptr,
+		int *size, int off, int convert);
+extern int ipt_target_align_compat(void *target, void **dstptr,
+		int *size, int off, int convert);
+
+#endif /* CONFIG_COMPAT */
 #endif /* __KERNEL__ */
 
 #endif /* _X_TABLES_H */
include/linux/netfilter_ipv4/ip_tables.h renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat +58 -0

69 lines not on this page · raw message

include/net/compat.h renamed from include/net/compat.h.iptcompat +8 -0
@@ -23,6 +23,14 @@ struct compat_cmsghdr {
 	compat_int_t	cmsg_type;
 };
 
+#if defined(CONFIG_X86_64)
+#define is_current_32bits() (current_thread_info()->flags & _TIF_IA32)
+#elif defined(CONFIG_IA64)
+#define is_current_32bits() (IS_IA32_PROCESS(ia64_task_regs(current)))
+#else
+#define is_current_32bits()	0
+#endif
+
 #else /* defined(CONFIG_COMPAT) */
 #define compat_msghdr	msghdr		/* to avoid compiler warnings */
 #endif /* defined(CONFIG_COMPAT) */
net/compat.c renamed from net/compat.c.iptcompat +0 -105

117 lines not on this page · raw message

net/ipv4/netfilter/ip_tables.c renamed from net/ipv4/netfilter/ip_tables.c.iptcompat +1097 -129

1,390 lines not on this page · raw message

net/netfilter/xt_tcpudp.c renamed from net/netfilter/xt_tcpudp.c.iptcompat +28 -0
@@ -266,10 +266,35 @@ udp6_checkentry(const char *tablename,
 	return 1;
 }
 
+#ifdef CONFIG_COMPAT
+static int tcp_compat(void *match,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = XT_ALIGN(sizeof(struct xt_tcp)) -
+		COMPAT_XT_ALIGN(sizeof(struct xt_tcp));
+	return ipt_match_align_compat(match, dstptr, size, off, convert);
+}
+
+static int udp_compat(void *match,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = XT_ALIGN(sizeof(struct xt_udp)) -
+		COMPAT_XT_ALIGN(sizeof(struct xt_udp));
+	return ipt_match_align_compat(match, dstptr, size, off, convert);
+}
+#endif
+
 static struct xt_match tcp_matchstruct = {
 	.name		= "tcp",
 	.match		= &tcp_match,
 	.checkentry	= &tcp_checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= &tcp_compat,
+#endif
 	.me		= THIS_MODULE,
 };
 static struct xt_match tcp6_matchstruct = {
@@ -283,6 +308,9 @@ static struct xt_match udp_matchstruct =
 	.name		= "udp",
 	.match		= &udp_match,
 	.checkentry	= &udp_checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= &udp_compat,
+#endif
 	.me		= THIS_MODULE,
 };
 static struct xt_match udp6_matchstruct = {
#1 lore raw

PATCH 2/2 iptables 32bit compat layer

This patch introduces compatibility functions for some ip_tables matches and targets, using interface provided in the first patch.

Quoted 6 lines

Hello,

This patch set extends current iptables compatibility layer in order to get 32bit iptables to work on 64bit kernel. Current layer is insufficient due to alignment checks both in kernel and user space tools.

Signature · 2 lines
Thanks,
Dmitry.
include/linux/netfilter/xt_conntrack.h renamed from include/linux/netfilter/xt_conntrack.h.iptcompat2 +18 -0
@@ -5,6 +5,7 @@
 #ifndef _XT_CONNTRACK_H
 #define _XT_CONNTRACK_H
 
+#include <linux/config.h>
 #include <linux/netfilter/nf_conntrack_tuple_common.h>
 #include <linux/in.h>
 
@@ -60,4 +61,21 @@ struct xt_conntrack_info
 	/* Inverse flags */
 	u_int8_t invflags;
 };
+
+#ifdef CONFIG_COMPAT
+struct compat_xt_conntrack_info
+{
+	compat_uint_t statemask, statusmask;
+
+	struct ip_conntrack_tuple tuple[IP_CT_DIR_MAX];
+	struct in_addr sipmsk[IP_CT_DIR_MAX], dipmsk[IP_CT_DIR_MAX];
+
+	compat_ulong_t expires_min, expires_max;
+
+	/* Flags word */
+	u_int8_t flags;
+	/* Inverse flags */
+	u_int8_t invflags;
+};
+#endif
 #endif /*_XT_CONNTRACK_H*/
include/linux/netfilter/xt_helper.h renamed from include/linux/netfilter/xt_helper.h.iptcompat2 +9 -0
@@ -1,8 +1,17 @@
 #ifndef _XT_HELPER_H
 #define _XT_HELPER_H
 
+#include <linux/config.h>
+
 struct xt_helper_info {
 	int invert;
 	char name[30];
 };
+
+#ifdef CONFIG_COMPAT
+struct compat_xt_helper_info {
+	compat_int_t invert;
+	char name[30];
+};
+#endif
 #endif /* _XT_HELPER_H */
include/linux/netfilter/xt_limit.h renamed from include/linux/netfilter/xt_limit.h.iptcompat2 +17 -0
@@ -1,6 +1,8 @@
 #ifndef _XT_RATE_H
 #define _XT_RATE_H
 
+#include <linux/config.h>
+
 /* timings are in milliseconds. */
 #define XT_LIMIT_SCALE 10000
 
@@ -18,4 +20,19 @@ struct xt_rateinfo {
 	/* Ugly, ugly fucker. */
 	struct xt_rateinfo *master;
 };
+
+#ifdef CONFIG_COMPAT
+struct compat_xt_rateinfo {
+	u_int32_t avg;    /* Average secs between packets * scale */
+	u_int32_t burst;  /* Period multiplier for upper limit. */
+
+	/* Used internally by the kernel */
+	compat_ulong_t prev;
+	u_int32_t credit;
+	u_int32_t credit_cap, cost;
+
+	/* Ugly, ugly fucker. */
+	compat_uptr_t master;
+};
+#endif
 #endif /*_XT_RATE_H*/
include/linux/netfilter/xt_state.h renamed from include/linux/netfilter/xt_state.h.iptcompat2 +9 -0
@@ -1,6 +1,8 @@
 #ifndef _XT_STATE_H
 #define _XT_STATE_H
 
+#include <linux/config.h>
+
 #define XT_STATE_BIT(ctinfo) (1 << ((ctinfo)%IP_CT_IS_REPLY+1))
 #define XT_STATE_INVALID (1 << 0)
 
@@ -10,4 +12,11 @@ struct xt_state_info
 {
 	unsigned int statemask;
 };
+
+#ifdef CONFIG_COMPAT
+struct compat_xt_state_info
+{
+	compat_uint_t statemask;
+};
+#endif
 #endif /*_XT_STATE_H*/
include/linux/netfilter_ipv4/ip_nat.h renamed from include/linux/netfilter_ipv4/ip_nat.h.iptcompat2 +18 -0
@@ -1,5 +1,6 @@
 #ifndef _IP_NAT_H
 #define _IP_NAT_H
+#include <linux/config.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
 
@@ -76,6 +77,23 @@ extern int ip_nat_used_tuple(const struc
 extern u_int16_t ip_nat_cheat_check(u_int32_t oldvalinv,
 				    u_int32_t newval,
 				    u_int16_t oldcheck);
+
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>
+
+struct compat_ip_nat_range
+{
+	compat_uint_t flags;
+	u_int32_t min_ip, max_ip;
+	union ip_conntrack_manip_proto min, max;
+};
+
+struct compat_ip_nat_multi_range
+{
+	compat_uint_t rangesize;
+	struct compat_ip_nat_range range[1];
+};
+#endif
 #else  /* !__KERNEL__: iptables wants this to compile. */
 #define ip_nat_multi_range ip_nat_multi_range_compat
 #endif /*__KERNEL__*/
net/ipv4/netfilter/ip_nat_rule.c renamed from net/ipv4/netfilter/ip_nat_rule.c.iptcompat2 +93 -0

111 lines not on this page · raw message

net/ipv4/netfilter/ipt_LOG.c renamed from net/ipv4/netfilter/ipt_LOG.c.iptcompat2 +15 -0
@@ -458,10 +458,25 @@ static int ipt_log_checkentry(const char
 	return 1;
 }
 
+#ifdef CONFIG_COMPAT
+static int ipt_log_compat(void *target,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = IPT_ALIGN(sizeof(struct ipt_log_info)) -
+		COMPAT_IPT_ALIGN(sizeof(struct ipt_log_info));
+	return ipt_target_align_compat(target, dstptr, size, off, convert);
+}
+#endif
+
 static struct ipt_target ipt_log_reg = {
 	.name		= "LOG",
 	.target		= ipt_log_target,
 	.checkentry	= ipt_log_checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= ipt_log_compat,
+#endif
 	.me		= THIS_MODULE,
 };
 
net/ipv4/netfilter/ipt_REJECT.c renamed from net/ipv4/netfilter/ipt_REJECT.c.iptcompat2 +15 -0
@@ -322,10 +322,25 @@ static int check(const char *tablename,
 	return 1;
 }
 
+#ifdef CONFIG_COMPAT
+static int compat(void *target,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = IPT_ALIGN(sizeof(struct ipt_reject_info)) -
+		COMPAT_IPT_ALIGN(sizeof(struct ipt_reject_info));
+	return ipt_target_align_compat(target, dstptr, size, off, convert);
+}
+#endif
+
 static struct ipt_target ipt_reject_reg = {
 	.name		= "REJECT",
 	.target		= reject,
 	.checkentry	= check,
+#ifdef CONFIG_COMPAT
+	.compat		= compat,
+#endif
 	.me		= THIS_MODULE,
 };
 
net/ipv4/netfilter/ipt_TCPMSS.c renamed from net/ipv4/netfilter/ipt_TCPMSS.c.iptcompat2 +15 -0
@@ -242,10 +242,25 @@ ipt_tcpmss_checkentry(const char *tablen
 	return 0;
 }
 
+#ifdef CONFIG_COMPAT
+static int ipt_tcpmss_compat(void *target,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = IPT_ALIGN(sizeof(struct ipt_tcpmss_info)) -
+		COMPAT_IPT_ALIGN(sizeof(struct ipt_tcpmss_info));
+	return ipt_target_align_compat(target, dstptr, size, off, convert);
+}
+#endif
+
 static struct ipt_target ipt_tcpmss_reg = {
 	.name		= "TCPMSS",
 	.target		= ipt_tcpmss_target,
 	.checkentry	= ipt_tcpmss_checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= ipt_tcpmss_compat,
+#endif
 	.me		= THIS_MODULE,
 };
 
net/ipv4/netfilter/ipt_TOS.c renamed from net/ipv4/netfilter/ipt_TOS.c.iptcompat2 +15 -0
@@ -83,10 +83,25 @@ checkentry(const char *tablename,
 	return 1;
 }
 
+#ifdef CONFIG_COMPAT
+static int compat(void *target,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = IPT_ALIGN(sizeof(struct ipt_tos_target_info)) -
+		COMPAT_IPT_ALIGN(sizeof(struct ipt_tos_target_info));
+	return ipt_target_align_compat(target, dstptr, size, off, convert);
+}
+#endif
+
 static struct ipt_target ipt_tos_reg = {
 	.name		= "TOS",
 	.target		= target,
 	.checkentry	= checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= compat,
+#endif
 	.me		= THIS_MODULE,
 };
 
net/ipv4/netfilter/ipt_multiport.c renamed from net/ipv4/netfilter/ipt_multiport.c.iptcompat2 +28 -0
@@ -174,11 +174,36 @@ checkentry_v1(const char *tablename,
 	return (matchsize == IPT_ALIGN(sizeof(struct ipt_multiport_v1)));
 }
 
+#ifdef CONFIG_COMPAT
+static int compat(void *match,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = IPT_ALIGN(sizeof(struct ipt_multiport)) -
+		COMPAT_IPT_ALIGN(sizeof(struct ipt_multiport));
+	return ipt_match_align_compat(match, dstptr, size, off, convert);
+}
+
+static int compat_v1(void *match,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = IPT_ALIGN(sizeof(struct ipt_multiport_v1)) -
+		COMPAT_IPT_ALIGN(sizeof(struct ipt_multiport_v1));
+	return ipt_match_align_compat(match, dstptr, size, off, convert);
+}
+#endif
+
 static struct ipt_match multiport_match = {
 	.name		= "multiport",
 	.revision	= 0,
 	.match		= &match,
 	.checkentry	= &checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= &compat,
+#endif
 	.me		= THIS_MODULE,
 };
 
@@ -187,6 +212,9 @@ static struct ipt_match multiport_match_
 	.revision	= 1,
 	.match		= &match_v1,
 	.checkentry	= &checkentry_v1,
+#ifdef CONFIG_COMPAT
+	.compat		= &compat_v1,
+#endif
 	.me		= THIS_MODULE,
 };
 
net/ipv4/netfilter/ipt_tos.c renamed from net/ipv4/netfilter/ipt_tos.c.iptcompat2 +15 -0
@@ -44,10 +44,25 @@ checkentry(const char *tablename,
 	return 1;
 }
 
+#ifdef CONFIG_COMPAT
+static int compat(void *match,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = IPT_ALIGN(sizeof(struct ipt_tos_info)) -
+		COMPAT_IPT_ALIGN(sizeof(struct ipt_tos_info));
+	return ipt_match_align_compat(match, dstptr, size, off, convert);
+}
+#endif
+
 static struct ipt_match tos_match = {
 	.name		= "tos",
 	.match		= &match,
 	.checkentry	= &checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= &compat,
+#endif
 	.me		= THIS_MODULE,
 };
 
net/ipv4/netfilter/ipt_ttl.c renamed from net/ipv4/netfilter/ipt_ttl.c.iptcompat2 +15 -0
@@ -57,10 +57,25 @@ static int checkentry(const char *tablen
 	return 1;
 }
 
+#ifdef CONFIG_COMPAT
+static int compat(void *match,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = IPT_ALIGN(sizeof(struct ipt_ttl_info)) -
+		COMPAT_IPT_ALIGN(sizeof(struct ipt_ttl_info));
+	return ipt_match_align_compat(match, dstptr, size, off, convert);
+}
+#endif
+
 static struct ipt_match ttl_match = {
 	.name		= "ttl",
 	.match		= &match,
 	.checkentry	= &checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= &compat,
+#endif
 	.me		= THIS_MODULE,
 };
 
net/netfilter/xt_conntrack.c renamed from net/netfilter/xt_conntrack.c.iptcompat2 +103 -0

119 lines not on this page · raw message

net/netfilter/xt_helper.c renamed from net/netfilter/xt_helper.c.iptcompat2 +86 -0

108 lines not on this page · raw message

net/netfilter/xt_length.c renamed from net/netfilter/xt_length.c.iptcompat2 +18 -0
@@ -63,16 +63,34 @@ checkentry(const char *tablename,
 	return 1;
 }
 
+#ifdef CONFIG_COMPAT
+static int compat(void *match,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = XT_ALIGN(sizeof(struct xt_length_info)) -
+		COMPAT_XT_ALIGN(sizeof(struct xt_length_info));
+	return ipt_match_align_compat(match, dstptr, size, off, convert);
+}
+#endif
+
 static struct xt_match length_match = {
 	.name		= "length",
 	.match		= &match,
 	.checkentry	= &checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= &compat,
+#endif
 	.me		= THIS_MODULE,
 };
 static struct xt_match length6_match = {
 	.name		= "length",
 	.match		= &match6,
 	.checkentry	= &checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= &compat,
+#endif
 	.me		= THIS_MODULE,
 };
 
net/netfilter/xt_limit.c renamed from net/netfilter/xt_limit.c.iptcompat2 +89 -0

111 lines not on this page · raw message

net/netfilter/xt_state.c renamed from net/netfilter/xt_state.c.iptcompat2 +84 -0

106 lines not on this page · raw message

net/netfilter/xt_tcpmss.c renamed from net/netfilter/xt_tcpmss.c.iptcompat2 +18 -0
@@ -133,10 +133,25 @@ checkentry6(const char *tablename,
 	return 1;
 }
 
+#ifdef CONFIG_COMPAT
+static int compat(void *match,
+		void **dstptr, int *size, int convert)
+{
+	int off;
+
+	off = XT_ALIGN(sizeof(struct xt_tcpmss_match_info)) -
+		COMPAT_XT_ALIGN(sizeof(struct xt_tcpmss_match_info));
+	return ipt_match_align_compat(match, dstptr, size, off, convert);
+}
+#endif
+
 static struct xt_match tcpmss_match = {
 	.name		= "tcpmss",
 	.match		= &match,
 	.checkentry	= &checkentry,
+#ifdef CONFIG_COMPAT
+	.compat		= &compat,
+#endif
 	.me		= THIS_MODULE,
 };
 
@@ -144,6 +159,9 @@ static struct xt_match tcpmss6_match = {
 	.name		= "tcpmss",
 	.match		= &match,
 	.checkentry	= &checkentry6,
+#ifdef CONFIG_COMPAT
+	.compat		= &compat,
+#endif
 	.me		= THIS_MODULE,
 };
 
maintainer
#2 lore raw
In reply to Mishin Dmitry

From: Mishin Dmitry <[email protected]>
Date: Mon, 20 Feb 2006 11:10:38 +0300

Quoted 4 lines

This patch set extends current iptables compatibility layer in order to get 32bit iptables to work on 64bit kernel. Current layer is insufficient due to alignment checks both in kernel and user space tools.

Thanks a lot for doing this work Mishin.

#3 lore raw
In reply to Mishin Dmitry
Quoted 13 lines · Mishin Dmitry
include/linux/netfilter/x_tables.h        2006-02-15 18:53:09.000000000 +0300 renamed from include/linux/netfilter/x_tables.h.iptcompat      2006-02-15 16:16:02.000000000 +0300 +0 -0

 struct xt_match
 {
        struct list_head list;

include/linux/netfilter/x_tables.h        2006-02-15 18:53:09.000000000 +0300 renamed from include/linux/netfilter/x_tables.h.iptcompat      2006-02-15 16:16:02.000000000 +0300 +0 -0
@@ -118,6 +125,10 @@ struct xt_match
         /* Called when entry of this type deleted. */
         void (*destroy)(void *matchinfo, unsigned int matchinfosize);

include/linux/netfilter/x_tables.h        2006-02-15 18:53:09.000000000 +0300 renamed from include/linux/netfilter/x_tables.h.iptcompat      2006-02-15 16:16:02.000000000 +0300 +4 -0
+#ifdef CONFIG_COMPAT
+       /* Called when userspace align differs from kernel space one */
+       int (*compat)(void *match, void **dstptr, int *size, int convert);
+#endif
Quoted 3 lines

        /* Set this to THIS_MODULE if you are a module, otherwise NULL */ struct module *me;
 };

Is CONFIG_COMPAT the right conditional here? If the code is only used for architectures that have different aligments, it should not need be compiled in for the other architectures.

Quoted 16 lines
include/linux/netfilter/x_tables.h        2006-02-15 18:53:09.000000000 +0300 renamed from include/linux/netfilter/x_tables.h.iptcompat      2006-02-15 16:16:02.000000000 +0300 +0 -0
@@ -154,6 +165,10 @@ struct xt_target
         /* Called when entry of this type deleted. */
         void (*destroy)(void *targinfo, unsigned int targinfosize);

include/linux/netfilter/x_tables.h        2006-02-15 18:53:09.000000000 +0300 renamed from include/linux/netfilter/x_tables.h.iptcompat      2006-02-15 16:16:02.000000000 +0300 +4 -0
+#ifdef CONFIG_COMPAT
+       /* Called when userspace align differs from kernel space one */
+       int (*compat)(void *target, void **dstptr, int *size, int convert);
+#endif

        /* Set this to THIS_MODULE if you are a module, otherwise NULL */ struct module *me;
 };

include/linux/netfilter/x_tables.h        2006-02-15 18:53:09.000000000 +0300 renamed from include/linux/netfilter/x_tables.h.iptcompat      2006-02-15 16:16:02.000000000 +0300 +0 -0
@@ -233,6 +248,34 @@ 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);

include/linux/netfilter/x_tables.h        2006-02-15 18:53:09.000000000 +0300 renamed from include/linux/netfilter/x_tables.h.iptcompat      2006-02-15 16:16:02.000000000 +0300 +1 -0
+#ifdef CONFIG_COMPAT

include/linux/netfilter/x_tables.h        2006-02-15 18:53:09.000000000 +0300

Quoted 10 lines
include/linux/netfilter/x_tables.h        2006-02-15 18:53:09.000000000 +0300 renamed from include/linux/netfilter/x_tables.h.iptcompat      2006-02-15 16:16:02.000000000 +0300 +10 -0
+#include <net/compat.h>
+
+/* FIXME: this works only on 32 bit tasks
+ * need to change whole approach in order to calculate align as function of
+ * current task alignment */
+
+struct compat_xt_counters
+{
+       u_int32_t cnt[4];
+};

Hmm, maybe we should have something like

typedef u64 __attribute__((aligned(4))) compat_u64;

in order to get the right alignment on the architectures where it makes a difference. Do all compiler versions get that right?

Quoted 9 lines
include/linux/netfilter_ipv4/ip_tables.h  2006-02-15 16:37:12.000000000 +0300 renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat        2006-02-15 16:06:41.000000000 +0300 +0 -0
@@ -364,5 +365,62 @@ extern unsigned int ipt_do_table(struct 
                                  void *userdata);


 #define IPT_ALIGN(s) XT_ALIGN(s)

include/linux/netfilter_ipv4/ip_tables.h  2006-02-15 16:37:12.000000000 +0300 renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat        2006-02-15 16:06:41.000000000 +0300 +3 -0
+
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>

include/linux/netfilter_ipv4/ip_tables.h  2006-02-15 16:37:12.000000000 +0300

Quoted 10 lines
include/linux/netfilter_ipv4/ip_tables.h  2006-02-15 16:37:12.000000000 +0300 renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat        2006-02-15 16:06:41.000000000 +0300 +10 -0
+
+struct compat_ipt_getinfo
+{
+       char name[IPT_TABLE_MAXNAMELEN];
+       compat_uint_t valid_hooks;
+       compat_uint_t hook_entry[NF_IP_NUMHOOKS];
+       compat_uint_t underflow[NF_IP_NUMHOOKS];
+       compat_uint_t num_entries;
+       compat_uint_t size;
+};

This structure looks like it does not need any
conversions. You should probably just use
struct ipt_getinfo then.

Quoted 14 lines
include/linux/netfilter_ipv4/ip_tables.h  2006-02-15 16:37:12.000000000 +0300 renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat        2006-02-15 16:06:41.000000000 +0300 +14 -0
+
+struct compat_ipt_entry_match
+{
+       union {
+               struct {
+                       u_int16_t match_size;
+                       char name[IPT_FUNCTION_MAXNAMELEN];
+               } user;
+               u_int16_t match_size;
+       } u;
+       unsigned char data[0];
+};
+
+struct compat_ipt_entry_target

include/linux/netfilter_ipv4/ip_tables.h  2006-02-15 16:37:12.000000000 +0300

Quoted 10 lines
include/linux/netfilter_ipv4/ip_tables.h  2006-02-15 16:37:12.000000000 +0300 renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat        2006-02-15 16:06:41.000000000 +0300 +10 -0
+{
+       union {
+               struct {
+                       u_int16_t target_size;
+                       char name[IPT_FUNCTION_MAXNAMELEN];
+               } user;
+               u_int16_t target_size;
+       } u;
+       unsigned char data[0];
+};

Dito

Quoted 16 lines
include/linux/netfilter_ipv4/ip_tables.h  2006-02-15 16:37:12.000000000 +0300 renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat        2006-02-15 16:06:41.000000000 +0300 +8 -0
+#define COMPAT_IPT_ALIGN(s)    COMPAT_XT_ALIGN(s)
+
+extern int ipt_match_align_compat(void *match, void **dstptr,
+               int *size, int off, int convert);
+extern int ipt_target_align_compat(void *target, void **dstptr,
+               int *size, int off, int convert);
+
+#endif /* CONFIG_COMPAT */

 #endif /*__KERNEL__*/
 #endif /* _IPTABLES_H */

include/net/compat.h      2006-02-15 18:45:49.000000000 +0300 renamed from include/net/compat.h.iptcompat    2006-01-03 06:21:10.000000000 +0300 +0 -0
@@ -23,6 +23,14 @@ struct compat_cmsghdr {
         compat_int_t    cmsg_type;
  };

include/net/compat.h      2006-02-15 18:45:49.000000000 +0300

Quoted 8 lines
include/net/compat.h      2006-02-15 18:45:49.000000000 +0300 renamed from include/net/compat.h.iptcompat    2006-01-03 06:21:10.000000000 +0300 +8 -0
+#if defined(CONFIG_X86_64)
+#define is_current_32bits() (current_thread_info()->flags & _TIF_IA32)
+#elif defined(CONFIG_IA64)
+#define is_current_32bits() (IS_IA32_PROCESS(ia64_task_regs(current)))
+#else
+#define is_current_32bits()    0
+#endif
+

This definition looks very wrong to me. For x86_64, the right thing to check should be TS_COMPAT, no _TIF_IA32, since you can also call the 64 bit syscall entry point from a i386 task running on x86_64. For most other architectures, is_current_32bits returns something that is not reflected in the name. I would e.g. expect the function to return '1' on i386 and the correct task state on other compat platforms, instead of a bogus '0'.

There have been long discussions about the inclusions of the 'is_compat_task' macro. Let's at least not define a second function that does almost the same but gets it wrong.

I would much rather have either an extra 'compat' argument to to sock_setsockopt and proto_ops->setsockopt than to spread the use of is_compat_task further.

Quoted 13 lines

 #else /* defined(CONFIG_COMPAT) */
 #define compat_msghdr  msghdr          /* to avoid compiler warnings */ #endif /* defined(CONFIG_COMPAT) */

net/compat.c      2006-02-15 16:38:45.000000000 +0300 renamed from net/compat.c.iptcompat    2006-01-03 06:21:10.000000000 +0300 +0 -0
@@ -308,107 +308,6 @@ void scm_detach_fds_compat(struct msghdr
  }


 /*
- * For now, we assume that the compatibility and native version
- * of struct ipt_entry are the same - sfr.  FIXME
- */

net/compat.c      2006-02-15 16:38:45.000000000 +0300 renamed from net/compat.c.iptcompat    2006-01-03 06:21:10.000000000 +0300 +0 -1
-struct compat_ipt_replace {

net/compat.c      2006-02-15 16:38:45.000000000 +0300

Quoted 10 lines
net/compat.c      2006-02-15 16:38:45.000000000 +0300 renamed from net/compat.c.iptcompat    2006-01-03 06:21:10.000000000 +0300 +0 -10
-       char                    name[IPT_TABLE_MAXNAMELEN];
-       u32                     valid_hooks;
-       u32                     num_entries;
-       u32                     size;
-       u32                     hook_entry[NF_IP_NUMHOOKS];
-       u32                     underflow[NF_IP_NUMHOOKS];
-       u32                     num_counters;
-       compat_uptr_t           counters;       /* struct ipt_counters * */
-       struct ipt_entry        entries[0];
-};

Is the FIXME above the only reason that the code needs to be changed? What is the reason that you did not just address this in the compat_sys_setsockopt implementation?

	Arnd <><
#12 lore raw
In reply to Mishin Dmitry
Quoted 7 lines · Mishin Dmitry

Hello,

This patch set extends current iptables compatibility layer in order to get 32bit iptables to work on 64bit kernel. Current layer is insufficient due to alignment checks both in kernel and user space tools.

This patch introduces base compatibility interface for other ip_tables modules

Nice. But some issues with the implementation

+#if defined(CONFIG_X86_64)
+#define is_current_32bits() (current_thread_info()->flags & _TIF_IA32)

This should be is_compat_task(). And we don't do such ifdefs in generic code. And what you actually need here is a is_compat_task_with_funny_u64_alignment() (better name sought)

So I would suggest you add macros for that to the ia64 and x86-64 asm/compat.hs and perhaps a ARCH_HAS_FUNNY_U64_ALIGNMENT #define in there.

+ ret = 0;
+ switch (convert) {
+ case COMPAT_TO_USER:
+ pt = (struct ipt_entry_target *)target;

etc. that looks ugly. why can't you just define different functions for that? We don't really need in kernel ioctl

+#ifdef CONFIG_COMPAT
+ down(&compat_ipt_mutex);
+#endif

Why does it need an own lock?

Overall the implementation looks very complicated. Are you sure it wasn't possible to do this simpler?

-Andi

#4 lore raw
In reply to Arnd Bergmann
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · Mishin Dmitry

--- ./include/linux/netfilter/x_tables.h.iptcompat      2006-02-15 16:16:02.000000000 +0300 +++ ./include/linux/netfilter/x_tables.h        2006-02-15 18:53:09.000000000 +0300 struct xt_match
 {
        struct list_head list;

include/linux/netfilter/x_tables.h renamed from include/linux/netfilter/x_tables.h.iptcompat +0 -0
@@ -118,6 +125,10 @@ struct xt_match
         /* Called when entry of this type deleted. */
         void (*destroy)(void *matchinfo, unsigned int matchinfosize);


+#ifdef CONFIG_COMPAT
+       /* Called when userspace align differs from kernel space one */ +       int (*compat)(void *match, void **dstptr, int *size, int

Quoted 8 lines
Quoted 4 lines

convert); +#endif
        /* Set this to THIS_MODULE if you are a module, otherwise NULL */ struct module *me;
 };

Is CONFIG_COMPAT the right conditional here? If the code is only used for architectures that have different aligments, it should not need be compiled in for the other architectures.

So, I'll define ARCH_HAS_FUNNY_64_ALIGNMENT in x86_64 and ia64 code and will check it, as Andi suggested.

Quoted 30 lines
Quoted 22 lines
include/linux/netfilter/x_tables.h renamed from include/linux/netfilter/x_tables.h.iptcompat +0 -0
@@ -154,6 +165,10 @@ struct xt_target
         /* Called when entry of this type deleted. */
         void (*destroy)(void *targinfo, unsigned int targinfosize);


+#ifdef CONFIG_COMPAT
+       /* Called when userspace align differs from kernel space one */ +       int (*compat)(void *target, void **dstptr, int *size, int convert); +#endif
        /* Set this to THIS_MODULE if you are a module, otherwise NULL */ struct module *me;
 };

include/linux/netfilter/x_tables.h renamed from include/linux/netfilter/x_tables.h.iptcompat +0 -0
@@ -233,6 +248,34 @@ 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);

include/linux/netfilter/x_tables.h renamed from include/linux/netfilter/x_tables.h.iptcompat +5 -0
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>
+
+/* FIXME: this works only on 32 bit tasks
+ * need to change whole approach in order to calculate align as function

of + * current task alignment */

include/linux/netfilter/x_tables.h extern void xt_proto_fini(int af); · line 261

Quoted 5 lines
include/linux/netfilter/x_tables.h renamed from include/linux/netfilter/x_tables.h.iptcompat +5 -0
+
+struct compat_xt_counters
+{
+       u_int32_t cnt[4];
+};

Hmm, maybe we should have something like

Quoted 5 lines

typedef u64 __attribute__((aligned(4))) compat_u64;

in order to get the right alignment on the architectures where it makes a difference. Do all compiler versions get that right?

good point. I don't know this and that's why tried to avoid use of 'aligned' attribute.

Quoted 18 lines
Quoted 18 lines

---
./include/linux/netfilter_ipv4/ip_tables.h.iptcompat        2006-02-15 16:06:41.000000000 +0300 +++ ./include/linux/netfilter_ipv4/ip_tables.h  2006-02-15 16:37:12.000000000 +0300 @@ -364,5 +365,62 @@ extern unsigned int ipt_do_table(struct void *userdata);

 #define IPT_ALIGN(s) XT_ALIGN(s)

include/linux/netfilter_ipv4/ip_tables.h renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat +9 -0
+
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>
+
+struct compat_ipt_getinfo
+{
+       char name[IPT_TABLE_MAXNAMELEN];
+       compat_uint_t valid_hooks;
+       compat_uint_t hook_entry[NF_IP_NUMHOOKS];
Quoted 8 lines
Quoted 4 lines

+       compat_uint_t underflow[NF_IP_NUMHOOKS];
+       compat_uint_t num_entries;
+       compat_uint_t size;
+};

This structure looks like it does not need any
conversions. You should probably just use
struct ipt_getinfo then.

I just saw compat_uint_t use in net/compat.c and thought, that it is a good style to use it. Does anybody know arch, where sizeof(compat_uint_t) != 4?

Quoted 19 lines
Quoted 19 lines
include/linux/netfilter_ipv4/ip_tables.h renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat +18 -0
+
+struct compat_ipt_entry_match
+{
+       union {
+               struct {
+                       u_int16_t match_size;
+                       char name[IPT_FUNCTION_MAXNAMELEN];
+               } user;
+               u_int16_t match_size;
+       } u;
+       unsigned char data[0];
+};
+
+struct compat_ipt_entry_target
+{
+       union {
+               struct {
+                       u_int16_t target_size;
Quoted 8 lines
Quoted 6 lines

+                       char name[IPT_FUNCTION_MAXNAMELEN]; +               } user;
+               u_int16_t target_size;
+       } u;
+       unsigned char data[0];
+};

Dito

Disagree, ipt_entry_match and ipt_entry_target contain pointers which make their alignment equal 8 byte on 64bits architectures.

Quoted 33 lines
Quoted 17 lines
include/linux/netfilter_ipv4/ip_tables.h renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat +8 -0
+#define COMPAT_IPT_ALIGN(s)    COMPAT_XT_ALIGN(s)
+
+extern int ipt_match_align_compat(void *match, void **dstptr,
+               int *size, int off, int convert);
+extern int ipt_target_align_compat(void *target, void **dstptr,
+               int *size, int off, int convert);
+
+#endif /* CONFIG_COMPAT */

 #endif /*__KERNEL__*/
 #endif /* _IPTABLES_H */
--- ./include/net/compat.h.iptcompat    2006-01-03 06:21:10.000000000 +0300 +++ ./include/net/compat.h      2006-02-15 18:45:49.000000000 +0300

include/net/compat.h renamed from include/net/compat.h.iptcompat +0 -0
@@ -23,6 +23,14 @@ struct compat_cmsghdr {
         compat_int_t    cmsg_type;
  };

include/net/compat.h struct compat_cmsghdr { · line 33

Quoted 8 lines
include/net/compat.h renamed from include/net/compat.h.iptcompat +8 -0
+#if defined(CONFIG_X86_64)
+#define is_current_32bits() (current_thread_info()->flags & _TIF_IA32)
+#elif defined(CONFIG_IA64)
+#define is_current_32bits() (IS_IA32_PROCESS(ia64_task_regs(current)))
+#else
+#define is_current_32bits()    0
+#endif
+

This definition looks very wrong to me. For x86_64, the right thing to check should be TS_COMPAT, no _TIF_IA32, since you can also call the 64 bit syscall entry point from a i386 task running on x86_64. For most other architectures, is_current_32bits returns something that is not reflected in the name. I would e.g. expect the function to return '1' on i386 and the correct task state on other compat platforms, instead of a bogus '0'.

Quoted 7 lines

There have been long discussions about the inclusions of the 'is_compat_task' macro. Let's at least not define a second function that does almost the same but gets it wrong.

I would much rather have either an extra 'compat' argument to to sock_setsockopt and proto_ops->setsockopt than to spread the use of is_compat_task further.

Another weak place in my code. is_compat_task() approach has one advantage - it doesn't require a lot of current code modifications.

Quoted 20 lines
Quoted 20 lines

 #else /* defined(CONFIG_COMPAT) */
 #define compat_msghdr  msghdr          /* to avoid compiler warnings */ #endif /* defined(CONFIG_COMPAT) */

net/compat.c      2006-02-15 16:38:45.000000000 +0300 renamed from net/compat.c.iptcompat    2006-01-03 06:21:10.000000000 +0300 +0 -0
@@ -308,107 +308,6 @@ void scm_detach_fds_compat(struct msghdr
  }


 /*
- * For now, we assume that the compatibility and native version
- * of struct ipt_entry are the same - sfr.  FIXME
- */
-struct compat_ipt_replace {
-       char                    name[IPT_TABLE_MAXNAMELEN]; -       u32                     valid_hooks;
-       u32                     num_entries;
-       u32                     size;
-       u32                     hook_entry[NF_IP_NUMHOOKS]; -       u32                     underflow[NF_IP_NUMHOOKS];

Quoted 8 lines
Quoted 4 lines

-       u32                     num_counters;
-       compat_uptr_t           counters;       /* struct ipt_counters * */ -       struct ipt_entry        entries[0];
-};

Is the FIXME above the only reason that the code needs to be changed? What is the reason that you did not just address this in the compat_sys_setsockopt implementation?

Code above doesn't work. iptables with version >= 1.3 does alignment checks as well as kernel does. So, we can't simply put entries with 8 bytes alignment to userspace or with 4 bytes alignment to kernel - we need translate them entry by entry. So, I tried to do this the most correct way - that userspace will hide its alignment from kernel and vice versa, with not only SET_REPLACE, but also GET_INFO, GET_ENTRIES and SET_COUNTERS translation. First implementation was exactly in compat_sys_setsockopt, but David asked me to do this in netfilter code itself.

Quoted 7 lines
	Arnd <><

_______________________________________________
Devel mailing list
[email protected]
https://openvz.org/mailman/listinfo/devel

Signature · 2 lines
Thanks,
Dmitry.
#13 lore raw
In reply to Andi Kleen
Quoted 16 lines · Andi Kleen
Quoted 8 lines · Mishin Dmitry

Hello,

This patch set extends current iptables compatibility layer in order to get 32bit iptables to work on 64bit kernel. Current layer is insufficient due to alignment checks both in kernel and user space tools.

This patch introduces base compatibility interface for other ip_tables modules

Nice. But some issues with the implementation

include/net/compat.h renamed from include/net/compat.h.iptcompat +2 -0
+#if defined(CONFIG_X86_64)
+#define is_current_32bits() (current_thread_info()->flags & _TIF_IA32)
Quoted 6 lines

This should be is_compat_task(). And we don't do such ifdefs in generic code. And what you actually need here is a is_compat_task_with_funny_u64_alignment() (better name sought)

So I would suggest you add macros for that to the ia64 and x86-64 asm/compat.hs and perhaps a ARCH_HAS_FUNNY_U64_ALIGNMENT #define in there.

agree.

Quoted 8 lines
net/ipv4/netfilter/ip_tables.c renamed from net/ipv4/netfilter/ip_tables.c.iptcompat +4 -0
+	ret = 0;
+	switch (convert) {
+		case COMPAT_TO_USER:
+			pt = (struct ipt_entry_target *)target;

etc. that looks ugly. why can't you just define different functions for that? We don't really need in kernel ioctl

3 functions and the requirement that if defined one, than defined all of them?

Quoted 6 lines
net/ipv4/netfilter/ip_tables.c renamed from net/ipv4/netfilter/ip_tables.c.iptcompat +3 -0
+#ifdef CONFIG_COMPAT
+	down(&compat_ipt_mutex);
+#endif

Why does it need an own lock?

Because it protects only compatibility translation. We spend a lot of time in these cycles and I don't think that it is a good way to hold ipt_mutex for this. The only reason of this lock is offset list - in the first iteration I fill it, in the second - use it. If you know how to implement this better, let me know.

Quoted 3 lines

Overall the implementation looks very complicated. Are you sure it wasn't possible to do this simpler?

ughh...
I don't like this code as well. But seems that it is due to iptables code itself, which was designed with no thoughts about compatibility in minds.

So, I see following approaches:
1) do translation before pass data to original do_replace or get_entries. Disadvantage of such approach is additional 2 cycles through data.
2) do translation in compat_do_replace and compat_get_entries. Avoidance of additional cycles, but some code duplication.
3) remove alignment checks in kernel - than we need only first time translation from kernel to user. But such code will not work with both 32bit and 64 bit iptables at the same time.

Any suggestions?

Quoted 8 lines

-Andi

_______________________________________________
Devel mailing list
[email protected]
https://openvz.org/mailman/listinfo/devel

Signature · 2 lines
Thanks,
Dmitry.
#5 lore raw
In reply to Dmitry Mishin
Quoted 8 lines · Dmitry Mishin
Quoted 3 lines · Arnd Bergmann

Is CONFIG_COMPAT the right conditional here? If the code is only used for architectures that have different aligments, it should not need be compiled in for the other architectures.

So, I'll define ARCH_HAS_FUNNY_64_ALIGNMENT in x86_64 and ia64 code and will check it, as Andi suggested.

I think nowadays, unconditionally setting CONFIG_FUNNY_64_ALIGNMENT from arch/{ia64,x86_64}/Kconfig would be the preferred way to a #define in include/asm.

Quoted 18 lines
Quoted 10 lines
Quoted 10 lines

 #define IPT_ALIGN(s) XT_ALIGN(s)

include/linux/netfilter_ipv4/ip_tables.h renamed from include/linux/netfilter_ipv4/ip_tables.h.iptcompat +9 -0
+
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>
+
+struct compat_ipt_getinfo
+{
+       char name[IPT_TABLE_MAXNAMELEN];
+       compat_uint_t valid_hooks;
+       compat_uint_t hook_entry[NF_IP_NUMHOOKS];
Quoted 8 lines
Quoted 4 lines

+       compat_uint_t underflow[NF_IP_NUMHOOKS];
+       compat_uint_t num_entries;
+       compat_uint_t size;
+};

This structure looks like it does not need any
conversions. You should probably just use
struct ipt_getinfo then.

Quoted 2 lines

I just saw compat_uint_t use in net/compat.c and thought, that it is a good style to use it. Does anybody know arch, where sizeof(compat_uint_t) != 4?

No, the compat layer already heavily depends on the fact that compat_uint_t is always the same as unsigned int.

Quoted 4 lines
Quoted 2 lines

Dito

Disagree, ipt_entry_match and ipt_entry_target contain pointers which make their alignment equal 8 byte on 64bits architectures.

Ah, I see.

Quoted 9 lines
Quoted 3 lines

I would much rather have either an extra 'compat' argument to to sock_setsockopt and proto_ops->setsockopt than to spread the use of is_compat_task further.

Another weak place in my code. is_compat_task() approach has one advantage - it doesn't require a lot of current code modifications.

Quoted 4 lines

Is the FIXME above the only reason that the code needs to be changed? What is the reason that you did not just address this in the compat_sys_setsockopt implementation?

Quoted 8 lines

Code above doesn't work. iptables with version >= 1.3 does alignment checks as well as kernel does. So, we can't simply put entries with 8 bytes alignment to userspace or with 4 bytes alignment to kernel - we need translate them entry by entry. So, I tried to do this the most correct way - that userspace will hide its alignment from kernel and vice versa, with not only SET_REPLACE, but also GET_INFO, GET_ENTRIES and SET_COUNTERS translation. First implementation was exactly in compat_sys_setsockopt, but David asked me to do this in netfilter code itself.

Ok, I see the point there. It's probably best to push down all the conversions from compat_sys_setsockopt down to the protocol specific parts, similar to what we do for the ioctl handlers.

I'm thinking of something like

int compat_sock_setsockopt(struct socket *sock, int level, int optname,
char __user *optval, int optlen)

{
	switch (optname) {
	case SO_ATTACH_FILTER:
		return do_set_attach_filter(fd, level, optname,
					    optval, optlen);
	case SO_SNDTIMEO:
		return do_set_sock_timeout(fd, level, optname,
					   optval, optlen);
	default:
		break;
	}
	return sock_setsockopt(sock, level, optname, optval, optlen);
}

asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
char __user *optval, int optlen)

{
	int err;
	struct socket *sock;

	if (optlen < 0)
		return -EINVAL;
			
	if ((sock = sockfd_lookup(fd, &err))!=NULL)
	{
		err = security_socket_setsockopt(sock,level,optname);
		if (err) {
			sockfd_put(sock);
			return err;
		}

		if (level == SOL_SOCKET)
			err = compat_sock_setsockopt(sock, level,
					optname, optval, optlen);
		else if (sock->ops->compat_setsockopt)
			err = sock->ops->compat_setsockopt(sock, level,
					optname, optval, optlen);
		else
			err = sock->ops->setsockopt(sock, level,
					optname, optval, optlen);
		sockfd_put(sock);
	}
	return err;
}

int tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int optlen)

{
	int err = 0;

	err = ip_setsockopt(sk, level, optname, optval, optlen);
#ifdef CONFIG_NETFILTER
	if (err = -ENOPROTOOPT) {
		lock_sock(sk);
		err = nf_setsockopt(sk, PF_INET, optname, optval, optlen);
		release_sock(sk);
	}
#endif
	return err;
}

int compat_tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int optlen)

{
	int err = 0;

	err = ip_setsockopt(sk, level, optname, optval, optlen);
#ifdef CONFIG_NETFILTER
	if (err = -ENOPROTOOPT) {
		lock_sock(sk);
		err = compat_nf_setsockopt(sk, PF_INET, optname, optval, optlen);
		release_sock(sk);
	}
#endif
	return err;
}

And the same for udp, raw, ipv6, decnet and each of those with getsockopt. It is a bigger change, but it puts all the handlers where they belong and it is more extensible to other sockopt handlers if we find more fsckup in some of them.

	Arnd <><
#6 lore raw

{get|set}sockopt compat layer

Hello, Arnd!

Sorry for such delay, was on vacancy. Here is a patch, introducing compat_(get|set)sockopt handlers, as you proposed.

Quoted 158 lines · Arnd Bergmann
Quoted 7 lines · Dmitry Mishin
Quoted 3 lines · Arnd Bergmann

Is CONFIG_COMPAT the right conditional here? If the code is only used for architectures that have different aligments, it should not need be compiled in for the other architectures.

So, I'll define ARCH_HAS_FUNNY_64_ALIGNMENT in x86_64 and ia64 code and will check it, as Andi suggested.

I think nowadays, unconditionally setting CONFIG_FUNNY_64_ALIGNMENT from arch/{ia64,x86_64}/Kconfig would be the preferred way to a #define in include/asm.

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines

 #define IPT_ALIGN(s) XT_ALIGN(s)

(quoted diff) +9 -0
+
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>
+
+struct compat_ipt_getinfo
+{
+       char name[IPT_TABLE_MAXNAMELEN];
+       compat_uint_t valid_hooks;
+       compat_uint_t hook_entry[NF_IP_NUMHOOKS];
Quoted 8 lines
Quoted 4 lines

+       compat_uint_t underflow[NF_IP_NUMHOOKS];
+       compat_uint_t num_entries;
+       compat_uint_t size;
+};

This structure looks like it does not need any
conversions. You should probably just use
struct ipt_getinfo then.

Quoted 3 lines

I just saw compat_uint_t use in net/compat.c and thought, that it is a good style to use it. Does anybody know arch, where sizeof(compat_uint_t) != 4?

No, the compat layer already heavily depends on the fact that compat_uint_t is always the same as unsigned int.

Quoted 4 lines
Quoted 1 line

Dito

Disagree, ipt_entry_match and ipt_entry_target contain pointers which make their alignment equal 8 byte on 64bits architectures.

Ah, I see.

Quoted 11 lines
Quoted 3 lines

I would much rather have either an extra 'compat' argument to to sock_setsockopt and proto_ops->setsockopt than to spread the use of is_compat_task further.

Another weak place in my code. is_compat_task() approach has one advantage - it doesn't require a lot of current code modifications.

Quoted 3 lines

Is the FIXME above the only reason that the code needs to be changed? What is the reason that you did not just address this in the compat_sys_setsockopt implementation?

Quoted 9 lines

Code above doesn't work. iptables with version >= 1.3 does alignment checks as well as kernel does. So, we can't simply put entries with 8 bytes alignment to userspace or with 4 bytes alignment to kernel - we need translate them entry by entry. So, I tried to do this the most correct way - that userspace will hide its alignment from kernel and vice versa, with not only SET_REPLACE, but also GET_INFO, GET_ENTRIES and SET_COUNTERS translation. First implementation was exactly in compat_sys_setsockopt, but David asked me to do this in netfilter code itself.

Ok, I see the point there. It's probably best to push down all the conversions from compat_sys_setsockopt down to the protocol specific parts, similar to what we do for the ioctl handlers.

I'm thinking of something like

int compat_sock_setsockopt(struct socket *sock, int level, int optname,
char __user *optval, int optlen)

{
	switch (optname) {
	case SO_ATTACH_FILTER:
		return do_set_attach_filter(fd, level, optname,
					    optval, optlen);
	case SO_SNDTIMEO:
		return do_set_sock_timeout(fd, level, optname,
					   optval, optlen);
	default:
		break;
	}
	return sock_setsockopt(sock, level, optname, optval, optlen);
}

asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
char __user *optval, int optlen)

{
	int err;
	struct socket *sock;

	if (optlen < 0)
		return -EINVAL;

	if ((sock = sockfd_lookup(fd, &err))!=NULL)
	{
		err = security_socket_setsockopt(sock,level,optname);
		if (err) {
			sockfd_put(sock);
			return err;
		}

		if (level == SOL_SOCKET)
			err = compat_sock_setsockopt(sock, level,
					optname, optval, optlen);
		else if (sock->ops->compat_setsockopt)
			err = sock->ops->compat_setsockopt(sock, level,
					optname, optval, optlen);
		else
			err = sock->ops->setsockopt(sock, level,
					optname, optval, optlen);
		sockfd_put(sock);
	}
	return err;
}

int tcp_setsockopt(struct sock *sk, int level, int optname, char __user

*optval, int optlen) {
	int err = 0;

	err = ip_setsockopt(sk, level, optname, optval, optlen);
#ifdef CONFIG_NETFILTER
	if (err = -ENOPROTOOPT) {
		lock_sock(sk);
		err = nf_setsockopt(sk, PF_INET, optname, optval, optlen);
		release_sock(sk);
	}
#endif
	return err;
}

int compat_tcp_setsockopt(struct sock *sk, int level, int optname, char

__user *optval, int optlen) {
	int err = 0;

	err = ip_setsockopt(sk, level, optname, optval, optlen);
#ifdef CONFIG_NETFILTER
	if (err = -ENOPROTOOPT) {
		lock_sock(sk);
		err = compat_nf_setsockopt(sk, PF_INET, optname, optval, optlen);
		release_sock(sk);
	}
#endif
	return err;
}

And the same for udp, raw, ipv6, decnet and each of those with getsockopt. It is a bigger change, but it puts all the handlers where they belong and it is more extensible to other sockopt handlers if we find more fsckup in some of them.

	Arnd <><
Signature · 2 lines
Thanks,
Dmitry.
include/linux/net.h renamed from include/linux/net.h.compat +6 -0
@@ -149,6 +149,12 @@ struct proto_ops {
 				      int optname, char __user *optval, int optlen);
 	int		(*getsockopt)(struct socket *sock, int level,
 				      int optname, char __user *optval, int __user *optlen);
+#ifdef CONFIG_COMPAT
+	int		(*compat_setsockopt)(struct socket *sock, int level,
+				      int optname, char __user *optval, int optlen);
+	int		(*compat_getsockopt)(struct socket *sock, int level,
+				      int optname, char __user *optval, int __user *optlen);
+#endif
 	int		(*sendmsg)   (struct kiocb *iocb, struct socket *sock,
 				      struct msghdr *m, size_t total_len);
 	int		(*recvmsg)   (struct kiocb *iocb, struct socket *sock,
include/linux/netfilter.h renamed from include/linux/netfilter.h.compat +16 -0
@@ -2,6 +2,7 @@
 #define __LINUX_NETFILTER_H
 
 #ifdef __KERNEL__
+#include <linux/config.h>
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/skbuff.h>
@@ -80,10 +81,18 @@ struct nf_sockopt_ops
 	int set_optmin;
 	int set_optmax;
 	int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
+#ifdef CONFIG_COMPAT
+	int (*compat_set)(struct sock *sk, int optval,
+			void __user *user, unsigned int len);
+#endif
 
 	int get_optmin;
 	int get_optmax;
 	int (*get)(struct sock *sk, int optval, void __user *user, int *len);
+#ifdef CONFIG_COMPAT
+	int (*compat_get)(struct sock *sk, int optval,
+			void __user *user, int *len);
+#endif
 
 	/* Number of users inside set() or get(). */
 	unsigned int use;
@@ -246,6 +255,13 @@ int nf_setsockopt(struct sock *sk, int p
 int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
 		  int *len);
 
+#ifdef CONFIG_COMPAT
+int compat_nf_setsockopt(struct sock *sk, int pf, int optval,
+		char __user *opt, int len);
+int compat_nf_getsockopt(struct sock *sk, int pf, int optval,
+		char __user *opt, int *len);
+#endif
+
 /* Packet queuing */
 struct nf_queue_handler {
 	int (*outfn)(struct sk_buff *skb, struct nf_info *info,
include/net/inet_connection_sock.h renamed from include/net/inet_connection_sock.h.compat +9 -0
@@ -15,6 +15,7 @@
 #ifndef _INET_CONNECTION_SOCK_H
 #define _INET_CONNECTION_SOCK_H
 
+#include <linux/config.h>
 #include <linux/compiler.h>
 #include <linux/string.h>
 #include <linux/timer.h>
@@ -50,6 +51,14 @@ struct inet_connection_sock_af_ops {
 				  char __user *optval, int optlen);
 	int	    (*getsockopt)(struct sock *sk, int level, int optname, 
 				  char __user *optval, int __user *optlen);
+#ifdef CONFIG_COMPAT
+	int	    (*compat_setsockopt)(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int optlen);
+	int	    (*compat_getsockopt)(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int __user *optlen);
+#endif
 	void	    (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
 	int sockaddr_len;
 };
include/net/ip.h renamed from include/net/ip.h.compat +6 -0
@@ -356,6 +356,12 @@ extern void	ip_cmsg_recv(struct msghdr *
 extern int	ip_cmsg_send(struct msghdr *msg, struct ipcm_cookie *ipc);
 extern int	ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int optlen);
 extern int	ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen);
+#ifdef CONFIG_COMPAT
+extern int	compat_ip_setsockopt(struct sock *sk, int level,
+			int optname, char __user *optval, int optlen);
+extern int	compat_ip_getsockopt(struct sock *sk, int level,
+			int optname, char __user *optval, int __user *optlen);
+#endif
 extern int	ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct sock *));
 
 extern int 	ip_recv_error(struct sock *sk, struct msghdr *msg, int len);
include/net/sctp/structs.h renamed from include/net/sctp/structs.h.compat +13 -0
@@ -54,6 +54,7 @@
 #ifndef __sctp_structs_h__
 #define __sctp_structs_h__
 
+#include <linux/config.h>
 #include <linux/time.h>		/* We get struct timespec.    */
 #include <linux/socket.h>	/* linux/in.h needs this!!    */
 #include <linux/in.h>		/* We get struct sockaddr_in. */
@@ -514,6 +515,18 @@ struct sctp_af {
 					 int optname,
 					 char __user *optval,
 					 int __user *optlen);
+#ifdef CONFIG_COMPAT
+	int		(*compat_setsockopt)	(struct sock *sk,
+					 int level,
+					 int optname,
+					 char __user *optval,
+					 int optlen);
+	int		(*compat_getsockopt)	(struct sock *sk,
+					 int level,
+					 int optname,
+					 char __user *optval,
+					 int __user *optlen);
+#endif
 	struct dst_entry *(*get_dst)	(struct sctp_association *asoc,
 					 union sctp_addr *daddr,
 					 union sctp_addr *saddr);
include/net/sock.h renamed from include/net/sock.h.compat +16 -0
@@ -520,6 +520,16 @@ struct proto {
 	int			(*getsockopt)(struct sock *sk, int level, 
 					int optname, char __user *optval, 
 					int __user *option);  	 
+#ifdef CONFIG_COMPAT
+	int			(*compat_setsockopt)(struct sock *sk,
+					int level,
+					int optname, char __user *optval,
+					int optlen);
+	int			(*compat_getsockopt)(struct sock *sk,
+					int level,
+					int optname, char __user *optval,
+					int __user *option);
+#endif
 	int			(*sendmsg)(struct kiocb *iocb, struct sock *sk,
 					   struct msghdr *msg, size_t len);
 	int			(*recvmsg)(struct kiocb *iocb, struct sock *sk,
@@ -816,6 +826,12 @@ extern int sock_common_recvmsg(struct ki
 			       struct msghdr *msg, size_t size, int flags);
 extern int sock_common_setsockopt(struct socket *sock, int level, int optname,
 				  char __user *optval, int optlen);
+#ifdef CONFIG_COMPAT
+extern int compat_sock_common_getsockopt(struct socket *sock, int level,
+		int optname, char __user *optval, int __user *optlen);
+extern int compat_sock_common_setsockopt(struct socket *sock, int level,
+		int optname, char __user *optval, int optlen);
+#endif
 
 extern void sk_common_release(struct sock *sk);
 
include/net/tcp.h renamed from include/net/tcp.h.compat +8 -0
@@ -347,6 +347,14 @@ extern int			tcp_getsockopt(struct sock 
 extern int			tcp_setsockopt(struct sock *sk, int level, 
 					       int optname, char __user *optval, 
 					       int optlen);
+#ifdef CONFIG_COMPAT
+extern int			compat_tcp_getsockopt(struct sock *sk,
+					int level, int optname,
+					char __user *optval, int __user *optlen);
+extern int			compat_tcp_setsockopt(struct sock *sk,
+					int level, int optname,
+					char __user *optval, int optlen);
+#endif
 extern void			tcp_set_keepalive(struct sock *sk, int val);
 extern int			tcp_recvmsg(struct kiocb *iocb, struct sock *sk,
 					    struct msghdr *msg,
net/compat.c renamed from net/compat.c.compat +77 -18

147 lines not on this page · raw message

net/core/sock.c renamed from net/core/sock.c.compat +28 -0
@@ -1385,6 +1385,20 @@ int sock_common_getsockopt(struct socket
 
 EXPORT_SYMBOL(sock_common_getsockopt);
 
+#ifdef CONFIG_COMPAT
+int compat_sock_common_getsockopt(struct socket *sock, int level,
+		int optname, char __user *optval, int __user *optlen)
+{
+	struct sock *sk = sock->sk;
+
+	if (sk->sk_prot->compat_setsockopt)
+		return sk->sk_prot->compat_getsockopt(sk, level,
+			optname, optval, optlen);
+	return sk->sk_prot->getsockopt(sk, level, optname, optval, optlen);
+}
+EXPORT_SYMBOL(compat_sock_common_getsockopt);
+#endif
+
 int sock_common_recvmsg(struct kiocb *iocb, struct socket *sock,
 			struct msghdr *msg, size_t size, int flags)
 {
@@ -1414,6 +1428,20 @@ int sock_common_setsockopt(struct socket
 
 EXPORT_SYMBOL(sock_common_setsockopt);
 
+#ifdef CONFIG_COMPAT
+int compat_sock_common_setsockopt(struct socket *sock,
+		int level, int optname, char __user *optval, int optlen)
+{
+	struct sock *sk = sock->sk;
+
+	if (sk->sk_prot->compat_setsockopt)
+		return sk->sk_prot->compat_setsockopt(sk, level,
+			optname, optval, optlen);
+	return sk->sk_prot->setsockopt(sk, level, optname, optval, optlen);
+}
+EXPORT_SYMBOL(compat_sock_common_setsockopt);
+#endif
+
 void sk_common_release(struct sock *sk)
 {
 	if (sk->sk_prot->destroy)
net/dccp/dccp.h renamed from net/dccp/dccp.h.compat +8 -0
@@ -246,6 +246,14 @@ extern int	   dccp_getsockopt(struct soc
 				   char __user *optval, int __user *optlen);
 extern int	   dccp_setsockopt(struct sock *sk, int level, int optname,
 				   char __user *optval, int optlen);
+#ifdef CONFIG_COMPAT
+extern int	   compat_dccp_getsockopt(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int __user *optlen);
+extern int	   compat_dccp_setsockopt(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int optlen);
+#endif
 extern int	   dccp_ioctl(struct sock *sk, int cmd, unsigned long arg);
 extern int	   dccp_sendmsg(struct kiocb *iocb, struct sock *sk,
 				struct msghdr *msg, size_t size);
net/dccp/ipv4.c renamed from net/dccp/ipv4.c.compat +8 -0
@@ -1028,6 +1028,10 @@ struct inet_connection_sock_af_ops dccp_
 	.net_header_len	= sizeof(struct iphdr),
 	.setsockopt	= ip_setsockopt,
 	.getsockopt	= ip_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_ip_setsockopt,
+	.compat_getsockopt	= compat_ip_getsockopt,
+#endif
 	.addr2sockaddr	= inet_csk_addr2sockaddr,
 	.sockaddr_len	= sizeof(struct sockaddr_in),
 };
@@ -1152,6 +1156,10 @@ struct proto dccp_prot = {
 	.init			= dccp_v4_init_sock,
 	.setsockopt		= dccp_setsockopt,
 	.getsockopt		= dccp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_dccp_setsockopt,
+	.compat_getsockopt	= compat_dccp_getsockopt,
+#endif
 	.sendmsg		= dccp_sendmsg,
 	.recvmsg		= dccp_recvmsg,
 	.backlog_rcv		= dccp_v4_do_rcv,
net/dccp/ipv6.c renamed from net/dccp/ipv6.c.compat +8 -0
@@ -1170,6 +1170,10 @@ static struct proto dccp_v6_prot = {
 	.init			= dccp_v6_init_sock,
 	.setsockopt		= dccp_setsockopt,
 	.getsockopt		= dccp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_dccp_setsockopt,
+	.compat_getsockopt	= compat_dccp_getsockopt,
+#endif
 	.sendmsg		= dccp_sendmsg,
 	.recvmsg		= dccp_recvmsg,
 	.backlog_rcv		= dccp_v6_do_rcv,
@@ -1207,6 +1211,10 @@ static struct proto_ops inet6_dccp_ops =
 	.shutdown	= inet_shutdown,
 	.setsockopt	= sock_common_setsockopt,
 	.getsockopt	= sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg	= inet_sendmsg,
 	.recvmsg	= sock_common_recvmsg,
 	.mmap		= sock_no_mmap,
net/dccp/proto.c renamed from net/dccp/proto.c.compat +59 -12

115 lines not on this page · raw message

net/ipv4/af_inet.c renamed from net/ipv4/af_inet.c.compat +12 -0
@@ -802,6 +802,10 @@ const struct proto_ops inet_stream_ops =
 	.shutdown =	inet_shutdown,
 	.setsockopt =	sock_common_setsockopt,
 	.getsockopt =	sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,
 	.recvmsg =	sock_common_recvmsg,
 	.mmap =		sock_no_mmap,
@@ -823,6 +827,10 @@ const struct proto_ops inet_dgram_ops = 
 	.shutdown =	inet_shutdown,
 	.setsockopt =	sock_common_setsockopt,
 	.getsockopt =	sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,
 	.recvmsg =	sock_common_recvmsg,
 	.mmap =		sock_no_mmap,
@@ -848,6 +856,10 @@ static const struct proto_ops inet_sockr
 	.shutdown =	inet_shutdown,
 	.setsockopt =	sock_common_setsockopt,
 	.getsockopt =	sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,
 	.recvmsg =	sock_common_recvmsg,
 	.mmap =		sock_no_mmap,
net/ipv4/ip_sockglue.c renamed from net/ipv4/ip_sockglue.c.compat +123 -19

185 lines not on this page · raw message

net/ipv4/raw.c renamed from net/ipv4/raw.c.compat +43 -7

79 lines not on this page · raw message

net/ipv4/tcp.c renamed from net/ipv4/tcp.c.compat +65 -12

115 lines not on this page · raw message

net/ipv4/tcp_ipv4.c renamed from net/ipv4/tcp_ipv4.c.compat +8 -0
@@ -1225,6 +1225,10 @@ struct inet_connection_sock_af_ops ipv4_
 	.net_header_len	=	sizeof(struct iphdr),
 	.setsockopt	=	ip_setsockopt,
 	.getsockopt	=	ip_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt =	compat_ip_setsockopt,
+	.compat_getsockopt =	compat_ip_getsockopt,
+#endif
 	.addr2sockaddr	=	inet_csk_addr2sockaddr,
 	.sockaddr_len	=	sizeof(struct sockaddr_in),
 };
@@ -1807,6 +1811,10 @@ struct proto tcp_prot = {
 	.shutdown		= tcp_shutdown,
 	.setsockopt		= tcp_setsockopt,
 	.getsockopt		= tcp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_tcp_setsockopt,
+	.compat_getsockopt	= compat_tcp_getsockopt,
+#endif
 	.sendmsg		= tcp_sendmsg,
 	.recvmsg		= tcp_recvmsg,
 	.backlog_rcv		= tcp_v4_do_rcv,
net/ipv4/udp.c renamed from net/ipv4/udp.c.compat +43 -8

86 lines not on this page · raw message

net/ipv6/af_inet6.c renamed from net/ipv6/af_inet6.c.compat +12 -0
@@ -470,6 +470,10 @@ const struct proto_ops inet6_stream_ops 
 	.shutdown =	inet_shutdown,			/* ok		*/
 	.setsockopt =	sock_common_setsockopt,		/* ok		*/
 	.getsockopt =	sock_common_getsockopt,		/* ok		*/
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,			/* ok		*/
 	.recvmsg =	sock_common_recvmsg,		/* ok		*/
 	.mmap =		sock_no_mmap,
@@ -491,6 +495,10 @@ const struct proto_ops inet6_dgram_ops =
 	.shutdown =	inet_shutdown,			/* ok		*/
 	.setsockopt =	sock_common_setsockopt,		/* ok		*/
 	.getsockopt =	sock_common_getsockopt,		/* ok		*/
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,			/* ok		*/
 	.recvmsg =	sock_common_recvmsg,		/* ok		*/
 	.mmap =		sock_no_mmap,
@@ -519,6 +527,10 @@ static const struct proto_ops inet6_sock
 	.shutdown =	inet_shutdown,			/* ok		*/
 	.setsockopt =	sock_common_setsockopt,		/* ok		*/
 	.getsockopt =	sock_common_getsockopt,		/* ok		*/
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,			/* ok		*/
 	.recvmsg =	sock_common_recvmsg,		/* ok		*/
 	.mmap =		sock_no_mmap,
net/ipv6/tcp_ipv6.c renamed from net/ipv6/tcp_ipv6.c.compat +4 -0
@@ -1565,6 +1565,10 @@ struct proto tcpv6_prot = {
 	.shutdown		= tcp_shutdown,
 	.setsockopt		= tcp_setsockopt,
 	.getsockopt		= tcp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_tcp_setsockopt,
+	.compat_getsockopt	= compat_tcp_getsockopt,
+#endif
 	.sendmsg		= tcp_sendmsg,
 	.recvmsg		= tcp_recvmsg,
 	.backlog_rcv		= tcp_v6_do_rcv,
net/netfilter/nf_sockopt.c renamed from net/netfilter/nf_sockopt.c.compat +69 -0

72 lines not on this page · raw message

net/sctp/ipv6.c renamed from net/sctp/ipv6.c.compat +4 -0
@@ -875,6 +875,10 @@ static const struct proto_ops inet6_seqp
 	.shutdown   = inet_shutdown,
 	.setsockopt = sock_common_setsockopt,
 	.getsockopt = sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg    = inet_sendmsg,
 	.recvmsg    = sock_common_recvmsg,
 	.mmap       = sock_no_mmap,
net/sctp/protocol.c renamed from net/sctp/protocol.c.compat +8 -0
@@ -845,6 +845,10 @@ static const struct proto_ops inet_seqpa
 	.shutdown    = inet_shutdown,     /* Looks harmless.  */
 	.setsockopt  = sock_common_setsockopt,   /* IP_SOL IP_OPTION is a problem. */
 	.getsockopt  = sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt  = compat_sock_common_setsockopt,
+	.compat_getsockopt  = compat_sock_common_getsockopt,
+#endif
 	.sendmsg     = inet_sendmsg,
 	.recvmsg     = sock_common_recvmsg,
 	.mmap        = sock_no_mmap,
@@ -883,6 +887,10 @@ static struct sctp_af sctp_ipv4_specific
 	.sctp_xmit      = sctp_v4_xmit,
 	.setsockopt     = ip_setsockopt,
 	.getsockopt     = ip_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt     = compat_ip_setsockopt,
+	.compat_getsockopt     = compat_ip_getsockopt,
+#endif
 	.get_dst	= sctp_v4_get_dst,
 	.get_saddr	= sctp_v4_get_saddr,
 	.copy_addrlist  = sctp_v4_copy_addrlist,
#7 lore raw

Re: {get|set}sockopt compat layer

Quoted 2 lines · Dmitry Mishin

Sorry for such delay, was on vacancy. Here is a patch, introducing compat_(get|set)sockopt handlers, as you proposed.

Looks pretty good to me, just a few nits I like to pick:

Quoted 5 lines
include/linux/net.h       2006-03-07 11:20:07.000000000 +0300 renamed from include/linux/net.h.compat        2006-03-07 11:22:27.000000000 +0300 +0 -0
@@ -149,6 +149,12 @@ struct proto_ops {
                                       int optname, char __user *optval, int optlen);
         int             (*getsockopt)(struct socket *sock, int level,

include/linux/net.h       2006-03-07 11:20:07.000000000 +0300 struct proto_ops { · line 160

Quoted 10 lines
include/linux/net.h       2006-03-07 11:20:07.000000000 +0300 renamed from include/linux/net.h.compat        2006-03-07 11:22:27.000000000 +0300 +6 -0
                                       int optname, char __user *optval, int __user *optlen);
+#ifdef CONFIG_COMPAT
+       int             (*compat_setsockopt)(struct socket *sock, int level,
+                                     int optname, char __user *optval, int optlen);
+       int             (*compat_getsockopt)(struct socket *sock, int level,
+                                     int optname, char __user *optval, int __user *optlen);
+#endif
         int             (*sendmsg)   (struct kiocb *iocb, struct socket *sock,
                                       struct msghdr *m, size_t total_len);
         int             (*recvmsg)   (struct kiocb *iocb, struct socket *sock,

For the compat_ioctl stuff, we don't have the function pointer inside an #ifdef, the overhead is relatively small since there is only one of these structures per module implementing a protocol, but it avoids having to rebuild everything when changing CONFIG_COMPAT.

It's probably not a big issue either way, maybe davem has a stronger opinion on it either way.

Quoted 10 lines
include/linux/netfilter.h 2006-03-07 15:00:14.000000000 +0300 renamed from include/linux/netfilter.h.compat  2006-03-06 12:06:34.000000000 +0300 +0 -0
@@ -2,6 +2,7 @@
  #define __LINUX_NETFILTER_H


 #ifdef __KERNEL__
+#include <linux/config.h>
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/skbuff.h>

You don't need to add new <linux/config.h> includes any more, these are automatic now.

Quoted 16 lines
include/linux/netfilter.h 2006-03-07 15:00:14.000000000 +0300 renamed from include/linux/netfilter.h.compat  2006-03-06 12:06:34.000000000 +0300 +4 -0
@@ -80,10 +81,18 @@ struct nf_sockopt_ops
         int set_optmin;
         int set_optmax;
         int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
+#ifdef CONFIG_COMPAT
+       int (*compat_set)(struct sock *sk, int optval,
+                       void __user *user, unsigned int len);
+#endif


        int get_optmin;
        int get_optmax;
        int (*get)(struct sock *sk, int optval, void __user *user, int *len);

include/linux/netfilter.h 2006-03-07 15:00:14.000000000 +0300 renamed from include/linux/netfilter.h.compat  2006-03-06 12:06:34.000000000 +0300 +4 -0
+#ifdef CONFIG_COMPAT
+       int (*compat_get)(struct sock *sk, int optval,
+                       void __user *user, int *len);
+#endif
Quoted 3 lines


        /* Number of users inside set() or get(). */ unsigned int use;

see above, same for some more of these.

Quoted 10 lines
include/linux/netfilter.h 2006-03-07 15:00:14.000000000 +0300 renamed from include/linux/netfilter.h.compat  2006-03-06 12:06:34.000000000 +0300 +6 -0
@@ -816,6 +826,12 @@ extern int sock_common_recvmsg(struct ki
                                struct msghdr *msg, size_t size, int flags);
  extern int sock_common_setsockopt(struct socket *sock, int level, int optname,
                                   char __user *optval, int optlen);
+#ifdef CONFIG_COMPAT
+extern int compat_sock_common_getsockopt(struct socket *sock, int level,
+               int optname, char __user *optval, int __user *optlen);
+extern int compat_sock_common_setsockopt(struct socket *sock, int level,
+               int optname, char __user *optval, int optlen);
+#endif
Quoted 3 lines


 extern void sk_common_release(struct sock *sk);

Declarations don't belong inside #ifdef.

	Arnd <><
#8 lore raw

Re: {get|set}sockopt compat layer

Hello, Arnd!

Quoted 8 lines

For the compat_ioctl stuff, we don't have the function pointer inside an #ifdef, the overhead is relatively small since there is only one of these structures per module implementing a protocol, but it avoids having to rebuild everything when changing CONFIG_COMPAT.

It's probably not a big issue either way, maybe davem has a stronger opinion on it either way.

Done.

Signature · 2 lines
Thanks,
Dmitry.
include/linux/net.h renamed from include/linux/net.h.compat +4 -0
@@ -149,6 +149,10 @@ struct proto_ops {
 				      int optname, char __user *optval, int optlen);
 	int		(*getsockopt)(struct socket *sock, int level,
 				      int optname, char __user *optval, int __user *optlen);
+	int		(*compat_setsockopt)(struct socket *sock, int level,
+				      int optname, char __user *optval, int optlen);
+	int		(*compat_getsockopt)(struct socket *sock, int level,
+				      int optname, char __user *optval, int __user *optlen);
 	int		(*sendmsg)   (struct kiocb *iocb, struct socket *sock,
 				      struct msghdr *m, size_t total_len);
 	int		(*recvmsg)   (struct kiocb *iocb, struct socket *sock,
include/linux/netfilter.h renamed from include/linux/netfilter.h.compat +9 -0
@@ -80,10 +80,14 @@ struct nf_sockopt_ops
 	int set_optmin;
 	int set_optmax;
 	int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
+	int (*compat_set)(struct sock *sk, int optval,
+			void __user *user, unsigned int len);
 
 	int get_optmin;
 	int get_optmax;
 	int (*get)(struct sock *sk, int optval, void __user *user, int *len);
+	int (*compat_get)(struct sock *sk, int optval,
+			void __user *user, int *len);
 
 	/* Number of users inside set() or get(). */
 	unsigned int use;
@@ -246,6 +250,11 @@ int nf_setsockopt(struct sock *sk, int p
 int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
 		  int *len);
 
+int compat_nf_setsockopt(struct sock *sk, int pf, int optval,
+		char __user *opt, int len);
+int compat_nf_getsockopt(struct sock *sk, int pf, int optval,
+		char __user *opt, int *len);
+
 /* Packet queuing */
 struct nf_queue_handler {
 	int (*outfn)(struct sk_buff *skb, struct nf_info *info,
include/net/inet_connection_sock.h renamed from include/net/inet_connection_sock.h.compat +6 -0
@@ -50,6 +50,12 @@ struct inet_connection_sock_af_ops {
 				  char __user *optval, int optlen);
 	int	    (*getsockopt)(struct sock *sk, int level, int optname, 
 				  char __user *optval, int __user *optlen);
+	int	    (*compat_setsockopt)(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int optlen);
+	int	    (*compat_getsockopt)(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int __user *optlen);
 	void	    (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
 	int sockaddr_len;
 };
include/net/ip.h renamed from include/net/ip.h.compat +4 -0
@@ -356,6 +356,10 @@ extern void	ip_cmsg_recv(struct msghdr *
 extern int	ip_cmsg_send(struct msghdr *msg, struct ipcm_cookie *ipc);
 extern int	ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int optlen);
 extern int	ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen);
+extern int	compat_ip_setsockopt(struct sock *sk, int level,
+			int optname, char __user *optval, int optlen);
+extern int	compat_ip_getsockopt(struct sock *sk, int level,
+			int optname, char __user *optval, int __user *optlen);
 extern int	ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct sock *));
 
 extern int 	ip_recv_error(struct sock *sk, struct msghdr *msg, int len);
include/net/sctp/structs.h renamed from include/net/sctp/structs.h.compat +10 -0
@@ -514,6 +514,16 @@ struct sctp_af {
 					 int optname,
 					 char __user *optval,
 					 int __user *optlen);
+	int		(*compat_setsockopt)	(struct sock *sk,
+					 int level,
+					 int optname,
+					 char __user *optval,
+					 int optlen);
+	int		(*compat_getsockopt)	(struct sock *sk,
+					 int level,
+					 int optname,
+					 char __user *optval,
+					 int __user *optlen);
 	struct dst_entry *(*get_dst)	(struct sctp_association *asoc,
 					 union sctp_addr *daddr,
 					 union sctp_addr *saddr);
include/net/sock.h renamed from include/net/sock.h.compat +12 -0
@@ -520,6 +520,14 @@ struct proto {
 	int			(*getsockopt)(struct sock *sk, int level, 
 					int optname, char __user *optval, 
 					int __user *option);  	 
+	int			(*compat_setsockopt)(struct sock *sk,
+					int level,
+					int optname, char __user *optval,
+					int optlen);
+	int			(*compat_getsockopt)(struct sock *sk,
+					int level,
+					int optname, char __user *optval,
+					int __user *option);
 	int			(*sendmsg)(struct kiocb *iocb, struct sock *sk,
 					   struct msghdr *msg, size_t len);
 	int			(*recvmsg)(struct kiocb *iocb, struct sock *sk,
@@ -816,6 +824,10 @@ extern int sock_common_recvmsg(struct ki
 			       struct msghdr *msg, size_t size, int flags);
 extern int sock_common_setsockopt(struct socket *sock, int level, int optname,
 				  char __user *optval, int optlen);
+extern int compat_sock_common_getsockopt(struct socket *sock, int level,
+		int optname, char __user *optval, int __user *optlen);
+extern int compat_sock_common_setsockopt(struct socket *sock, int level,
+		int optname, char __user *optval, int optlen);
 
 extern void sk_common_release(struct sock *sk);
 
include/net/tcp.h renamed from include/net/tcp.h.compat +6 -0
@@ -347,6 +347,12 @@ extern int			tcp_getsockopt(struct sock 
 extern int			tcp_setsockopt(struct sock *sk, int level, 
 					       int optname, char __user *optval, 
 					       int optlen);
+extern int			compat_tcp_getsockopt(struct sock *sk,
+					int level, int optname,
+					char __user *optval, int __user *optlen);
+extern int			compat_tcp_setsockopt(struct sock *sk,
+					int level, int optname,
+					char __user *optval, int optlen);
 extern void			tcp_set_keepalive(struct sock *sk, int val);
 extern int			tcp_recvmsg(struct kiocb *iocb, struct sock *sk,
 					    struct msghdr *msg,
net/compat.c renamed from net/compat.c.compat +77 -18

147 lines not on this page · raw message

net/core/sock.c renamed from net/core/sock.c.compat +28 -0
@@ -1385,6 +1385,20 @@ int sock_common_getsockopt(struct socket
 
 EXPORT_SYMBOL(sock_common_getsockopt);
 
+#ifdef CONFIG_COMPAT
+int compat_sock_common_getsockopt(struct socket *sock, int level,
+		int optname, char __user *optval, int __user *optlen)
+{
+	struct sock *sk = sock->sk;
+
+	if (sk->sk_prot->compat_setsockopt)
+		return sk->sk_prot->compat_getsockopt(sk, level,
+			optname, optval, optlen);
+	return sk->sk_prot->getsockopt(sk, level, optname, optval, optlen);
+}
+EXPORT_SYMBOL(compat_sock_common_getsockopt);
+#endif
+
 int sock_common_recvmsg(struct kiocb *iocb, struct socket *sock,
 			struct msghdr *msg, size_t size, int flags)
 {
@@ -1414,6 +1428,20 @@ int sock_common_setsockopt(struct socket
 
 EXPORT_SYMBOL(sock_common_setsockopt);
 
+#ifdef CONFIG_COMPAT
+int compat_sock_common_setsockopt(struct socket *sock,
+		int level, int optname, char __user *optval, int optlen)
+{
+	struct sock *sk = sock->sk;
+
+	if (sk->sk_prot->compat_setsockopt)
+		return sk->sk_prot->compat_setsockopt(sk, level,
+			optname, optval, optlen);
+	return sk->sk_prot->setsockopt(sk, level, optname, optval, optlen);
+}
+EXPORT_SYMBOL(compat_sock_common_setsockopt);
+#endif
+
 void sk_common_release(struct sock *sk)
 {
 	if (sk->sk_prot->destroy)
net/dccp/dccp.h renamed from net/dccp/dccp.h.compat +8 -0
@@ -246,6 +246,14 @@ extern int	   dccp_getsockopt(struct soc
 				   char __user *optval, int __user *optlen);
 extern int	   dccp_setsockopt(struct sock *sk, int level, int optname,
 				   char __user *optval, int optlen);
+#ifdef CONFIG_COMPAT
+extern int	   compat_dccp_getsockopt(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int __user *optlen);
+extern int	   compat_dccp_setsockopt(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int optlen);
+#endif
 extern int	   dccp_ioctl(struct sock *sk, int cmd, unsigned long arg);
 extern int	   dccp_sendmsg(struct kiocb *iocb, struct sock *sk,
 				struct msghdr *msg, size_t size);
net/dccp/ipv4.c renamed from net/dccp/ipv4.c.compat +8 -0
@@ -1028,6 +1028,10 @@ struct inet_connection_sock_af_ops dccp_
 	.net_header_len	= sizeof(struct iphdr),
 	.setsockopt	= ip_setsockopt,
 	.getsockopt	= ip_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_ip_setsockopt,
+	.compat_getsockopt	= compat_ip_getsockopt,
+#endif
 	.addr2sockaddr	= inet_csk_addr2sockaddr,
 	.sockaddr_len	= sizeof(struct sockaddr_in),
 };
@@ -1152,6 +1156,10 @@ struct proto dccp_prot = {
 	.init			= dccp_v4_init_sock,
 	.setsockopt		= dccp_setsockopt,
 	.getsockopt		= dccp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_dccp_setsockopt,
+	.compat_getsockopt	= compat_dccp_getsockopt,
+#endif
 	.sendmsg		= dccp_sendmsg,
 	.recvmsg		= dccp_recvmsg,
 	.backlog_rcv		= dccp_v4_do_rcv,
net/dccp/ipv6.c renamed from net/dccp/ipv6.c.compat +8 -0
@@ -1170,6 +1170,10 @@ static struct proto dccp_v6_prot = {
 	.init			= dccp_v6_init_sock,
 	.setsockopt		= dccp_setsockopt,
 	.getsockopt		= dccp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_dccp_setsockopt,
+	.compat_getsockopt	= compat_dccp_getsockopt,
+#endif
 	.sendmsg		= dccp_sendmsg,
 	.recvmsg		= dccp_recvmsg,
 	.backlog_rcv		= dccp_v6_do_rcv,
@@ -1207,6 +1211,10 @@ static struct proto_ops inet6_dccp_ops =
 	.shutdown	= inet_shutdown,
 	.setsockopt	= sock_common_setsockopt,
 	.getsockopt	= sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg	= inet_sendmsg,
 	.recvmsg	= sock_common_recvmsg,
 	.mmap		= sock_no_mmap,
net/dccp/proto.c renamed from net/dccp/proto.c.compat +59 -12

115 lines not on this page · raw message

net/ipv4/af_inet.c renamed from net/ipv4/af_inet.c.compat +12 -0
@@ -802,6 +802,10 @@ const struct proto_ops inet_stream_ops =
 	.shutdown =	inet_shutdown,
 	.setsockopt =	sock_common_setsockopt,
 	.getsockopt =	sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,
 	.recvmsg =	sock_common_recvmsg,
 	.mmap =		sock_no_mmap,
@@ -823,6 +827,10 @@ const struct proto_ops inet_dgram_ops = 
 	.shutdown =	inet_shutdown,
 	.setsockopt =	sock_common_setsockopt,
 	.getsockopt =	sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,
 	.recvmsg =	sock_common_recvmsg,
 	.mmap =		sock_no_mmap,
@@ -848,6 +856,10 @@ static const struct proto_ops inet_sockr
 	.shutdown =	inet_shutdown,
 	.setsockopt =	sock_common_setsockopt,
 	.getsockopt =	sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,
 	.recvmsg =	sock_common_recvmsg,
 	.mmap =		sock_no_mmap,
net/ipv4/ip_sockglue.c renamed from net/ipv4/ip_sockglue.c.compat +123 -19

185 lines not on this page · raw message

net/ipv4/raw.c renamed from net/ipv4/raw.c.compat +43 -7

79 lines not on this page · raw message

net/ipv4/tcp.c renamed from net/ipv4/tcp.c.compat +65 -12

115 lines not on this page · raw message

net/ipv4/tcp_ipv4.c renamed from net/ipv4/tcp_ipv4.c.compat +8 -0
@@ -1225,6 +1225,10 @@ struct inet_connection_sock_af_ops ipv4_
 	.net_header_len	=	sizeof(struct iphdr),
 	.setsockopt	=	ip_setsockopt,
 	.getsockopt	=	ip_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt =	compat_ip_setsockopt,
+	.compat_getsockopt =	compat_ip_getsockopt,
+#endif
 	.addr2sockaddr	=	inet_csk_addr2sockaddr,
 	.sockaddr_len	=	sizeof(struct sockaddr_in),
 };
@@ -1807,6 +1811,10 @@ struct proto tcp_prot = {
 	.shutdown		= tcp_shutdown,
 	.setsockopt		= tcp_setsockopt,
 	.getsockopt		= tcp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_tcp_setsockopt,
+	.compat_getsockopt	= compat_tcp_getsockopt,
+#endif
 	.sendmsg		= tcp_sendmsg,
 	.recvmsg		= tcp_recvmsg,
 	.backlog_rcv		= tcp_v4_do_rcv,
net/ipv4/udp.c renamed from net/ipv4/udp.c.compat +43 -8

86 lines not on this page · raw message

net/ipv6/af_inet6.c renamed from net/ipv6/af_inet6.c.compat +12 -0
@@ -470,6 +470,10 @@ const struct proto_ops inet6_stream_ops 
 	.shutdown =	inet_shutdown,			/* ok		*/
 	.setsockopt =	sock_common_setsockopt,		/* ok		*/
 	.getsockopt =	sock_common_getsockopt,		/* ok		*/
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,			/* ok		*/
 	.recvmsg =	sock_common_recvmsg,		/* ok		*/
 	.mmap =		sock_no_mmap,
@@ -491,6 +495,10 @@ const struct proto_ops inet6_dgram_ops =
 	.shutdown =	inet_shutdown,			/* ok		*/
 	.setsockopt =	sock_common_setsockopt,		/* ok		*/
 	.getsockopt =	sock_common_getsockopt,		/* ok		*/
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,			/* ok		*/
 	.recvmsg =	sock_common_recvmsg,		/* ok		*/
 	.mmap =		sock_no_mmap,
@@ -519,6 +527,10 @@ static const struct proto_ops inet6_sock
 	.shutdown =	inet_shutdown,			/* ok		*/
 	.setsockopt =	sock_common_setsockopt,		/* ok		*/
 	.getsockopt =	sock_common_getsockopt,		/* ok		*/
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,			/* ok		*/
 	.recvmsg =	sock_common_recvmsg,		/* ok		*/
 	.mmap =		sock_no_mmap,
net/ipv6/tcp_ipv6.c renamed from net/ipv6/tcp_ipv6.c.compat +4 -0
@@ -1565,6 +1565,10 @@ struct proto tcpv6_prot = {
 	.shutdown		= tcp_shutdown,
 	.setsockopt		= tcp_setsockopt,
 	.getsockopt		= tcp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_tcp_setsockopt,
+	.compat_getsockopt	= compat_tcp_getsockopt,
+#endif
 	.sendmsg		= tcp_sendmsg,
 	.recvmsg		= tcp_recvmsg,
 	.backlog_rcv		= tcp_v6_do_rcv,
net/netfilter/nf_sockopt.c renamed from net/netfilter/nf_sockopt.c.compat +69 -0

72 lines not on this page · raw message

net/sctp/ipv6.c renamed from net/sctp/ipv6.c.compat +4 -0
@@ -875,6 +875,10 @@ static const struct proto_ops inet6_seqp
 	.shutdown   = inet_shutdown,
 	.setsockopt = sock_common_setsockopt,
 	.getsockopt = sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg    = inet_sendmsg,
 	.recvmsg    = sock_common_recvmsg,
 	.mmap       = sock_no_mmap,
net/sctp/protocol.c renamed from net/sctp/protocol.c.compat +8 -0
@@ -845,6 +845,10 @@ static const struct proto_ops inet_seqpa
 	.shutdown    = inet_shutdown,     /* Looks harmless.  */
 	.setsockopt  = sock_common_setsockopt,   /* IP_SOL IP_OPTION is a problem. */
 	.getsockopt  = sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt  = compat_sock_common_setsockopt,
+	.compat_getsockopt  = compat_sock_common_getsockopt,
+#endif
 	.sendmsg     = inet_sendmsg,
 	.recvmsg     = sock_common_recvmsg,
 	.mmap        = sock_no_mmap,
@@ -883,6 +887,10 @@ static struct sctp_af sctp_ipv4_specific
 	.sctp_xmit      = sctp_v4_xmit,
 	.setsockopt     = ip_setsockopt,
 	.getsockopt     = ip_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt     = compat_ip_setsockopt,
+	.compat_getsockopt     = compat_ip_getsockopt,
+#endif
 	.get_dst	= sctp_v4_get_dst,
 	.get_saddr	= sctp_v4_get_saddr,
 	.copy_addrlist  = sctp_v4_copy_addrlist,
maintainer
#9 lore raw

Re: {get|set}sockopt compat layer

From: Dmitry Mishin <[email protected]>
Date: Thu, 9 Mar 2006 13:23:59 +0300

Quoted 11 lines

Hello, Arnd!

Quoted 8 lines

For the compat_ioctl stuff, we don't have the function pointer inside an #ifdef, the overhead is relatively small since there is only one of these structures per module implementing a protocol, but it avoids having to rebuild everything when changing CONFIG_COMPAT.

It's probably not a big issue either way, maybe davem has a stronger opinion on it either way.

Done.

I think this looks fine but it doesn't apply cleanly to the current net-2.6.17 tree.

Could you cook up a fresh patch, and send it with a complete changelog entry and appropriate Signed-off-by: lines?

Thanks a lot Dmitry.

#10 lore raw

PATCH 1/1 {get|set}sockopt compatibility layer

This patch extends {get|set}sockopt compatibility layer in order to move protocol specific parts to their place and avoid huge universal net/compat.c file in the future.

Signature · 2 lines
Thanks,
Dmitry.
include/linux/net.h renamed from include/linux/net.h.compat +4 -0
@@ -149,6 +149,10 @@ struct proto_ops {
 				      int optname, char __user *optval, int optlen);
 	int		(*getsockopt)(struct socket *sock, int level,
 				      int optname, char __user *optval, int __user *optlen);
+	int		(*compat_setsockopt)(struct socket *sock, int level,
+				      int optname, char __user *optval, int optlen);
+	int		(*compat_getsockopt)(struct socket *sock, int level,
+				      int optname, char __user *optval, int __user *optlen);
 	int		(*sendmsg)   (struct kiocb *iocb, struct socket *sock,
 				      struct msghdr *m, size_t total_len);
 	int		(*recvmsg)   (struct kiocb *iocb, struct socket *sock,
include/linux/netfilter.h renamed from include/linux/netfilter.h.compat +9 -0
@@ -80,10 +80,14 @@ struct nf_sockopt_ops
 	int set_optmin;
 	int set_optmax;
 	int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
+	int (*compat_set)(struct sock *sk, int optval,
+			void __user *user, unsigned int len);
 
 	int get_optmin;
 	int get_optmax;
 	int (*get)(struct sock *sk, int optval, void __user *user, int *len);
+	int (*compat_get)(struct sock *sk, int optval,
+			void __user *user, int *len);
 
 	/* Number of users inside set() or get(). */
 	unsigned int use;
@@ -246,6 +250,11 @@ int nf_setsockopt(struct sock *sk, int p
 int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
 		  int *len);
 
+int compat_nf_setsockopt(struct sock *sk, int pf, int optval,
+		char __user *opt, int len);
+int compat_nf_getsockopt(struct sock *sk, int pf, int optval,
+		char __user *opt, int *len);
+
 /* Packet queuing */
 struct nf_queue_handler {
 	int (*outfn)(struct sk_buff *skb, struct nf_info *info,
include/net/inet_connection_sock.h renamed from include/net/inet_connection_sock.h.compat +6 -0
@@ -50,6 +50,12 @@ struct inet_connection_sock_af_ops {
 				  char __user *optval, int optlen);
 	int	    (*getsockopt)(struct sock *sk, int level, int optname, 
 				  char __user *optval, int __user *optlen);
+	int	    (*compat_setsockopt)(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int optlen);
+	int	    (*compat_getsockopt)(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int __user *optlen);
 	void	    (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
 	int sockaddr_len;
 };
include/net/ip.h renamed from include/net/ip.h.compat +4 -0
@@ -356,6 +356,10 @@ extern void	ip_cmsg_recv(struct msghdr *
 extern int	ip_cmsg_send(struct msghdr *msg, struct ipcm_cookie *ipc);
 extern int	ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int optlen);
 extern int	ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen);
+extern int	compat_ip_setsockopt(struct sock *sk, int level,
+			int optname, char __user *optval, int optlen);
+extern int	compat_ip_getsockopt(struct sock *sk, int level,
+			int optname, char __user *optval, int __user *optlen);
 extern int	ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct sock *));
 
 extern int 	ip_recv_error(struct sock *sk, struct msghdr *msg, int len);
include/net/ipv6.h renamed from include/net/ipv6.h.compat +10 -0
@@ -520,6 +520,16 @@ extern int			ipv6_getsockopt(struct sock
 						int optname,
 						char __user *optval, 
 						int __user *optlen);
+extern int			compat_ipv6_setsockopt(struct sock *sk,
+						int level,
+						int optname,
+						char __user *optval,
+						int optlen);
+extern int			compat_ipv6_getsockopt(struct sock *sk,
+						int level,
+						int optname,
+						char __user *optval,
+						int __user *optlen);
 
 extern void			ipv6_packet_init(void);
 
include/net/sctp/structs.h renamed from include/net/sctp/structs.h.compat +10 -0
@@ -514,6 +514,16 @@ struct sctp_af {
 					 int optname,
 					 char __user *optval,
 					 int __user *optlen);
+	int		(*compat_setsockopt)	(struct sock *sk,
+					 int level,
+					 int optname,
+					 char __user *optval,
+					 int optlen);
+	int		(*compat_getsockopt)	(struct sock *sk,
+					 int level,
+					 int optname,
+					 char __user *optval,
+					 int __user *optlen);
 	struct dst_entry *(*get_dst)	(struct sctp_association *asoc,
 					 union sctp_addr *daddr,
 					 union sctp_addr *saddr);
include/net/sock.h renamed from include/net/sock.h.compat +12 -0
@@ -520,6 +520,14 @@ struct proto {
 	int			(*getsockopt)(struct sock *sk, int level, 
 					int optname, char __user *optval, 
 					int __user *option);  	 
+	int			(*compat_setsockopt)(struct sock *sk,
+					int level,
+					int optname, char __user *optval,
+					int optlen);
+	int			(*compat_getsockopt)(struct sock *sk,
+					int level,
+					int optname, char __user *optval,
+					int __user *option);
 	int			(*sendmsg)(struct kiocb *iocb, struct sock *sk,
 					   struct msghdr *msg, size_t len);
 	int			(*recvmsg)(struct kiocb *iocb, struct sock *sk,
@@ -816,6 +824,10 @@ extern int sock_common_recvmsg(struct ki
 			       struct msghdr *msg, size_t size, int flags);
 extern int sock_common_setsockopt(struct socket *sock, int level, int optname,
 				  char __user *optval, int optlen);
+extern int compat_sock_common_getsockopt(struct socket *sock, int level,
+		int optname, char __user *optval, int __user *optlen);
+extern int compat_sock_common_setsockopt(struct socket *sock, int level,
+		int optname, char __user *optval, int optlen);
 
 extern void sk_common_release(struct sock *sk);
 
include/net/tcp.h renamed from include/net/tcp.h.compat +6 -0
@@ -352,6 +352,12 @@ extern int			tcp_getsockopt(struct sock 
 extern int			tcp_setsockopt(struct sock *sk, int level, 
 					       int optname, char __user *optval, 
 					       int optlen);
+extern int			compat_tcp_getsockopt(struct sock *sk,
+					int level, int optname,
+					char __user *optval, int __user *optlen);
+extern int			compat_tcp_setsockopt(struct sock *sk,
+					int level, int optname,
+					char __user *optval, int optlen);
 extern void			tcp_set_keepalive(struct sock *sk, int val);
 extern int			tcp_recvmsg(struct kiocb *iocb, struct sock *sk,
 					    struct msghdr *msg,
net/compat.c renamed from net/compat.c.compat +77 -18

147 lines not on this page · raw message

net/core/sock.c renamed from net/core/sock.c.compat +28 -0
@@ -1385,6 +1385,20 @@ int sock_common_getsockopt(struct socket
 
 EXPORT_SYMBOL(sock_common_getsockopt);
 
+#ifdef CONFIG_COMPAT
+int compat_sock_common_getsockopt(struct socket *sock, int level,
+		int optname, char __user *optval, int __user *optlen)
+{
+	struct sock *sk = sock->sk;
+
+	if (sk->sk_prot->compat_setsockopt)
+		return sk->sk_prot->compat_getsockopt(sk, level,
+			optname, optval, optlen);
+	return sk->sk_prot->getsockopt(sk, level, optname, optval, optlen);
+}
+EXPORT_SYMBOL(compat_sock_common_getsockopt);
+#endif
+
 int sock_common_recvmsg(struct kiocb *iocb, struct socket *sock,
 			struct msghdr *msg, size_t size, int flags)
 {
@@ -1414,6 +1428,20 @@ int sock_common_setsockopt(struct socket
 
 EXPORT_SYMBOL(sock_common_setsockopt);
 
+#ifdef CONFIG_COMPAT
+int compat_sock_common_setsockopt(struct socket *sock,
+		int level, int optname, char __user *optval, int optlen)
+{
+	struct sock *sk = sock->sk;
+
+	if (sk->sk_prot->compat_setsockopt)
+		return sk->sk_prot->compat_setsockopt(sk, level,
+			optname, optval, optlen);
+	return sk->sk_prot->setsockopt(sk, level, optname, optval, optlen);
+}
+EXPORT_SYMBOL(compat_sock_common_setsockopt);
+#endif
+
 void sk_common_release(struct sock *sk)
 {
 	if (sk->sk_prot->destroy)
net/dccp/dccp.h renamed from net/dccp/dccp.h.compat +8 -0
@@ -192,6 +192,14 @@ extern int	   dccp_getsockopt(struct soc
 				   char __user *optval, int __user *optlen);
 extern int	   dccp_setsockopt(struct sock *sk, int level, int optname,
 				   char __user *optval, int optlen);
+#ifdef CONFIG_COMPAT
+extern int	   compat_dccp_getsockopt(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int __user *optlen);
+extern int	   compat_dccp_setsockopt(struct sock *sk,
+				int level, int optname,
+				char __user *optval, int optlen);
+#endif
 extern int	   dccp_ioctl(struct sock *sk, int cmd, unsigned long arg);
 extern int	   dccp_sendmsg(struct kiocb *iocb, struct sock *sk,
 				struct msghdr *msg, size_t size);
net/dccp/ipv4.c renamed from net/dccp/ipv4.c.compat +12 -0
@@ -994,6 +994,10 @@ static struct inet_connection_sock_af_op
 	.net_header_len	= sizeof(struct iphdr),
 	.setsockopt	= ip_setsockopt,
 	.getsockopt	= ip_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_ip_setsockopt,
+	.compat_getsockopt	= compat_ip_getsockopt,
+#endif
 	.addr2sockaddr	= inet_csk_addr2sockaddr,
 	.sockaddr_len	= sizeof(struct sockaddr_in),
 };
@@ -1040,6 +1044,10 @@ static struct proto dccp_v4_prot = {
 	.init			= dccp_v4_init_sock,
 	.setsockopt		= dccp_setsockopt,
 	.getsockopt		= dccp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_dccp_setsockopt,
+	.compat_getsockopt	= compat_dccp_getsockopt,
+#endif
 	.sendmsg		= dccp_sendmsg,
 	.recvmsg		= dccp_recvmsg,
 	.backlog_rcv		= dccp_v4_do_rcv,
@@ -1079,6 +1087,10 @@ static const struct proto_ops inet_dccp_
 	.shutdown	= inet_shutdown,
 	.setsockopt	= sock_common_setsockopt,
 	.getsockopt	= sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg	= inet_sendmsg,
 	.recvmsg	= sock_common_recvmsg,
 	.mmap		= sock_no_mmap,
net/dccp/ipv6.c renamed from net/dccp/ipv6.c.compat +16 -0
@@ -1114,6 +1114,10 @@ static struct inet_connection_sock_af_op
 	.net_header_len	= sizeof(struct ipv6hdr),
 	.setsockopt	= ipv6_setsockopt,
 	.getsockopt	= ipv6_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_ipv6_setsockopt,
+	.compat_getsockopt	= compat_ipv6_getsockopt,
+#endif
 	.addr2sockaddr	= inet6_csk_addr2sockaddr,
 	.sockaddr_len	= sizeof(struct sockaddr_in6)
 };
@@ -1130,6 +1134,10 @@ static struct inet_connection_sock_af_op
 	.net_header_len	= sizeof(struct iphdr),
 	.setsockopt	= ipv6_setsockopt,
 	.getsockopt	= ipv6_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_ipv6_setsockopt,
+	.compat_getsockopt	= compat_ipv6_getsockopt,
+#endif
 	.addr2sockaddr	= inet6_csk_addr2sockaddr,
 	.sockaddr_len	= sizeof(struct sockaddr_in6)
 };
@@ -1167,6 +1175,10 @@ static struct proto dccp_v6_prot = {
 	.init		= dccp_v6_init_sock,
 	.setsockopt	= dccp_setsockopt,
 	.getsockopt	= dccp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_dccp_setsockopt,
+	.compat_getsockopt	= compat_dccp_getsockopt,
+#endif
 	.sendmsg	= dccp_sendmsg,
 	.recvmsg	= dccp_recvmsg,
 	.backlog_rcv	= dccp_v6_do_rcv,
@@ -1204,6 +1216,10 @@ static struct proto_ops inet6_dccp_ops =
 	.shutdown	= inet_shutdown,
 	.setsockopt	= sock_common_setsockopt,
 	.getsockopt	= sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg	= inet_sendmsg,
 	.recvmsg	= sock_common_recvmsg,
 	.mmap		= sock_no_mmap,
net/dccp/proto.c renamed from net/dccp/proto.c.compat +55 -12

105 lines not on this page · raw message

net/ipv4/af_inet.c renamed from net/ipv4/af_inet.c.compat +12 -0
@@ -802,6 +802,10 @@ const struct proto_ops inet_stream_ops =
 	.shutdown =	inet_shutdown,
 	.setsockopt =	sock_common_setsockopt,
 	.getsockopt =	sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,
 	.recvmsg =	sock_common_recvmsg,
 	.mmap =		sock_no_mmap,
@@ -823,6 +827,10 @@ const struct proto_ops inet_dgram_ops = 
 	.shutdown =	inet_shutdown,
 	.setsockopt =	sock_common_setsockopt,
 	.getsockopt =	sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,
 	.recvmsg =	sock_common_recvmsg,
 	.mmap =		sock_no_mmap,
@@ -848,6 +856,10 @@ static const struct proto_ops inet_sockr
 	.shutdown =	inet_shutdown,
 	.setsockopt =	sock_common_setsockopt,
 	.getsockopt =	sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,
 	.recvmsg =	sock_common_recvmsg,
 	.mmap =		sock_no_mmap,
net/ipv4/ip_sockglue.c renamed from net/ipv4/ip_sockglue.c.compat +123 -19

185 lines not on this page · raw message

net/ipv4/raw.c renamed from net/ipv4/raw.c.compat +43 -7

79 lines not on this page · raw message

net/ipv4/tcp.c renamed from net/ipv4/tcp.c.compat +65 -12

115 lines not on this page · raw message

net/ipv4/tcp_ipv4.c renamed from net/ipv4/tcp_ipv4.c.compat +8 -0
@@ -1226,6 +1226,10 @@ struct inet_connection_sock_af_ops ipv4_
 	.net_header_len	=	sizeof(struct iphdr),
 	.setsockopt	=	ip_setsockopt,
 	.getsockopt	=	ip_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt =	compat_ip_setsockopt,
+	.compat_getsockopt =	compat_ip_getsockopt,
+#endif
 	.addr2sockaddr	=	inet_csk_addr2sockaddr,
 	.sockaddr_len	=	sizeof(struct sockaddr_in),
 };
@@ -1808,6 +1812,10 @@ struct proto tcp_prot = {
 	.shutdown		= tcp_shutdown,
 	.setsockopt		= tcp_setsockopt,
 	.getsockopt		= tcp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_tcp_setsockopt,
+	.compat_getsockopt	= compat_tcp_getsockopt,
+#endif
 	.sendmsg		= tcp_sendmsg,
 	.recvmsg		= tcp_recvmsg,
 	.backlog_rcv		= tcp_v4_do_rcv,
net/ipv4/udp.c renamed from net/ipv4/udp.c.compat +43 -8

86 lines not on this page · raw message

net/ipv6/af_inet6.c renamed from net/ipv6/af_inet6.c.compat +12 -0
@@ -470,6 +470,10 @@ const struct proto_ops inet6_stream_ops 
 	.shutdown =	inet_shutdown,			/* ok		*/
 	.setsockopt =	sock_common_setsockopt,		/* ok		*/
 	.getsockopt =	sock_common_getsockopt,		/* ok		*/
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,			/* ok		*/
 	.recvmsg =	sock_common_recvmsg,		/* ok		*/
 	.mmap =		sock_no_mmap,
@@ -491,6 +495,10 @@ const struct proto_ops inet6_dgram_ops =
 	.shutdown =	inet_shutdown,			/* ok		*/
 	.setsockopt =	sock_common_setsockopt,		/* ok		*/
 	.getsockopt =	sock_common_getsockopt,		/* ok		*/
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,			/* ok		*/
 	.recvmsg =	sock_common_recvmsg,		/* ok		*/
 	.mmap =		sock_no_mmap,
@@ -519,6 +527,10 @@ static const struct proto_ops inet6_sock
 	.shutdown =	inet_shutdown,			/* ok		*/
 	.setsockopt =	sock_common_setsockopt,		/* ok		*/
 	.getsockopt =	sock_common_getsockopt,		/* ok		*/
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg =	inet_sendmsg,			/* ok		*/
 	.recvmsg =	sock_common_recvmsg,		/* ok		*/
 	.mmap =		sock_no_mmap,
net/ipv6/ipv6_sockglue.c renamed from net/ipv6/ipv6_sockglue.c.compat +133 -30

215 lines not on this page · raw message

net/ipv6/ipv6_syms.c renamed from net/ipv6/ipv6_syms.c.compat +4 -0
@@ -18,6 +18,10 @@ EXPORT_SYMBOL(ip6_route_output);
 EXPORT_SYMBOL(addrconf_lock);
 EXPORT_SYMBOL(ipv6_setsockopt);
 EXPORT_SYMBOL(ipv6_getsockopt);
+#ifdef CONFIG_COMPAT
+EXPORT_SYMBOL(compat_ipv6_setsockopt);
+EXPORT_SYMBOL(compat_ipv6_getsockopt);
+#endif
 EXPORT_SYMBOL(inet6_register_protosw);
 EXPORT_SYMBOL(inet6_unregister_protosw);
 EXPORT_SYMBOL(inet6_add_protocol);
net/ipv6/raw.c renamed from net/ipv6/raw.c.compat +87 -25

155 lines not on this page · raw message

net/ipv6/tcp_ipv6.c renamed from net/ipv6/tcp_ipv6.c.compat +12 -0
@@ -1308,6 +1308,10 @@ static struct inet_connection_sock_af_op
 
 	.setsockopt	=	ipv6_setsockopt,
 	.getsockopt	=	ipv6_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_ipv6_setsockopt,
+	.compat_getsockopt	= compat_ipv6_getsockopt,
+#endif
 	.addr2sockaddr	=	inet6_csk_addr2sockaddr,
 	.sockaddr_len	=	sizeof(struct sockaddr_in6)
 };
@@ -1327,6 +1331,10 @@ static struct inet_connection_sock_af_op
 
 	.setsockopt	=	ipv6_setsockopt,
 	.getsockopt	=	ipv6_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_ipv6_setsockopt,
+	.compat_getsockopt	= compat_ipv6_getsockopt,
+#endif
 	.addr2sockaddr	=	inet6_csk_addr2sockaddr,
 	.sockaddr_len	=	sizeof(struct sockaddr_in6)
 };
@@ -1566,6 +1574,10 @@ struct proto tcpv6_prot = {
 	.shutdown		= tcp_shutdown,
 	.setsockopt		= tcp_setsockopt,
 	.getsockopt		= tcp_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_tcp_setsockopt,
+	.compat_getsockopt	= compat_tcp_getsockopt,
+#endif
 	.sendmsg		= tcp_sendmsg,
 	.recvmsg		= tcp_recvmsg,
 	.backlog_rcv		= tcp_v6_do_rcv,
net/ipv6/udp.c renamed from net/ipv6/udp.c.compat +44 -8

87 lines not on this page · raw message

net/netfilter/nf_sockopt.c renamed from net/netfilter/nf_sockopt.c.compat +69 -0

72 lines not on this page · raw message

net/sctp/ipv6.c renamed from net/sctp/ipv6.c.compat +8 -0
@@ -875,6 +875,10 @@ static const struct proto_ops inet6_seqp
 	.shutdown   = inet_shutdown,
 	.setsockopt = sock_common_setsockopt,
 	.getsockopt = sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_sock_common_setsockopt,
+	.compat_getsockopt	= compat_sock_common_getsockopt,
+#endif
 	.sendmsg    = inet_sendmsg,
 	.recvmsg    = sock_common_recvmsg,
 	.mmap       = sock_no_mmap,
@@ -914,6 +918,10 @@ static struct sctp_af sctp_ipv6_specific
 	.sctp_xmit       = sctp_v6_xmit,
 	.setsockopt      = ipv6_setsockopt,
 	.getsockopt      = ipv6_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt	= compat_ipv6_setsockopt,
+	.compat_getsockopt	= compat_ipv6_getsockopt,
+#endif
 	.get_dst	 = sctp_v6_get_dst,
 	.get_saddr	 = sctp_v6_get_saddr,
 	.copy_addrlist   = sctp_v6_copy_addrlist,
net/sctp/protocol.c renamed from net/sctp/protocol.c.compat +8 -0
@@ -845,6 +845,10 @@ static const struct proto_ops inet_seqpa
 	.shutdown    = inet_shutdown,     /* Looks harmless.  */
 	.setsockopt  = sock_common_setsockopt,   /* IP_SOL IP_OPTION is a problem. */
 	.getsockopt  = sock_common_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt  = compat_sock_common_setsockopt,
+	.compat_getsockopt  = compat_sock_common_getsockopt,
+#endif
 	.sendmsg     = inet_sendmsg,
 	.recvmsg     = sock_common_recvmsg,
 	.mmap        = sock_no_mmap,
@@ -883,6 +887,10 @@ static struct sctp_af sctp_ipv4_specific
 	.sctp_xmit      = sctp_v4_xmit,
 	.setsockopt     = ip_setsockopt,
 	.getsockopt     = ip_getsockopt,
+#ifdef CONFIG_COMPAT
+	.compat_setsockopt     = compat_ip_setsockopt,
+	.compat_getsockopt     = compat_ip_getsockopt,
+#endif
 	.get_dst	= sctp_v4_get_dst,
 	.get_saddr	= sctp_v4_get_saddr,
 	.copy_addrlist  = sctp_v4_copy_addrlist,
maintainer Applied
#11 lore raw

Re: [PATCH] {get|set}sockopt compatibility layer

From: Dmitry Mishin <[email protected]>
Date: Fri, 10 Mar 2006 14:21:10 +0300

Quoted 5 lines

This patch extends {get|set}sockopt compatibility layer in order to move protocol specific parts to their place and avoid huge universal net/compat.c file in the future.

Applied, thanks Dmitry.

Please give "-p1" format patches in the future, I fixed your's up by hand so could feed it to git.

Thanks again.

#14 lore raw

PATCH 1/1 iptables 32bit compat layer

In reply to Mishin Dmitry

This patch extends current iptables compatibility layer in order to get 32bit iptables to work on 64bit kernel. Current layer is insufficient due to alignment checks both in kernel and user space tools.

Patch is for current net-2.6.17 with addition of move of ipt_entry_{match| target} definitions to xt_entry_{match|target}.

Signature · 2 lines
Thanks,
Dmitry.
include/linux/netfilter/x_tables.h +67 -0
index ad72a4f..9d4fa6d 100644
@@ -142,6 +142,12 @@ struct xt_counters_info
 #define ASSERT_WRITE_LOCK(x)
 #include <linux/netfilter_ipv4/listhelp.h>
 
+#ifdef CONFIG_COMPAT
+#define COMPAT_TO_USER		1
+#define COMPAT_FROM_USER	-1
+#define COMPAT_CALC_SIZE	0
+#endif
+
 struct xt_match
 {
 	struct list_head list;
@@ -175,6 +181,9 @@ struct xt_match
 	void (*destroy)(const struct xt_match *match, void *matchinfo,
 			unsigned int matchinfosize);
 
+	/* Called when userspace align differs from kernel space one */
+	int (*compat)(void *match, void **dstptr, int *size, int convert);
+
 	/* Set this to THIS_MODULE if you are a module, otherwise NULL */
 	struct module *me;
 
@@ -220,6 +229,9 @@ struct xt_target
 	void (*destroy)(const struct xt_target *target, void *targinfo,
 			unsigned int targinfosize);
 
+	/* Called when userspace align differs from kernel space one */
+	int (*compat)(void *target, void **dstptr, int *size, int convert);
+
 	/* Set this to THIS_MODULE if you are a module, otherwise NULL */
 	struct module *me;
 
@@ -314,6 +326,61 @@ 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);
 
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>
+
+struct compat_xt_entry_match
+{
+	union {
+		struct {
+			u_int16_t match_size;
+			char name[XT_FUNCTION_MAXNAMELEN - 1];
+			u_int8_t revision;
+		} user;
+		u_int16_t match_size;
+	} u;
+	unsigned char data[0];
+};
+
+struct compat_xt_entry_target
+{
+	union {
+		struct {
+			u_int16_t target_size;
+			char name[XT_FUNCTION_MAXNAMELEN - 1];
+			u_int8_t revision;
+		} user;
+		u_int16_t target_size;
+	} u;
+	unsigned char data[0];
+};
+
+/* FIXME: this works only on 32 bit tasks
+ * need to change whole approach in order to calculate align as function of
+ * current task alignment */
+
+struct compat_xt_counters
+{
+	u_int32_t cnt[4];
+};
+
+struct compat_xt_counters_info
+{
+	char name[XT_TABLE_MAXNAMELEN];
+	compat_uint_t num_counters;
+	struct compat_xt_counters counters[0];
+};
+
+#define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \
+		& ~(__alignof__(struct compat_xt_counters)-1))
+
+extern void xt_compat_lock(int af);
+extern void xt_compat_unlock(int af);
+extern int xt_compat_match(void *match, void **dstptr, int *size, int convert);
+extern int xt_compat_target(void *target, void **dstptr, int *size,
+		int convert);
+
+#endif /* CONFIG_COMPAT */
 #endif /* __KERNEL__ */
 
 #endif /* _X_TABLES_H */
include/linux/netfilter_ipv4/ip_tables.h +18 -0
index 56eebc6..9e11e32 100644
@@ -312,5 +312,23 @@ extern unsigned int ipt_do_table(struct 
 				 void *userdata);
 
 #define IPT_ALIGN(s) XT_ALIGN(s)
+
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>
+
+struct compat_ipt_entry
+{
+	struct ipt_ip ip;
+	compat_uint_t nfcache;
+	u_int16_t target_offset;
+	u_int16_t next_offset;
+	compat_uint_t comefrom;
+	struct compat_xt_counters counters;
+	unsigned char elems[0];
+};
+
+#define COMPAT_IPT_ALIGN(s) 	COMPAT_XT_ALIGN(s)
+
+#endif /* CONFIG_COMPAT */
 #endif /*__KERNEL__*/
 #endif /* _IPTABLES_H */
net/compat.c +1 -2
index 13177a1..6a7028e 100644
@@ -476,8 +476,7 @@ asmlinkage long compat_sys_setsockopt(in
 	int err;
 	struct socket *sock;
 
-	/* SO_SET_REPLACE seems to be the same in all levels */
-	if (optname == IPT_SO_SET_REPLACE)
+	if (level == SOL_IPV6 && optname == IPT_SO_SET_REPLACE)
 		return do_netfilter_replace(fd, level, optname,
 					    optval, optlen);
 
net/ipv4/netfilter/ip_tables.c +1077 -205

1,395 lines not on this page · raw message

net/netfilter/x_tables.c +113 -0

143 lines not on this page · raw message

#15 lore raw
Quoted 6 lines · Dmitry Mishin

This patch extends current iptables compatibility layer in order to get 32bit iptables to work on 64bit kernel. Current layer is insufficient due to alignment checks both in kernel and user space tools.

Patch is for current net-2.6.17 with addition of move of ipt_entry_{match| target} definitions to xt_entry_{match|target}.

Thanks, this looks good. Two small issues so far:

net/compat.c asmlinkage long compat_sys_setsockopt(in · line 481

Quoted 13 lines
net/compat.c +1 -2
index 13177a1..6a7028e 100644
@@ -476,8 +476,7 @@ asmlinkage long compat_sys_setsockopt(in
 	int err;
 	struct socket *sock;
 
-	/* SO_SET_REPLACE seems to be the same in all levels */
-	if (optname == IPT_SO_SET_REPLACE)
+	if (level == SOL_IPV6 && optname == IPT_SO_SET_REPLACE)
 		return do_netfilter_replace(fd, level, optname,
 					    optval, optlen);

I don't understand the reason for this change. If its not a mistake, it would make more sense to check for IP6T_SO_SET_REPLACE I guess ..

net/compat.c asmlinkage long compat_sys_setsockopt(in

Quoted 13 lines
net/compat.c +13 -0
+#ifdef CONFIG_COMPAT
+void xt_compat_lock(int af)
+{
+	down(&xt[af].compat_mutex);
+}
+EXPORT_SYMBOL_GPL(xt_compat_lock);
+
+void xt_compat_unlock(int af)
+{
+	up(&xt[af].compat_mutex);
+}
+EXPORT_SYMBOL_GPL(xt_compat_unlock);
+#endif

Won't a seperate compat-mutex introduce races between compat- and non-compat users? BTW, the up/down calls have been replaced by the new mutex API in Linus' tree, please resend the patch against the current tree.

#16 lore raw
Quoted 17 lines · Patrick McHardy
Quoted 6 lines · Dmitry Mishin

This patch extends current iptables compatibility layer in order to get 32bit iptables to work on 64bit kernel. Current layer is insufficient due to alignment checks both in kernel and user space tools.

Patch is for current net-2.6.17 with addition of move of ipt_entry_{match| target} definitions to xt_entry_{match|target}.

Thanks, this looks good. Two small issues so far:

Quoted 8 lines
net/compat.c +0 -0
index 13177a1..6a7028e 100644
@@ -476,8 +476,7 @@ asmlinkage long compat_sys_setsockopt(in
 	int err;
 	struct socket *sock;
 
Quoted 8 lines

net/compat.c asmlinkage long compat_sys_setsockopt(in · line 481

Quoted 5 lines
net/compat.c +1 -2
-	/* SO_SET_REPLACE seems to be the same in all levels */
-	if (optname == IPT_SO_SET_REPLACE)
+	if (level == SOL_IPV6 && optname == IPT_SO_SET_REPLACE)
 		return do_netfilter_replace(fd, level, optname,
 					    optval, optlen);

I don't understand the reason for this change. If its not a mistake, it would make more sense to check for IP6T_SO_SET_REPLACE I guess ..

IP6T_SO_SET_REPLACE == IPT_SO_SET_REPLACE == XT_SO_SET_REPLACE. Rename will require respective #include directive rename, so, I just leave this as it is. BTW, I'll make respective patch for IPV6 in the near future and this hunk will be removed at all.

Quoted 11 lines
Quoted 11 lines
net/compat.c +10 -0
+#ifdef CONFIG_COMPAT
+void xt_compat_lock(int af)
+{
+	down(&xt[af].compat_mutex);
+}
+EXPORT_SYMBOL_GPL(xt_compat_lock);
+
+void xt_compat_unlock(int af)
+{
+	up(&xt[af].compat_mutex);
Quoted 8 lines

net/compat.c

Quoted 3 lines
net/compat.c +3 -0
+}
+EXPORT_SYMBOL_GPL(xt_compat_unlock);
+#endif

Won't a seperate compat-mutex introduce races between compat- and non-compat users? BTW, the up/down calls have been replaced by the new mutex API in Linus' tree, please resend the patch against the current tree.

compat_mutex is always over xt[af].mutex and can't be taken under the last one, so, there should be no races.
New patch is attached.

Signature · 2 lines
Thanks,
Dmitry.
include/linux/netfilter/x_tables.h +67 -0
index 1350e47..f6bdef8 100644
@@ -142,6 +142,12 @@ struct xt_counters_info
 #define ASSERT_WRITE_LOCK(x)
 #include <linux/netfilter_ipv4/listhelp.h>
 
+#ifdef CONFIG_COMPAT
+#define COMPAT_TO_USER		1
+#define COMPAT_FROM_USER	-1
+#define COMPAT_CALC_SIZE	0
+#endif
+
 struct xt_match
 {
 	struct list_head list;
@@ -175,6 +181,9 @@ struct xt_match
 	void (*destroy)(const struct xt_match *match, void *matchinfo,
 			unsigned int matchinfosize);
 
+	/* Called when userspace align differs from kernel space one */
+	int (*compat)(void *match, void **dstptr, int *size, int convert);
+
 	/* Set this to THIS_MODULE if you are a module, otherwise NULL */
 	struct module *me;
 
@@ -220,6 +229,9 @@ struct xt_target
 	void (*destroy)(const struct xt_target *target, void *targinfo,
 			unsigned int targinfosize);
 
+	/* Called when userspace align differs from kernel space one */
+	int (*compat)(void *target, void **dstptr, int *size, int convert);
+
 	/* Set this to THIS_MODULE if you are a module, otherwise NULL */
 	struct module *me;
 
@@ -314,6 +326,61 @@ 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);
 
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>
+
+struct compat_xt_entry_match
+{
+	union {
+		struct {
+			u_int16_t match_size;
+			char name[XT_FUNCTION_MAXNAMELEN - 1];
+			u_int8_t revision;
+		} user;
+		u_int16_t match_size;
+	} u;
+	unsigned char data[0];
+};
+
+struct compat_xt_entry_target
+{
+	union {
+		struct {
+			u_int16_t target_size;
+			char name[XT_FUNCTION_MAXNAMELEN - 1];
+			u_int8_t revision;
+		} user;
+		u_int16_t target_size;
+	} u;
+	unsigned char data[0];
+};
+
+/* FIXME: this works only on 32 bit tasks
+ * need to change whole approach in order to calculate align as function of
+ * current task alignment */
+
+struct compat_xt_counters
+{
+	u_int32_t cnt[4];
+};
+
+struct compat_xt_counters_info
+{
+	char name[XT_TABLE_MAXNAMELEN];
+	compat_uint_t num_counters;
+	struct compat_xt_counters counters[0];
+};
+
+#define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \
+		& ~(__alignof__(struct compat_xt_counters)-1))
+
+extern void xt_compat_lock(int af);
+extern void xt_compat_unlock(int af);
+extern int xt_compat_match(void *match, void **dstptr, int *size, int convert);
+extern int xt_compat_target(void *target, void **dstptr, int *size,
+		int convert);
+
+#endif /* CONFIG_COMPAT */
 #endif /* __KERNEL__ */
 
 #endif /* _X_TABLES_H */
include/linux/netfilter_ipv4/ip_tables.h +18 -0
index d5b8c0d..c0dac16 100644
@@ -316,5 +316,23 @@ extern unsigned int ipt_do_table(struct 
 				 void *userdata);
 
 #define IPT_ALIGN(s) XT_ALIGN(s)
+
+#ifdef CONFIG_COMPAT
+#include <net/compat.h>
+
+struct compat_ipt_entry
+{
+	struct ipt_ip ip;
+	compat_uint_t nfcache;
+	u_int16_t target_offset;
+	u_int16_t next_offset;
+	compat_uint_t comefrom;
+	struct compat_xt_counters counters;
+	unsigned char elems[0];
+};
+
+#define COMPAT_IPT_ALIGN(s) 	COMPAT_XT_ALIGN(s)
+
+#endif /* CONFIG_COMPAT */
 #endif /*__KERNEL__*/
 #endif /* _IPTABLES_H */
net/compat.c +1 -2
index 8fd37cd..d5d69fa 100644
@@ -476,8 +476,7 @@ asmlinkage long compat_sys_setsockopt(in
 	int err;
 	struct socket *sock;
 
-	/* SO_SET_REPLACE seems to be the same in all levels */
-	if (optname == IPT_SO_SET_REPLACE)
+	if (level == SOL_IPV6 && optname == IPT_SO_SET_REPLACE)
 		return do_netfilter_replace(fd, level, optname,
 					    optval, optlen);
 
net/ipv4/netfilter/ip_tables.c +1080 -208

1,404 lines not on this page · raw message

net/netfilter/x_tables.c +113 -0

143 lines not on this page · raw message

#17 lore raw
Quoted 19 lines · Dmitry Mishin
Quoted 8 lines · Patrick McHardy
Quoted 8 lines
net/compat.c +0 -0
index 13177a1..6a7028e 100644
@@ -476,8 +476,7 @@ asmlinkage long compat_sys_setsockopt(in
 	int err;
 	struct socket *sock;
 
Quoted 8 lines

net/compat.c asmlinkage long compat_sys_setsockopt(in · line 481

Quoted 5 lines
net/compat.c +1 -2
-	/* SO_SET_REPLACE seems to be the same in all levels */
-	if (optname == IPT_SO_SET_REPLACE)
+	if (level == SOL_IPV6 && optname == IPT_SO_SET_REPLACE)
 		return do_netfilter_replace(fd, level, optname,
 					    optval, optlen);

I don't understand the reason for this change. If its not a mistake, it would make more sense to check for IP6T_SO_SET_REPLACE I guess ..

Quoted 4 lines

IP6T_SO_SET_REPLACE == IPT_SO_SET_REPLACE == XT_SO_SET_REPLACE. Rename will require respective #include directive rename, so, I just leave this as it is. BTW, I'll make respective patch for IPV6 in the near future and this hunk will be removed at all.

I know, but SOL_IPV6 implies IP6T_* - but please don't bother sending a new patch for this :) So the point of the change is to exclude IPv6 from the compat layer because its not implemented yet?

#18 lore raw
Quoted 19 lines · Patrick McHardy
Quoted 18 lines · Dmitry Mishin
Quoted 16 lines · Patrick McHardy

net/compat.c asmlinkage long compat_sys_setsockopt(in · line 481

Quoted 13 lines
net/compat.c +1 -2
index 13177a1..6a7028e 100644
@@ -476,8 +476,7 @@ asmlinkage long compat_sys_setsockopt(in
 	int err;
 	struct socket *sock;
 
-	/* SO_SET_REPLACE seems to be the same in all levels */
-	if (optname == IPT_SO_SET_REPLACE)
+	if (level == SOL_IPV6 && optname == IPT_SO_SET_REPLACE)
 		return do_netfilter_replace(fd, level, optname,
 					    optval, optlen);

I don't understand the reason for this change. If its not a mistake, it would make more sense to check for IP6T_SO_SET_REPLACE I guess ..

Quoted 8 lines
Quoted 4 lines

IP6T_SO_SET_REPLACE == IPT_SO_SET_REPLACE == XT_SO_SET_REPLACE. Rename will require respective #include directive rename, so, I just leave this as it is. BTW, I'll make respective patch for IPV6 in the near future and this hunk will be removed at all.

I know, but SOL_IPV6 implies IP6T_* - but please don't bother sending a new patch for this :) So the point of the change is to exclude IPv6 from the compat layer because its not implemented yet?

Exactly. Because do_netfilter_replace still works for some cases, but newer replacement isn't ready yet.

Signature · 2 lines
Thanks,
Dmitry.
#19 lore raw
Quoted 8 lines · Dmitry Mishin
Quoted 4 lines · Patrick McHardy

I know, but SOL_IPV6 implies IP6T_* - but please don't bother sending a new patch for this :) So the point of the change is to exclude IPv6 from the compat layer because its not implemented yet?

Exactly. Because do_netfilter_replace still works for some cases, but newer replacement isn't ready yet.

Ah OK. One last thing before I'll pass it on. There was one 64 bit architecture where iptables already worked with 32 bit userspace for some reason. I would like to make sure that it still works before it goes in because I can't debug it if it fails afterwards. I don't recall which arch it was, but I think Martin had one of these machines. Martin, could you give the compat patch a try?

#20 lore raw
Quoted 10 lines · Patrick McHardy
Quoted 8 lines · Dmitry Mishin
Quoted 4 lines · Patrick McHardy

I know, but SOL_IPV6 implies IP6T_* - but please don't bother sending a new patch for this :) So the point of the change is to exclude IPv6 from the compat layer because its not implemented yet?

Exactly. Because do_netfilter_replace still works for some cases, but newer replacement isn't ready yet.

Quoted 6 lines

Ah OK. One last thing before I'll pass it on. There was one 64 bit architecture where iptables already worked with 32 bit userspace for some reason. I would like to make sure that it still works before it goes in because I can't debug it if it fails afterwards. I don't recall which arch it was, but I think Martin had one of these machines. Martin, could you give the compat patch a try?

It was an sparc64 machine with 32bit userspace I used for this testing. Iirc, there was no problem adding/removing rules with the normal built in matches and targets. The parts that were troublesome was some matches/targets and rule counters.
That was worked around with very very very very ugly hacks in the matches/targets in userspace, first an attempt to detect if we are running 64/32 and if that's the case add some padding to some structs to make the placement of used struct members match what's in kernel)

That machine (an old ultra1) hasn't seen electricity in a long time, I'll see if I can dig it out this weekend unless someone else (dave?) beats me to testing the patch.

Signature · 1 line
/Martin
maintainer
#21 lore raw

From: Martin Josefsson <[email protected]>
Date: Wed, 29 Mar 2006 21:04:45 +0200

Quoted 3 lines

That machine (an old ultra1) hasn't seen electricity in a long time, I'll see if I can dig it out this weekend unless someone else (dave?) beats me to testing the patch.

I think such userland hacks should not be worried about and we should put the new correct kernel compat netfilter stuff in.

If anything explodes on sparc64 for whatever reason, I will take care of it. :-)

#22 lore raw
Quoted 9 lines · David S. Miller

From: Martin Josefsson <[email protected]>
Date: Wed, 29 Mar 2006 21:04:45 +0200

Quoted 3 lines

That machine (an old ultra1) hasn't seen electricity in a long time, I'll see if I can dig it out this weekend unless someone else (dave?) beats me to testing the patch.

Quoted 6 lines

I think such userland hacks should not be worried about and we should put the new correct kernel compat netfilter stuff in.

If anything explodes on sparc64 for whatever reason, I will take care of it. :-)

Fine with me :) I've added it to my tree, I'll pass it on a couple of hours.