From: Oliver Hartkopp Date: Wed, 16 Mar 2022 16:42:57 +0000 (+0100) Subject: can: isotp: return -EADDRNOTAVAIL when reading from unbound socket X-Git-Tag: v5.15.73~5683 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=05e4e7d9bbb3cbdc1eeb65ddf439f28edfdf38c2;p=platform%2Fkernel%2Flinux-rpi.git can: isotp: return -EADDRNOTAVAIL when reading from unbound socket [ Upstream commit 30ffd5332e06316bd69a654c06aa033872979b7c ] When reading from an unbound can-isotp socket the syscall blocked indefinitely. As unbound sockets (without given CAN address information) do not make sense anyway we directly return -EADDRNOTAVAIL on read() analogue to the known behavior from sendmsg(). Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol") Link: https://github.com/linux-can/can-utils/issues/349 Link: https://lore.kernel.org/all/20220316164258.54155-2-socketcan@hartkopp.net Suggested-by: Derek Will Signed-off-by: Oliver Hartkopp Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- diff --git a/net/can/isotp.c b/net/can/isotp.c index f8e3aeb..8966f06 100644 --- a/net/can/isotp.c +++ b/net/can/isotp.c @@ -1005,12 +1005,16 @@ 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 err = 0; int noblock; noblock = flags & MSG_DONTWAIT; flags &= ~MSG_DONTWAIT; + if (!so->bound) + return -EADDRNOTAVAIL; + skb = skb_recv_datagram(sk, flags, noblock, &err); if (!skb) return err;