x86, fs: add sys_compat_write for net/socket.c
Subsystems (3)
Quoted 15 lines · Florian Westphal
On some configurations, e.g.
x86_64with 32bit userspace, netlink/xfrm misinterprets messages from userspace due to different structure layout (u64 has different alignment requirements on x86 vs.x86_64).As long as messages are sent via
sendmsg(), this could be handled vianet/compat.c; it will set theCMSG_MSG_COMPATflag in struct msghdr for compat tasks, which would allow to thexfrm_usercode to detect when messages need compat fixups.Unfortunately, some programs (e.g. pluto ike daemon), send netlink data to the kernel using
write().Thus, introduce
f_ops->compat_aio_writeandcompat_sys_writeto treat writes on sockets specially.
Quoted 8 lines
This only wires up
compat_sys_writefor x86/x86_64 -- at the moment this is only required to parse xfrm netlink messages, which happen to only need special treatment in case of COMPAT_FOR_U64_ALIGNMENT=y.Setting
CMSG_MSG_COMPATdepending on plainis_compat_task()innet/socket.cwas not done due to concerns regarding the kernel doing socket writes in response to a user event (which might setMSG_COMPATerronously).
OK... I have to ask the question:
This only applies if you're using unpacked structures with non-naturally-aligned objects in them. Where to we have those, and can we shoot the authors?
-hpa
Quoted 3 lines · H. Peter Anvin
Quoted 3 lines
On some configurations, e.g.
x86_64with 32bit userspace, netlink/xfrm misinterprets messages from userspace due to different structure layout (u64 has different alignment requirements on x86 vs.x86_64).
[..]
Quoted 20 lines
Quoted 11 lines
As long as messages are sent via
sendmsg(), this could be handled vianet/compat.c; it will set theCMSG_MSG_COMPATflag in struct msghdr for compat tasks, which would allow to thexfrm_usercode to detect when messages need compat fixups.Unfortunately, some programs (e.g. pluto ike daemon), send netlink data to the kernel using
write().Thus, introduce
f_ops->compat_aio_writeandcompat_sys_writeto treat writes on sockets specially.Quoted 8 lines
This only wires up
compat_sys_writefor x86/x86_64 -- at the moment this is only required to parse xfrm netlink messages, which happen to only need special treatment in case of COMPAT_FOR_U64_ALIGNMENT=y.Setting
CMSG_MSG_COMPATdepending on plainis_compat_task()innet/socket.cwas not done due to concerns regarding the kernel doing socket writes in response to a user event (which might setMSG_COMPATerronously).
Quoted 5 lines
OK... I have to ask the question:
This only applies if you're using unpacked structures with non-naturally-aligned objects in them. Where to we have those, and can we shoot the authors?
Fair enough.
This happens e.g. when trying to add xfrm policies or SAs from 32bit x86 userspace on x86_64 kernels, e.g. commands like "ip xfrm pol add dir in" fail due to user/kernelspace structure size mismatch.
One structure that has this problem is struct xfrm_userpolicy_info, but there are more.
Now, I realize that adding a write compat syscall is borderline insanity, and I am open to suggestions.
In fact, I would even accept a "userspace must use sendmsg() when dealing with xfrm netlink"; the only problem is that my pending xfrm compat patches depend on this patch being accepted [ or, rather, they depend
on the MSG_COMPAT flag being set; which is currently only done when userspace uses sendmsg().
In fact, "ip xfrm .. " even works with the xfrm compat patch set applied because ip xfrm ... happens to use sendmsg(). But not all userspace apps do this ].
Thanks, Florian
Quoted 2 lines · On Tuesday 30 March 2010 20:17:57 Florian Westphal wrote:
Now, I realize that adding a write compat syscall is borderline insanity, and I am open to suggestions.
Another option, which may be marginally better, would be to redefine the data structures to be compatible, and assign them new numbers, with kernel compat support for the numbers in x86-32 binaries.
If you manually add padding to the new data structures in the places that the other architectures have implicit padding, the hack will only be needed on x86-32 and compat x86-64.
The obvious disadvantage is that you need to recompile the x86-32 binaries to work in compat mode.
Arnd