Skip to contentSkip to conversation

can: allow MSG_CMSG_COMPAT flag in recvmsg() syscalls

PATCH In review Oliver Hartkopp 3 participants 4 messages Apr 6, 2023 – May 5, 2023

Subsystems (3)
lore
Share & tools
lore

Oliver Hartkopp

author maintainer
#0 lore raw

PATCH 1/1 can: allow MSG_CMSG_COMPAT flag in recvmsg() syscalls

The control messages provided by j1939 and isotp support MSG_CMSG_COMPAT but blocked recvmsg() syscalls that have set this flag, e.g. on 32bit ARM systems.

---
 net/can/isotp.c        | 2 +-
 net/can/j1939/socket.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/can/isotp.c +1 -1
index 9bc344851704..fd0e297a8584 100644
@@ -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;
 
net/can/j1939/socket.c +1 -1
index 7e90f9e61d9b..1790469b2580 100644
@@ -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);
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

I should probably split this into two patches when thinking of stable kernels.

E.g. we have to handle two "Fixes:" tags here:

Fixes 42bf50a1795a ("can: isotp: support MSG_TRUNC flag when reading from socket")
Fixes 9d71dd0c7009 ("can: add support of SAE J1939 protocol")

@Oleksij: Can you please check if adding this flag is fine for you too - and if you can "ack" it?

Thanks,
Oliver

Quoted 47 lines · Oliver Hartkopp

The control messages provided by j1939 and isotp support MSG_CMSG_COMPAT but blocked recvmsg() syscalls that have set this flag, e.g. on 32bit ARM systems.

---
  net/can/isotp.c        | 2 +-
  net/can/j1939/socket.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
net/can/isotp.c +1 -1
index 9bc344851704..fd0e297a8584 100644
@@ -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;
 
net/can/j1939/socket.c +1 -1
index 7e90f9e61d9b..1790469b2580 100644
@@ -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);
#2 lore raw
Quoted 2 lines · Oliver Hartkopp

I should probably split this into two patches when thinking of stable kernels.

+1

Quoted 9 lines

E.g. we have to handle two "Fixes:" tags here:

Fixes 42bf50a1795a ("can: isotp: support MSG_TRUNC flag when reading from

socket")

Fixes 9d71dd0c7009 ("can: add support of SAE J1939 protocol")

@Oleksij: Can you please check if adding this flag is fine for you too - and if you can "ack" it?

Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |
maintainer Tested-by Acked-by
#3 lore raw
In reply to Oliver Hartkopp

Hi Oliver,

Sorry for long delay.

Quoted 2 lines · Oliver Hartkopp

I should probably split this into two patches when thinking of stable kernels.

yes, please.

Quoted 9 lines

E.g. we have to handle two "Fixes:" tags here:

Fixes 42bf50a1795a ("can: isotp: support MSG_TRUNC flag when reading from

socket")

Fixes 9d71dd0c7009 ("can: add support of SAE J1939 protocol")

@Oleksij: Can you please check if adding this flag is fine for you too - and if you can "ack" it?

I tested it on imx8mp with 64bit kernel and 32bit user space. Without this patch "j1939spy -P vcan0" is not working. So, here is my:

Thank you!

Regards,
Oleksij

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |