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: e057dd3fc2
("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 <derekrobertwill@gmail.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
8a9d996d4e
commit
f402c49865
@@ -1003,12 +1003,16 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
|
|||||||
{
|
{
|
||||||
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
|
struct isotp_sock *so = isotp_sk(sk);
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int noblock;
|
int noblock;
|
||||||
|
|
||||||
noblock = flags & MSG_DONTWAIT;
|
noblock = flags & MSG_DONTWAIT;
|
||||||
flags &= ~MSG_DONTWAIT;
|
flags &= ~MSG_DONTWAIT;
|
||||||
|
|
||||||
|
if (!so->bound)
|
||||||
|
return -EADDRNOTAVAIL;
|
||||||
|
|
||||||
skb = skb_recv_datagram(sk, flags, noblock, &err);
|
skb = skb_recv_datagram(sk, flags, noblock, &err);
|
||||||
if (!skb)
|
if (!skb)
|
||||||
return err;
|
return err;
|
||||||
|
Reference in New Issue
Block a user