* [PATCH] net: compat: Ignore MSG_CMSG_COMPAT in compat_sys_{send,recv}msg
@ 2015-02-12 12:28 Catalin Marinas
2015-02-12 16:41 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2015-02-12 12:28 UTC (permalink / raw)
To: netdev; +Cc: linux-kernel, Will Deacon, Andy Lutomirski, David S. Miller
With commit a7526eb5d06b (net: Unbreak compat_sys_{send,recv}msg), the
MSG_CMSG_COMPAT flag is blocked at the compat syscall entry points,
changing the kernel compat behaviour from the one before the commit it
was trying to fix (1be374a0518a, net: Block MSG_CMSG_COMPAT in
send(m)msg and recv(m)msg).
On 32-bit kernels (!CONFIG_COMPAT), MSG_CMSG_COMPAT is 0 and the native
32-bit sys_sendmsg() allows flag 0x80000000 to be set (it is ignored by
the kernel). However, on a 64-bit kernel, the compat ABI is different
with commit a7526eb5d06b.
This patch changes the compat_sys_{send,recv}msg behaviour to the one
prior to commit 1be374a0518a.
The problem was found running 32-bit LTP (sendmsg01) binary on an arm64
kernel. Arguably, LTP should not pass 0xffffffff as flags to sendmsg()
but the general rule is not to break user ABI (even when the user
behaviour is not entirely sane).
Fixes: a7526eb5d06b (net: Unbreak compat_sys_{send,recv}msg)
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---
net/compat.c | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/net/compat.c b/net/compat.c
index 3236b4167a32..94d3d5e97883 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -711,24 +711,18 @@ static unsigned char nas[21] = {
COMPAT_SYSCALL_DEFINE3(sendmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)
{
- if (flags & MSG_CMSG_COMPAT)
- return -EINVAL;
return __sys_sendmsg(fd, (struct user_msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
}
COMPAT_SYSCALL_DEFINE4(sendmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
unsigned int, vlen, unsigned int, flags)
{
- if (flags & MSG_CMSG_COMPAT)
- return -EINVAL;
return __sys_sendmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
flags | MSG_CMSG_COMPAT);
}
COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)
{
- if (flags & MSG_CMSG_COMPAT)
- return -EINVAL;
return __sys_recvmsg(fd, (struct user_msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
}
@@ -751,9 +745,6 @@ COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
int datagrams;
struct timespec ktspec;
- if (flags & MSG_CMSG_COMPAT)
- return -EINVAL;
-
if (timeout == NULL)
return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
flags | MSG_CMSG_COMPAT, NULL);
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] net: compat: Ignore MSG_CMSG_COMPAT in compat_sys_{send,recv}msg
2015-02-12 12:28 [PATCH] net: compat: Ignore MSG_CMSG_COMPAT in compat_sys_{send,recv}msg Catalin Marinas
@ 2015-02-12 16:41 ` David Miller
2015-02-12 17:32 ` Catalin Marinas
0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2015-02-12 16:41 UTC (permalink / raw)
To: catalin.marinas; +Cc: netdev, linux-kernel, will.deacon, luto
From: Catalin Marinas <catalin.marinas@arm.com>
Date: Thu, 12 Feb 2015 12:28:07 +0000
> With commit a7526eb5d06b (net: Unbreak compat_sys_{send,recv}msg), the
> MSG_CMSG_COMPAT flag is blocked at the compat syscall entry points,
> changing the kernel compat behaviour from the one before the commit it
> was trying to fix (1be374a0518a, net: Block MSG_CMSG_COMPAT in
> send(m)msg and recv(m)msg).
>
> On 32-bit kernels (!CONFIG_COMPAT), MSG_CMSG_COMPAT is 0 and the native
> 32-bit sys_sendmsg() allows flag 0x80000000 to be set (it is ignored by
> the kernel). However, on a 64-bit kernel, the compat ABI is different
> with commit a7526eb5d06b.
>
> This patch changes the compat_sys_{send,recv}msg behaviour to the one
> prior to commit 1be374a0518a.
>
> The problem was found running 32-bit LTP (sendmsg01) binary on an arm64
> kernel. Arguably, LTP should not pass 0xffffffff as flags to sendmsg()
> but the general rule is not to break user ABI (even when the user
> behaviour is not entirely sane).
>
> Fixes: a7526eb5d06b (net: Unbreak compat_sys_{send,recv}msg)
> Cc: Andy Lutomirski <luto@amacapital.net>
> Cc: David S. Miller <davem@davemloft.net>
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
I think this is a very poor LTP test.
Setting MSG_* bits that aren't supported by the protocol in any way
gives undefined semantics. You may get an error, it may be silently
ignored, etc.
I'm not applying this, sorry.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] net: compat: Ignore MSG_CMSG_COMPAT in compat_sys_{send,recv}msg
2015-02-12 16:41 ` David Miller
@ 2015-02-12 17:32 ` Catalin Marinas
2015-02-19 21:15 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2015-02-12 17:32 UTC (permalink / raw)
To: David Miller
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Will Deacon,
luto@amacapital.net
On Thu, Feb 12, 2015 at 04:41:24PM +0000, David Miller wrote:
> From: Catalin Marinas <catalin.marinas@arm.com>
> Date: Thu, 12 Feb 2015 12:28:07 +0000
>
> > With commit a7526eb5d06b (net: Unbreak compat_sys_{send,recv}msg), the
> > MSG_CMSG_COMPAT flag is blocked at the compat syscall entry points,
> > changing the kernel compat behaviour from the one before the commit it
> > was trying to fix (1be374a0518a, net: Block MSG_CMSG_COMPAT in
> > send(m)msg and recv(m)msg).
> >
> > On 32-bit kernels (!CONFIG_COMPAT), MSG_CMSG_COMPAT is 0 and the native
> > 32-bit sys_sendmsg() allows flag 0x80000000 to be set (it is ignored by
> > the kernel). However, on a 64-bit kernel, the compat ABI is different
> > with commit a7526eb5d06b.
> >
> > This patch changes the compat_sys_{send,recv}msg behaviour to the one
> > prior to commit 1be374a0518a.
> >
> > The problem was found running 32-bit LTP (sendmsg01) binary on an arm64
> > kernel. Arguably, LTP should not pass 0xffffffff as flags to sendmsg()
> > but the general rule is not to break user ABI (even when the user
> > behaviour is not entirely sane).
> >
> > Fixes: a7526eb5d06b (net: Unbreak compat_sys_{send,recv}msg)
> > Cc: Andy Lutomirski <luto@amacapital.net>
> > Cc: David S. Miller <davem@davemloft.net>
> > Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
>
> I think this is a very poor LTP test.
That I agree.
> Setting MSG_* bits that aren't supported by the protocol in any way
> gives undefined semantics. You may get an error, it may be silently
> ignored, etc.
>From the sendmsg(2) man page, if some bit in the flags is inappropriate
for the socket type, it should return -EOPNOTSUPP. But I can't tell
whether it refers only to bits which are defined (for other socket
types) or just any bit. The test itself checks for -EOPNOTSUPP but it
gets -EINVAL instead, hence the failure being reported.
> I'm not applying this, sorry.
What I'm after is consistency between the native 32-bit kernel and the
compat layer on 64-bit. On the former, bit 31 is silently ignored, on
the latter it reports -EINVAL.
We could as well do something like below but we end up with unnecessary
flags check on 32-bit. The question is whether such change would be
considered a 32-bit user ABI breakage.
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 6e49a14365dc..0b283397ca0a 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -272,11 +272,7 @@ struct ucred {
#define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exec for file
descriptor received through
SCM_RIGHTS */
-#if defined(CONFIG_COMPAT)
#define MSG_CMSG_COMPAT 0x80000000 /* This message needs 32 bit fixups */
-#else
-#define MSG_CMSG_COMPAT 0 /* We never have 32 bit fixups */
-#endif
/* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */
--
Catalin
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] net: compat: Ignore MSG_CMSG_COMPAT in compat_sys_{send,recv}msg
2015-02-12 17:32 ` Catalin Marinas
@ 2015-02-19 21:15 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2015-02-19 21:15 UTC (permalink / raw)
To: catalin.marinas; +Cc: netdev, linux-kernel, Will.Deacon, luto
From: Catalin Marinas <catalin.marinas@arm.com>
Date: Thu, 12 Feb 2015 17:32:18 +0000
> On Thu, Feb 12, 2015 at 04:41:24PM +0000, David Miller wrote:
>> Setting MSG_* bits that aren't supported by the protocol in any way
>> gives undefined semantics. You may get an error, it may be silently
>> ignored, etc.
>
> From the sendmsg(2) man page, if some bit in the flags is inappropriate
> for the socket type, it should return -EOPNOTSUPP. But I can't tell
> whether it refers only to bits which are defined (for other socket
> types) or just any bit. The test itself checks for -EOPNOTSUPP but it
> gets -EINVAL instead, hence the failure being reported.
Thanks for thinking about this a bit more. Yes, -EINVAL is probably
not the thing we should return in this situation.
>> I'm not applying this, sorry.
>
> What I'm after is consistency between the native 32-bit kernel and the
> compat layer on 64-bit. On the former, bit 31 is silently ignored, on
> the latter it reports -EINVAL.
>
> We could as well do something like below but we end up with unnecessary
> flags check on 32-bit. The question is whether such change would be
> considered a 32-bit user ABI breakage.
Ok, after some further consideration I like your original patch.
If 32-bit ignores the value, 64-bit should too. So just mask it out.
Please resubmit your original patch, I'll apply it, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-02-19 21:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-12 12:28 [PATCH] net: compat: Ignore MSG_CMSG_COMPAT in compat_sys_{send,recv}msg Catalin Marinas
2015-02-12 16:41 ` David Miller
2015-02-12 17:32 ` Catalin Marinas
2015-02-19 21:15 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox