hartkopp / can-isotp

Linux Kernel Module for ISO 15765-2:2016 CAN transport protocol PLEASE NOTE: This module is part of the mainline Linux kernel since version 5.10
Other
239 stars 69 forks source link

MSG_CMSG_COMPAT set by the kernel for `recvmsg` #59

Closed ghost closed 9 months ago

ghost commented 1 year ago

Hi, not sure if this is the right place for this issue, but I've encountered a problem with more recent kernels > 5.10 on ARM64 machines.

On any recvmsg call from the kernel, the flag MSG_CMSG_COMPAT is set on my machine, which results in EINVAL on this line: https://github.com/hartkopp/can-isotp/blob/7626d0a0707391970080d493ce69638719938da7/net/can/isotp.c#L1057

The issue can be reproduced on any Raspberry PI 4 with the latest kernel.

One remark, isotprecv is not affected by this issue, since it uses read and not recvmsg.

I propose to add this flag to this line: https://github.com/hartkopp/can-isotp/blob/7626d0a0707391970080d493ce69638719938da7/net/can/isotp.c#L1057

ghost commented 1 year ago

For reference, I guess the issue comes from this line: https://elixir.bootlin.com/linux/latest/source/net/compat.c#L507

hartkopp commented 1 year ago

@marckleinebudde @olerem : Using MSG_CMSG_COMPAT in recvmsg flags seems to be a common pattern, e.g. in af_packet.c or bluetooth/hci_sock.c .

I don't see any 'special' handlings in cmsg's in isotp.c but some special created cmsg's in j1939/socket.c (search for put_cmsg()).

Do you see any problems with adding the MSG_CMSG_COMPAT flag in recvmsg flags ?

diff --git a/net/can/isotp.c b/net/can/isotp.c
index 9bc344851704..fd0e297a8584 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1099,11 +1099,11 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
        struct sock *sk = sock->sk;
        struct sk_buff *skb;
        struct isotp_sock *so = isotp_sk(sk);
        int ret = 0;

-       if (flags & ~(MSG_DONTWAIT | MSG_TRUNC | MSG_PEEK))
+       if (flags & ~(MSG_DONTWAIT | MSG_TRUNC | MSG_PEEK | MSG_CMSG_COMPAT))
                return -EINVAL;

        if (!so->bound)
                return -EADDRNOTAVAIL;

diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index 7e90f9e61d9b..1790469b2580 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -796,11 +796,11 @@ static int j1939_sk_recvmsg(struct socket *sock, struct msghdr *msg,
        struct sock *sk = sock->sk;
        struct sk_buff *skb;
        struct j1939_sk_buff_cb *skcb;
        int ret = 0;

-       if (flags & ~(MSG_DONTWAIT | MSG_ERRQUEUE))
+       if (flags & ~(MSG_DONTWAIT | MSG_ERRQUEUE | MSG_CMSG_COMPAT))
                return -EINVAL;

        if (flags & MSG_ERRQUEUE)
                return sock_recv_errqueue(sock->sk, msg, size, SOL_CAN_J1939,
                                          SCM_J1939_ERRQUEUE);
marckleinebudde commented 1 year ago

Hi, not sure if this is the right place for this issue, but I've encountered a problem with more recent kernels > 5.10 on ARM64 machines.

On any recvmsg call from the kernel, the flag MSG_CMSG_COMPAT is set on my machine, which results in EINVAL on this line:

Are you using a 32 bit userspace?

ghost commented 1 year ago

Yes, I‘m using a 32bit userspace.

-- Mit freundlichen Grüßen

Dr. Nils Weiß

dissecto GmbH Franz-Mayer-Str. 1 93053 Regensburg


From: Marc Kleine-Budde @.> Sent: Wednesday, April 5, 2023 11:37:21 AM To: hartkopp/can-isotp @.> Cc: Nils Weiß @.>; Author @.> Subject: Re: [hartkopp/can-isotp] MSG_CMSG_COMPAT set by the kernel for recvmsg (Issue #59)

Hi, not sure if this is the right place for this issue, but I've encountered a problem with more recent kernels > 5.10 on ARM64 machines.

On any recvmsg call from the kernel, the flag MSG_CMSG_COMPAT is set on my machine, which results in EINVAL on this line:

Are you using a 32 bit userspace?

— Reply to this email directly, view it on GitHubhttps://github.com/hartkopp/can-isotp/issues/59#issuecomment-1497200119, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A6YQZC5XSY2UE5YJZ2MLZ23W7U4NDANCNFSM6AAAAAAWM4FAJQ. You are receiving this because you authored the thread.Message ID: @.***>

marckleinebudde commented 1 year ago

Yes, I‘m using a 32bit userspace.

This is where the MSG_CMSG_COMPAT comes from.

marckleinebudde commented 1 year ago

@marckleinebudde @olerem : Using MSG_CMSG_COMPAT in recvmsg flags seems to be a common pattern, e.g. in af_packet.c or bluetooth/hci_sock.c .

I don't see any 'special' handlings in cmsg's in isotp.c but some special created cmsg's in j1939/socket.c (search for put_cmsg()).

Looks good send a patch.

hartkopp commented 9 months ago

Has been fixed in mainline Linux and stable kernels.