can: ems_usb: validate CPC message lengths
Subsystems (4)
PATCH 1/1 can: ems_usb: validate CPC message lengths
From: Pengpeng Hou <[email protected]>
commit 02925f51377f2a42a6724f00549167499c9302e5 upstream.
ems_usb_read_bulk_callback() walks CPC messages packed in one USB receive buffer.
Check that each declared message fits in the URB payload. Also require the type-specific payload to cover the fields used by the CAN, state, error and overrun handlers.
Signed-off-by Pengpeng Hou <[email protected]>
Fixes 702171adeed3 ("ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface")
Signed-off-by Marc Kleine-Budde <[email protected]>
[Denis Arefev: adapted for 5.10: use get_can_dlc() instead of
can_cc_dlc2len(), the latter was introduced in 6.x along with include/linux/can/length.h; get_can_dlc() has identical semantics for classic CAN frames (min(dlc, CAN_MAX_DLEN))]
Signed-off-by Denis Arefev <[email protected]>
---
Backport fix for CVE-2026-74460
--- drivers/net/can/usb/ems_usb.c | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
drivers/net/can/usb/ems_usb.c +43 -0
@@ -402,6 +402,40 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg)netif_rx (skb); } +static bool ems_usb_rx_msg_len_valid (struct ems_cpc_msg *msg) +{ +size_t len = msg->length; +size_t can_len; + +switch (msg->type) { +case CPC_MSG_TYPE_CAN_STATE : +return len >=sizeof (msg->msg.can_state); + +case CPC_MSG_TYPE_CAN_FRAME : +case CPC_MSG_TYPE_EXT_CAN_FRAME : +case CPC_MSG_TYPE_RTR_FRAME : +case CPC_MSG_TYPE_EXT_RTR_FRAME : +if (len <CPC_CAN_MSG_MIN_SIZE ) +return false; + +if (msg->type ==CPC_MSG_TYPE_RTR_FRAME || + msg->type ==CPC_MSG_TYPE_EXT_RTR_FRAME ) +return true; + + can_len =get_can_dlc (msg->msg.can_msg.length &0xf ); +return len >=CPC_CAN_MSG_MIN_SIZE + can_len; + +case CPC_MSG_TYPE_CAN_FRAME_ERROR : +return len >=sizeof (msg->msg.error); + +case CPC_MSG_TYPE_OVERRUN : +return len >=sizeof (msg->msg.overrun); + +default : +return true; + } +} +/* * callback for bulk IN urb */
@@ -444,6 +478,15 @@ static void ems_usb_read_bulk_callback(struct urb *urb) } msg = (struct ems_cpc_msg *)&ibuf[start]; +if (msg->length > + urb->actual_length - start -CPC_MSG_HEADER_LEN ) { +netdev_err (netdev,"format error\n" ); +break ; + } +if (!ems_usb_rx_msg_len_valid (msg)) { +netdev_err (netdev,"format error\n" ); +break ; + }switch (msg->type) {case CPC_MSG_TYPE_CAN_STATE :
Signature · 1 line
2.43.0