Skip to contentSkip to conversation

ip xfrm: support 64bit kernel and 32bit userspace

PATCH In review [email protected] 5 participants 7 messages Nov 28, 2014 – Nov 30, 2014

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

PATCH 1/1 ip xfrm: support 64bit kernel and 32bit userspace

From: Li RongQing <[email protected]>

The size of struct xfrm_userpolicy_info is 168 bytes for 64bit kernel, and 164 bytes for 32bit userspace because of the different alignment. and lead to "ip xfrm" be unable to work.

add a pad in struct xfrm_userpolicy_info, and enable it by set KERNEL_64_USERSPACE_32 to y

---
 Makefile             | 4 ++++
 include/linux/xfrm.h | 3 +++
 2 files changed, 7 insertions(+)
Makefile +4 -0
index 9dbb29f..3cd0d67 100644
@@ -18,6 +18,10 @@ ifneq ($(SHARED_LIBS),y)
 DEFINES+= -DNO_SHARED_LIBS
 endif
 
+ifeq ($(KERNEL_64_USERSPACE_32),y)
+DEFINES+= -DKNL_64_US_32
+endif
+
 DEFINES+=-DCONFDIR=\"$(CONFDIR)\"
 
 #options for decnet
include/linux/xfrm.h +3 -0
index fa2ecb2..009510c 100644
@@ -407,6 +407,9 @@ struct xfrm_userpolicy_info {
 	/* Automatically expand selector to include matching ICMP payloads. */
 #define XFRM_POLICY_ICMP	2
 	__u8				share;
+#ifdef KNL_64_US_32
+	int				pad;
+#endif
 };
 
 struct xfrm_userpolicy_id {
Signature · 1 line
2.1.0
#1 lore raw
Quoted 8 lines · 于 2014年11月28日 14:58, [email protected] 写道:

From: Li RongQing<[email protected]>

The size of struct xfrm_userpolicy_info is 168 bytes for 64bit kernel, and 164 bytes for 32bit userspace because of the different alignment. and lead to "ip xfrm" be unable to work.

add a pad in struct xfrm_userpolicy_info, and enable it by set KERNEL_64_USERSPACE_32 to y

It's not easy to fix it like this.

Refer:
http://marc.info/?l=linux-netdev&m=139280143513650&w=2
http://thread.gmane.org/gmane.linux.network/157118/focus=157122

#2 lore raw
Quoted 11 lines · FengYu LeiDian
Quoted 8 lines · 于 2014年11月28日 14:58, [email protected] 写道:

From: Li RongQing<[email protected]>

The size of struct xfrm_userpolicy_info is 168 bytes for 64bit kernel, and 164 bytes for 32bit userspace because of the different alignment. and lead to "ip xfrm" be unable to work.

add a pad in struct xfrm_userpolicy_info, and enable it by set KERNEL_64_USERSPACE_32 to y

Quoted 6 lines

It's not easy to fix it like this.

Refer:
http://marc.info/?l=linux-netdev&m=139280143513650&w=2
http://thread.gmane.org/gmane.linux.network/157118/focus=157122

is it be practical to find all structures which has the issue for 64bit kernel and 32 bit
userspace, and conditionally add a pad for them

-Roy

#3 lore raw
Quoted 15 lines · Li RongQing
Quoted 13 lines · FengYu LeiDian
Quoted 13 lines
Quoted 8 lines · 于 2014年11月28日 14:58,[email protected] 写道:
Quoted 8 lines

From: Li RongQing<[email protected]>

The size of struct xfrm_userpolicy_info is 168 bytes for 64bit kernel, and 164 bytes for 32bit userspace because of the different alignment. and lead to "ip xfrm" be unable to work.

add a pad in struct xfrm_userpolicy_info, and enable it by set KERNEL_64_USERSPACE_32 to y

It's not easy to fix it like this.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

Refer:
http://marc.info/?l=linux-netdev&m=139280143513650&w=2
http://thread.gmane.org/gmane.linux.network/157118/focus=157122

is it be practical to find all structures which has the issue for 64bit kernel and 32 bit
userspace, and conditionally add a pad for them

Apparently struct xfrm_userpolicy_info is not the only one, you could try to set SA as well, it breaks also... Fix those where it hurts, hehe :) Otherwise, the "compat layer" fix style is good choice.

#4 lore raw
In reply to [email protected]

From: [email protected]

Quoted 8 lines

From: Li RongQing <[email protected]>

The size of struct xfrm_userpolicy_info is 168 bytes for 64bit kernel, and 164 bytes for 32bit userspace because of the different alignment. and lead to "ip xfrm" be unable to work.

add a pad in struct xfrm_userpolicy_info, and enable it by set KERNEL_64_USERSPACE_32 to y

...

include/linux/xfrm.h struct xfrm_userpolicy_info { · line 413

Quoted 12 lines
include/linux/xfrm.h +3 -0
index fa2ecb2..009510c 100644
@@ -407,6 +407,9 @@ struct xfrm_userpolicy_info {
 	/* Automatically expand selector to include matching ICMP payloads. */
 #define XFRM_POLICY_ICMP	2
 	__u8				share;
+#ifdef KNL_64_US_32
+	int				pad;
+#endif
 };

You could add __attribute__((aligned(8))) to the structure to pad it on all systems.

Or find the 64bit member and add __attribute__((aligned(4))) to that member so that the 64bit version doesn't get padded.
That will make the field more expensive to access on systems that can't do misaligned memory transfers.

David

#5 lore raw
In reply to [email protected]
Quoted 4 lines · On Fri, 2014-11-28 at 14:58 +0800, [email protected] wrote:

From: Li RongQing <[email protected]>

The size of struct xfrm_userpolicy_info is 168 bytes for 64bit kernel, and 164 bytes for 32bit userspace because of the different alignment.

I think it's specific to x86 as other architectures have the same type alignments for 32- and 64-bit variants.

Quoted 4 lines

and lead to "ip xfrm" be unable to work.

add a pad in struct xfrm_userpolicy_info, and enable it by set KERNEL_64_USERSPACE_32 to y

[...]

This doesn't make sense. 32-bit compat needs to work like 32-bit native
- no exceptions, no workarounds in userland. And if you really want to work around this in userland you'll need a run-time, not compile-time, check.

Ben.

Signature · 2 lines
Ben Hutchings
The world is coming to an end.	Please log off.
#6 lore raw
Quoted 11 lines · On Sun, 30 Nov 2014 01:33:22 +0000 Ben Hutchings <[email protected]> wrote:
Quoted 4 lines · On Fri, 2014-11-28 at 14:58 +0800, [email protected] wrote:

From: Li RongQing <[email protected]>

The size of struct xfrm_userpolicy_info is 168 bytes for 64bit kernel, and 164 bytes for 32bit userspace because of the different alignment.

I think it's specific to x86 as other architectures have the same type alignments for 32- and 64-bit variants.

Quoted 2 lines

and lead to "ip xfrm" be unable to work.

Quoted 8 lines
Quoted 2 lines

add a pad in struct xfrm_userpolicy_info, and enable it by set KERNEL_64_USERSPACE_32 to y

[...]

This doesn't make sense. 32-bit compat needs to work like 32-bit native
- no exceptions, no workarounds in userland. And if you really want to work around this in userland you'll need a run-time, not compile-time, check.

I agree with Ben, this is not a good solution.
It creates a 3rd ABI (32, 64, and 32/64).