can: raw: instantly reject disabled CAN frames
For real CAN interfaces the CAN_CTRLMODE_FD and CAN_CTRLMODE_XL control
modes indicate whether an interface can handle those CAN FD/XL frames.
In the case a CAN XL interface is configured in CANXL-only mode with
disabled error-signalling neither CAN CC nor CAN FD frames can be sent.
The checks are now performed on CAN_RAW sockets to give an instant feedback
to the user when writing unsupported CAN frames to the interface or when
the CAN interface is in read-only mode.
Fixes: 1a620a7238 ("can: raw: instantly reject unsupported CAN frames")
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20260109144135.8495-4-socketcan@hartkopp.net
[mkl: fix dev reference leak]
Link: https://lore.kernel.org/all/0636c732-2e71-4633-8005-dfa85e1da445@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
pull/1258/merge
parent
166e87329c
commit
faba5860fc
|
|
@ -49,8 +49,8 @@
|
|||
#include <linux/if_arp.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/can.h>
|
||||
#include <linux/can/can-ml.h>
|
||||
#include <linux/can/core.h>
|
||||
#include <linux/can/dev.h> /* for can_is_canxl_dev_mtu() */
|
||||
#include <linux/can/skb.h>
|
||||
#include <linux/can/raw.h>
|
||||
#include <net/sock.h>
|
||||
|
|
@ -892,20 +892,21 @@ static void raw_put_canxl_vcid(struct raw_sock *ro, struct sk_buff *skb)
|
|||
}
|
||||
}
|
||||
|
||||
static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff *skb, int mtu)
|
||||
static unsigned int raw_check_txframe(struct raw_sock *ro, struct sk_buff *skb,
|
||||
struct net_device *dev)
|
||||
{
|
||||
/* Classical CAN -> no checks for flags and device capabilities */
|
||||
if (can_is_can_skb(skb))
|
||||
/* Classical CAN */
|
||||
if (can_is_can_skb(skb) && can_cap_enabled(dev, CAN_CAP_CC))
|
||||
return CAN_MTU;
|
||||
|
||||
/* CAN FD -> needs to be enabled and a CAN FD or CAN XL device */
|
||||
/* CAN FD */
|
||||
if (ro->fd_frames && can_is_canfd_skb(skb) &&
|
||||
(mtu == CANFD_MTU || can_is_canxl_dev_mtu(mtu)))
|
||||
can_cap_enabled(dev, CAN_CAP_FD))
|
||||
return CANFD_MTU;
|
||||
|
||||
/* CAN XL -> needs to be enabled and a CAN XL device */
|
||||
/* CAN XL */
|
||||
if (ro->xl_frames && can_is_canxl_skb(skb) &&
|
||||
can_is_canxl_dev_mtu(mtu))
|
||||
can_cap_enabled(dev, CAN_CAP_XL))
|
||||
return CANXL_MTU;
|
||||
|
||||
return 0;
|
||||
|
|
@ -944,6 +945,12 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
|
|||
if (!dev)
|
||||
return -ENXIO;
|
||||
|
||||
/* no sending on a CAN device in read-only mode */
|
||||
if (can_cap_enabled(dev, CAN_CAP_RO)) {
|
||||
err = -EACCES;
|
||||
goto put_dev;
|
||||
}
|
||||
|
||||
skb = sock_alloc_send_skb(sk, size + sizeof(struct can_skb_priv),
|
||||
msg->msg_flags & MSG_DONTWAIT, &err);
|
||||
if (!skb)
|
||||
|
|
@ -961,7 +968,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
|
|||
err = -EINVAL;
|
||||
|
||||
/* check for valid CAN (CC/FD/XL) frame content */
|
||||
txmtu = raw_check_txframe(ro, skb, READ_ONCE(dev->mtu));
|
||||
txmtu = raw_check_txframe(ro, skb, dev);
|
||||
if (!txmtu)
|
||||
goto free_skb;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue