can: raw: check for CAN FD capable netdev in raw_sendmsg()
When the socket is CAN FD enabled it can handle CAN FD frame transmissions. Add an additional check in raw_sendmsg() as a CAN2.0 CAN driver (non CAN FD) should never see a CAN FD frame. Due to the commonly used can_dropped_invalid_skb() function the CAN 2.0 driver would drop that CAN FD frame anyway - but with this patch the user gets a proper -EINVAL return code. Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Cc: linux-stable <stable@vger.kernel.org> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
parent
85b18b0237
commit
a43608fa77
|
@ -745,18 +745,19 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
|
||||||
} else
|
} else
|
||||||
ifindex = ro->ifindex;
|
ifindex = ro->ifindex;
|
||||||
|
|
||||||
if (ro->fd_frames) {
|
|
||||||
if (unlikely(size != CANFD_MTU && size != CAN_MTU))
|
|
||||||
return -EINVAL;
|
|
||||||
} else {
|
|
||||||
if (unlikely(size != CAN_MTU))
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
dev = dev_get_by_index(sock_net(sk), ifindex);
|
dev = dev_get_by_index(sock_net(sk), ifindex);
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return -ENXIO;
|
return -ENXIO;
|
||||||
|
|
||||||
|
err = -EINVAL;
|
||||||
|
if (ro->fd_frames && dev->mtu == CANFD_MTU) {
|
||||||
|
if (unlikely(size != CANFD_MTU && size != CAN_MTU))
|
||||||
|
goto put_dev;
|
||||||
|
} else {
|
||||||
|
if (unlikely(size != CAN_MTU))
|
||||||
|
goto put_dev;
|
||||||
|
}
|
||||||
|
|
||||||
skb = sock_alloc_send_skb(sk, size + sizeof(struct can_skb_priv),
|
skb = sock_alloc_send_skb(sk, size + sizeof(struct can_skb_priv),
|
||||||
msg->msg_flags & MSG_DONTWAIT, &err);
|
msg->msg_flags & MSG_DONTWAIT, &err);
|
||||||
if (!skb)
|
if (!skb)
|
||||||
|
|
Loading…
Reference in New Issue