Skip to contentSkip to conversation

ethtool: Compat handling for struct ethtool_rxnfc

PATCH Superseded Ben Hutchings 2 participants 4 messages Feb 28, 2011 – Apr 11, 2011

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ethtool: Compat handling for struct ethtool_rxnfc

This structure was accidentally defined such that its layout can differ between 32-bit and 64-bit processes. Add compat structure definitions and functions to copy from/to user-space with the necessary adjustments.

---
I have not tested this with a driver that implements the ETHTOOL_{G,S}RXCLSRL* operations. However I have tested the new functions in a simple userland test harness.

Ben.

 include/linux/ethtool.h |   34 ++++++++++++
 net/core/ethtool.c      |  131 ++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 134 insertions(+), 31 deletions(-)
include/linux/ethtool.h +34 -0
index aac3e2e..b297f28 100644
@@ -13,6 +13,9 @@
 #ifndef _LINUX_ETHTOOL_H
 #define _LINUX_ETHTOOL_H
 
+#ifdef __KERNEL__
+#include <linux/compat.h>
+#endif
 #include <linux/types.h>
 #include <linux/if_ether.h>
 
@@ -450,6 +453,37 @@ struct ethtool_rxnfc {
 	__u32				rule_locs[0];
 };
 
+#ifdef __KERNEL__
+#ifdef CONFIG_COMPAT
+
+struct compat_ethtool_rx_flow_spec {
+	u32		flow_type;
+	union {
+		struct ethtool_tcpip4_spec		tcp_ip4_spec;
+		struct ethtool_tcpip4_spec		udp_ip4_spec;
+		struct ethtool_tcpip4_spec		sctp_ip4_spec;
+		struct ethtool_ah_espip4_spec		ah_ip4_spec;
+		struct ethtool_ah_espip4_spec		esp_ip4_spec;
+		struct ethtool_usrip4_spec		usr_ip4_spec;
+		struct ethhdr				ether_spec;
+		u8					hdata[72];
+	} h_u, m_u;
+	compat_u64	ring_cookie;
+	u32		location;
+};
+
+struct compat_ethtool_rxnfc {
+	u32				cmd;
+	u32				flow_type;
+	compat_u64			data;
+	struct compat_ethtool_rx_flow_spec fs;
+	u32				rule_cnt;
+	u32				rule_locs[0];
+};
+
+#endif /* CONFIG_COMPAT */
+#endif /* __KERNEL__ */
+
 /**
  * struct ethtool_rxfh_indir - command to get or set RX flow hash indirection
  * @cmd: Specific command number - %ETHTOOL_GRXFHINDIR or %ETHTOOL_SRXFHINDIR
net/core/ethtool.c +100 -31

163 lines not on this page · raw message

Signature · 7 lines
1.7.4


-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
maintainer
#1 lore raw

From: Ben Hutchings <[email protected]>
Date: Mon, 28 Feb 2011 18:22:26 +0000

Quoted 6 lines

This structure was accidentally defined such that its layout can differ between 32-bit and 64-bit processes. Add compat structure definitions and functions to copy from/to user-space with the necessary adjustments.

Please implement this via the proper contextual compat ioctl handling in net/socket.c

Using is_compat_task() is heavily discouraged.

#2 lore raw
Quoted 8 lines · David Miller

From: Ben Hutchings <[email protected]>
Date: Mon, 28 Feb 2011 18:22:26 +0000

Quoted 5 lines

This structure was accidentally defined such that its layout can differ between 32-bit and 64-bit processes. Add compat structure definitions and functions to copy from/to user-space with the necessary adjustments.

Quoted 6 lines
Quoted 1 line

Please implement this via the proper contextual compat ioctl handling in net/socket.c

Using is_compat_task() is heavily discouraged.

This is going to be even more horrible. But I'll try it.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#3 lore raw
In reply to Ben Hutchings
Quoted 4 lines · Ben Hutchings

This structure was accidentally defined such that its layout can differ between 32-bit and 64-bit processes. Add compat structure definitions and functions to copy from/to user-space with the necessary adjustments.

Damnit, we have to do the same thing for struct ethtool_rx_ntuple:

$ cc -m64 test.c
$ ./a.out
sizeof(struct ethtool_rx_ntuple) = 184
offsetof(ethtool_rx_ntuple, fs) = 8
offsetof(ethtool_rx_ntuple_flow_spec, vlan_tag) = 148
offsetof(ethtool_rx_ntuple_flow_spec, data) = 152
$ cc -m32 test.c
$ ./a.out
sizeof(struct ethtool_rx_ntuple) = 176
offsetof(ethtool_rx_ntuple, fs) = 4
offsetof(ethtool_rx_ntuple_flow_spec, vlan_tag) = 148
offsetof(ethtool_rx_ntuple_flow_spec, data) = 152

At least there's only one hole to deal with in this case.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.