From nobody Thu Oct 2 09:22:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA3CB2F60DB; Thu, 18 Sep 2025 09:01:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758186109; cv=none; b=qjp1h7sR+egoEbwz1MD4uTOo14U493OPyDExj76G8mEb/xRcckuocJ2cnArn+efMigrGhwXZCmcJ4y/w2p5hvZ7SAuSuQ5OUydSgmUCpIUPJZNCm+AjuREG5QrBQHBjNZIbS4swaeqxpYCm2kmH7AhK1eLN/GuF7FiwW8gxdV8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758186109; c=relaxed/simple; bh=99bx0qqju2UEGVzQhTUbxA8T28JN+IzFGx/ISmPcSf4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AYqO7DXrVnNYap4cc0EhfFX/YodLsBMBG+pxqpzEcWA3DG7ywJah1qQ2ox/qHgD3zhJU2aUduDya1RIGm89l82msm3y8TrkM0Xv7P4eUz8UeycIa1aWYVhd6TdQctm7m2hSmeO2/CDNqFl8YJHNJ8LrvzhxhCNpWY1J/KJN0kgs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kH+ibA9R; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kH+ibA9R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25FDEC4CEFB; Thu, 18 Sep 2025 09:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758186109; bh=99bx0qqju2UEGVzQhTUbxA8T28JN+IzFGx/ISmPcSf4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kH+ibA9RimkNjlWOzcnxzqAitYkbqRM5/CJfNWkcORvEWN9WrfPs8ShwdVZHY0ET3 DLo1QhJc6/oze4/74DjYNN8TRgrCK/l3COjFnV8n7+Cb0C76nbjjg5bLHij0GzSZ2h 3TzKGnZ4WY4B3caZ7HLMNfTyU7WWFBW+sgPjl4rbvLNu3hQ7JEyvZH3WeEu3UqQGUC +lVV80yrpLw0iCThDxCePzELPZvmE9Qt7Qv1kzE1/HvHhjdShe+zyG+BCfqghLPFHg kCnA4lxvwsVx2dBT2BfC2qB6iPC/ajxONhI0ZVxe0xS4pkQ+TxtzURGaqrSW9DlEEr R0u3OoKCTs/pw== From: Vincent Mailhol Date: Thu, 18 Sep 2025 18:00:24 +0900 Subject: [PATCH 1/4] can: etas_es58x: populate ndo_change_mtu() to prevent buffer overflow Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250918-can-fix-mtu-v1-1-0d1cada9393b@kernel.org> References: <20250918-can-fix-mtu-v1-0-0d1cada9393b@kernel.org> In-Reply-To: <20250918-can-fix-mtu-v1-0-0d1cada9393b@kernel.org> To: Marc Kleine-Budde , Oliver Hartkopp Cc: Arunachalam Santhanam , Akshay Bhat , Wolfgang Grandegger , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Gerhard Bertelsmann , Yasushi SHOJI , =?utf-8?q?Remigiusz_Ko=C5=82=C5=82=C4=85taj?= , linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3267; i=mailhol@kernel.org; h=from:subject:message-id; bh=99bx0qqju2UEGVzQhTUbxA8T28JN+IzFGx/ISmPcSf4=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDBmnT+U6it09XHjp1J2k1U/PXLpx2WKK4Pf+wt9vFizWt tKrNly6rKOUhUGMi0FWTJFlWTknt0JHoXfYob+WMHNYmUCGMHBxCsBEinsZ/keu99z6r3fH53Xz J7b6aCTJxvsI/W2Yd9en/DqfW7nGEWGG36xXD6w/bl9nMtfX9BXD1goJ7rAF0u+3Lwn/m6bGmn2 cjQMA X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 Sending an PF_PACKET allows to bypass the CAN framework logic and to directly reach the xmit() function of a CAN driver. The only check which is performed by the PF_PACKET framework is to make sure that skb->len fits the interface's MTU. Unfortunately, because the etas_es58x driver does not populate its net_device_ops->ndo_change_mtu(), it is possible for an attacker to configure an invalid MTU by doing, for example: $ ip link set can0 mtu 9999 After doing so, the attacker could open a PF_PACKET socket using the ETH_P_CANXL protocol: socket(PF_PACKET, SOCK_RAW, htons(ETH_P_CANXL)); to inject a malicious CAN XL frames. For example: struct canxl_frame frame =3D { .flags =3D 0xff, .len =3D 2048, }; The CAN drivers' xmit() function are calling can_dev_dropped_skb() to check that the skb is valid, unfortunately under above conditions, the malicious packet is able to go through can_dev_dropped_skb() checks: 1. the skb->protocol is set to ETH_P_CANXL which is valid (the function does not check the actual device capabilities). 2. the length is a valid CAN XL length. And so, es58x_start_xmit() receives a CAN XL frame which it is not able to correctly handle and will thus misinterpret it as a CAN(FD) frame. This can result in a buffer overflow. For example, using the es581.4 variant, the frame will be dispatched to es581_4_tx_can_msg(), go through the last check at the beginning of this function: if (can_is_canfd_skb(skb)) return -EMSGSIZE; and reach this line: memcpy(tx_can_msg->data, cf->data, cf->len); Here, cf->len corresponds to the flags field of the CAN XL frame. In our previous example, we set canxl_frame->flags to 0xff. Because the maximum expected length is 8, a buffer overflow of 247 bytes occurs! Populate net_device_ops->ndo_change_mtu() to ensure that the interface's MTU can not be set to anything bigger than CAN_MTU or CANFD_MTU (depending on the device capabilities). By fixing the root cause, this prevents the buffer overflow. Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN = USB interfaces") Signed-off-by: Vincent Mailhol --- drivers/net/can/usb/etas_es58x/es58x_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/= usb/etas_es58x/es58x_core.c index db1acf6d504cf37cec724d392c9f7fee2d1f6045..adc91873c083f968ff7571a5b0d= b5747988482c5 100644 --- a/drivers/net/can/usb/etas_es58x/es58x_core.c +++ b/drivers/net/can/usb/etas_es58x/es58x_core.c @@ -7,7 +7,7 @@ * * Copyright (c) 2019 Robert Bosch Engineering and Business Solutions. All= rights reserved. * Copyright (c) 2020 ETAS K.K.. All rights reserved. - * Copyright (c) 2020-2022 Vincent Mailhol + * Copyright (c) 2020-2025 Vincent Mailhol */ =20 #include @@ -1977,6 +1977,7 @@ static const struct net_device_ops es58x_netdev_ops = =3D { .ndo_stop =3D es58x_stop, .ndo_start_xmit =3D es58x_start_xmit, .ndo_eth_ioctl =3D can_eth_ioctl_hwts, + .ndo_change_mtu =3D can_change_mtu, }; =20 static const struct ethtool_ops es58x_ethtool_ops =3D { --=20 2.49.1 From nobody Thu Oct 2 09:22:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57E382FFDD7; Thu, 18 Sep 2025 09:01:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758186112; cv=none; b=BhyZ85cfQopH+2782+Kz6CFzfEwo/6Vx6sV+7dfgjTOy8JVELMUtwJhxoXJLpaej6PexfkobrarIe7F9Svu83m0UyfbtEnrEZWNgYrrM3UBUN53CyZsXhXYDuQ6VA6HLt+kJt5g5YBgjJWiav8hSAC3Whwm5GF9xeOZtDAz2lrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758186112; c=relaxed/simple; bh=2ojWim0st4lnA2XgT/Qg56HLdpsIlwLb6NH17RfD91E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IaoPJByFUtqKE4Rw4pI9uMfjIswQhIf8dg/ezn2TOJW5EQkrh/NoHmy3D+/IFa7kjfXxRVknIf2LCqrvPttM7Vw3z50PNpk4BdyQAKaM3b/qk8rxi9VKit6OpPyqZSytKOVu+LnOrmpvuirHHhOKHjf/iOGh/Ti52AkRnmm2O1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vI+C1g/e; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vI+C1g/e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1676C4CEF7; Thu, 18 Sep 2025 09:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758186112; bh=2ojWim0st4lnA2XgT/Qg56HLdpsIlwLb6NH17RfD91E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vI+C1g/e4EQ9UYWBlg8FNogeSAxF7IsqrjbIKlefff7UPE4VZhL7IunkvHKKmbL4S fPZ4gxz+MnlsDX3NMkowkdB4msN+2IeSRVzSlagISr8bHzteyIYgqjsEfeJtc81fvA SI8mQ9/i/kRAHEuO+3uZ/l8SxohvfpXrwG6iKi90Oi7JZKUCjkLfqOEaLeIHq9wDGJ d9x4MABSIRXimIt0sATWTcMkox6L5RNZp1mPQvWXdivpdHpPlqFWbtp860oQJ2yyOV r6zFw+Q/3glj/XBfJQfjUu2k7h+UOXfgtdFLw3qsLAh1LVc52g+k1YshRtpEfI83ru W6Jky67iqsEDQ== From: Vincent Mailhol Date: Thu, 18 Sep 2025 18:00:25 +0900 Subject: [PATCH 2/4] can: hi311x: populate ndo_change_mtu() to prevent buffer overflow Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250918-can-fix-mtu-v1-2-0d1cada9393b@kernel.org> References: <20250918-can-fix-mtu-v1-0-0d1cada9393b@kernel.org> In-Reply-To: <20250918-can-fix-mtu-v1-0-0d1cada9393b@kernel.org> To: Marc Kleine-Budde , Oliver Hartkopp Cc: Arunachalam Santhanam , Akshay Bhat , Wolfgang Grandegger , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Gerhard Bertelsmann , Yasushi SHOJI , =?utf-8?q?Remigiusz_Ko=C5=82=C5=82=C4=85taj?= , linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2644; i=mailhol@kernel.org; h=from:subject:message-id; bh=2ojWim0st4lnA2XgT/Qg56HLdpsIlwLb6NH17RfD91E=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDBmnTxW8SLihku7eY1d3/cZPkdrHCZ6R/1fwzJvSmexu0 T49/hFHRykLgxgXg6yYIsuyck5uhY5C77BDfy1h5rAygQxh4OIUgIlIejEyXFkuX7Ft50TvzoDn BmZ/K3dFFP1MU0+Vbj3zqUHWL2ZxMSPDF/FvzC/n8b1RMj+2Kvtmmopvff2kq3Ff16RX/z9iKyP EDQA= X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 Sending an PF_PACKET allows to bypass the CAN framework logic and to directly reach the xmit() function of a CAN driver. The only check which is performed by the PF_PACKET framework is to make sure that skb->len fits the interface's MTU. Unfortunately, because the sun4i_can driver does not populate its net_device_ops->ndo_change_mtu(), it is possible for an attacker to configure an invalid MTU by doing, for example: $ ip link set can0 mtu 9999 After doing so, the attacker could open a PF_PACKET socket using the ETH_P_CANXL protocol: socket(PF_PACKET, SOCK_RAW, htons(ETH_P_CANXL)) to inject a malicious CAN XL frames. For example: struct canxl_frame frame =3D { .flags =3D 0xff, .len =3D 2048, }; The CAN drivers' xmit() function are calling can_dev_dropped_skb() to check that the skb is valid, unfortunately under above conditions, the malicious packet is able to go through can_dev_dropped_skb() checks: 1. the skb->protocol is set to ETH_P_CANXL which is valid (the function does not check the actual device capabilities). 2. the length is a valid CAN XL length. And so, hi3110_hard_start_xmit() receives a CAN XL frame which it is not able to correctly handle and will thus misinterpret it as a CAN frame. The driver will consume frame->len as-is with no further checks. This can result in a buffer overflow later on in hi3110_hw_tx() on this line: memcpy(buf + HI3110_FIFO_EXT_DATA_OFF, frame->data, frame->len); Here, frame->len corresponds to the flags field of the CAN XL frame. In our previous example, we set canxl_frame->flags to 0xff. Because the maximum expected length is 8, a buffer overflow of 247 bytes occurs! Populate net_device_ops->ndo_change_mtu() to ensure that the interface's MTU can not be set to anything bigger than CAN_MTU. By fixing the root cause, this prevents the buffer overflow. Fixes: 57e83fb9b746 ("can: hi311x: Add Holt HI-311x CAN driver") Signed-off-by: Vincent Mailhol --- drivers/net/can/spi/hi311x.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c index 09ae218315d73d49c2ec4280707911966fce1c31..6441ff3b4198718e8e662daa302= 2f06a2405f322 100644 --- a/drivers/net/can/spi/hi311x.c +++ b/drivers/net/can/spi/hi311x.c @@ -812,6 +812,7 @@ static const struct net_device_ops hi3110_netdev_ops = =3D { .ndo_open =3D hi3110_open, .ndo_stop =3D hi3110_stop, .ndo_start_xmit =3D hi3110_hard_start_xmit, + .ndo_change_mtu =3D can_change_mtu, }; =20 static const struct ethtool_ops hi3110_ethtool_ops =3D { --=20 2.49.1 From nobody Thu Oct 2 09:22:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E86FD2FFFB8; Thu, 18 Sep 2025 09:01:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758186115; cv=none; b=I6T0PHN4avfqjvqeLAx0+qpKfSolLThJCrzk705timqAQ5N4ebeUA2EwQNYPH2X65sQYQVMICHnkJKo9q9lGOtP2bS9UC8cQwRJOo9WcS2SkHicAxWXZ+hdF76qCv9uYhB53pIHriEsXor9TxROyUQBapAcgOTdeti2Z9GaTyL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758186115; c=relaxed/simple; bh=mGSWa58npvsbMCZz/6vmp8p/XePk3TJBfYof7NGs8oU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uJYvb5huZkMXsN5QLA/tEdVR2dc52L6wIXxfvMOeFwoLco5q7PqNTwa3dXMV+LYZ/3a+xVURwOajMU34tIFHl72z+0h85SVA4fWaUa+Qvc4n07dUf/cUL1K6pSQrYMUCxu2hLei2CvexMZUcKq+o6eeCnPo3ih99HeJutpI3oNE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LykDXyf9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LykDXyf9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48F37C4CEE7; Thu, 18 Sep 2025 09:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758186114; bh=mGSWa58npvsbMCZz/6vmp8p/XePk3TJBfYof7NGs8oU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LykDXyf9viuasSfBsno2kiu+GBRZ9k02IgoUx32ATpI36+DMYYge8IsVktJ9Y0hCh itVkhBj/FxyvYIGA/ZC66LiXHhEY+BCGEcLOG6DriQ7pntaLTQzj4mT9MFxuXrdZWR WTlQZ+3uh7vQZJciFKtbeaQAWg2Fj5Z3CKaHH9DV5J7ZDeO0BOJgzGqIQYA6AZVHbu KWkWpLNsRJtCOKlUzhICLsYmMJPHWa2AvjT1JqQAK0x8A3ZI5V0GAdmzBzy5aAuZnR Ms3juopOsxXJRCs9uV5hU1+6dquREhGtGXFRjkpIAe/5CmUGaA6xiBdTsK6cje+hEh 6JCP5JTck0aAw== From: Vincent Mailhol Date: Thu, 18 Sep 2025 18:00:26 +0900 Subject: [PATCH 3/4] can: sun4i_can: populate ndo_change_mtu() to prevent buffer overflow Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250918-can-fix-mtu-v1-3-0d1cada9393b@kernel.org> References: <20250918-can-fix-mtu-v1-0-0d1cada9393b@kernel.org> In-Reply-To: <20250918-can-fix-mtu-v1-0-0d1cada9393b@kernel.org> To: Marc Kleine-Budde , Oliver Hartkopp Cc: Arunachalam Santhanam , Akshay Bhat , Wolfgang Grandegger , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Gerhard Bertelsmann , Yasushi SHOJI , =?utf-8?q?Remigiusz_Ko=C5=82=C5=82=C4=85taj?= , linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2683; i=mailhol@kernel.org; h=from:subject:message-id; bh=mGSWa58npvsbMCZz/6vmp8p/XePk3TJBfYof7NGs8oU=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDBmnTxWZTgw4VM999eMKhiW/mgPzTVdd92X5/OeGtJvF4 gvHcjqud5SyMIhxMciKKbIsK+fkVugo9A479NcSZg4rE8gQBi5OAZjIfQZGhv9126JX8G42aY3J mbiI+0nZJbvFB699Tqvivdr3J7Ca8z8jwwTdeWUXmvIuqQQHsiS6Km2sXf3IRa/fUMf80IctX55 PZwEA X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 Sending an PF_PACKET allows to bypass the CAN framework logic and to directly reach the xmit() function of a CAN driver. The only check which is performed by the PF_PACKET framework is to make sure that skb->len fits the interface's MTU. Unfortunately, because the sun4i_can driver does not populate its net_device_ops->ndo_change_mtu(), it is possible for an attacker to configure an invalid MTU by doing, for example: $ ip link set can0 mtu 9999 After doing so, the attacker could open a PF_PACKET socket using the ETH_P_CANXL protocol: socket(PF_PACKET, SOCK_RAW, htons(ETH_P_CANXL)) to inject a malicious CAN XL frames. For example: struct canxl_frame frame =3D { .flags =3D 0xff, .len =3D 2048, }; The CAN drivers' xmit() function are calling can_dev_dropped_skb() to check that the skb is valid, unfortunately under above conditions, the malicious packet is able to go through can_dev_dropped_skb() checks: 1. the skb->protocol is set to ETH_P_CANXL which is valid (the function does not check the actual device capabilities). 2. the length is a valid CAN XL length. And so, sun4ican_start_xmit() receives a CAN XL frame which it is not able to correctly handle and will thus misinterpret it as a CAN frame. This can result in a buffer overflow. The driver will consume cf->len as-is with no further checks on this line: dlc =3D cf->len; Here, cf->len corresponds to the flags field of the CAN XL frame. In our previous example, we set canxl_frame->flags to 0xff. Because the maximum expected length is 8, a buffer overflow of 247 bytes occurs a couple line below when doing: for (i =3D 0; i < dlc; i++) writel(cf->data[i], priv->base + (dreg + i * 4)); Populate net_device_ops->ndo_change_mtu() to ensure that the interface's MTU can not be set to anything bigger than CAN_MTU. By fixing the root cause, this prevents the buffer overflow. Fixes: 0738eff14d81 ("can: Allwinner A10/A20 CAN Controller support - Kerne= l module") Signed-off-by: Vincent Mailhol --- drivers/net/can/sun4i_can.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c index 6fcb301ef611d0c8bdb8720aaa77dc78950123d6..53bfd873de9bdecaf6923049007= f9efd71289dd3 100644 --- a/drivers/net/can/sun4i_can.c +++ b/drivers/net/can/sun4i_can.c @@ -768,6 +768,7 @@ static const struct net_device_ops sun4ican_netdev_ops = =3D { .ndo_open =3D sun4ican_open, .ndo_stop =3D sun4ican_close, .ndo_start_xmit =3D sun4ican_start_xmit, + .ndo_change_mtu =3D can_change_mtu, }; =20 static const struct ethtool_ops sun4ican_ethtool_ops =3D { --=20 2.49.1 From nobody Thu Oct 2 09:22:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A8683002C4; Thu, 18 Sep 2025 09:01:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758186117; cv=none; b=ZD6FHIGPyncvDfugzh9bnHvzJkWRZzqS3KIyz9Cwf2mqPyeDC1o36ly9FEQhlcUsxB07vn0fhS6AYopAkNhVdGJ0GdJTadfG267MBvAjBmjvDxuhV/RtqZcPcI3lxvwOiC+SIeG41hC/buKq+fQ72yaHCGy17uwKTY8MG+blmB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758186117; c=relaxed/simple; bh=jwRTUoN54HeyKKOV4Dj4gsSdmsvGsDnd8DlVRGDSbDU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=unOPKE0FOUs3O1KRHCha4ReKxS2JJUcoxN+VpplYQwcthrQMYvPzW/59gJdDrjaWh9d84gkvcudS7sk99ZaqekI0P+VnWVYYSB1xDJz7fBTLQ5WRhmcZh3FKbGMOITOPs5eZnSeyUI6BI47GkpSz5PO0FZ8bKu164Hz2vkjYfZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GxoH68x7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GxoH68x7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D35ECC4CEF0; Thu, 18 Sep 2025 09:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758186117; bh=jwRTUoN54HeyKKOV4Dj4gsSdmsvGsDnd8DlVRGDSbDU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GxoH68x7hQHtLVtLVFaUYb+D7yUzMQAZLIcgN2NuzCvOueygHkFoCIZpYVskFiuxX y1TATBou4FNIrB9zORxwf1WlGgQDx1qcA8PYE7mHvTFGHzVCicFJUwRQ+a2yCVmcvO rM8g62VcDBWqaVYPddsMgb5LImWZa41OdSK5Y0rqFxnQ4DbfrQBkXJyQikO8/kUFEp J9nM5mVxOGfBgnoghgHUUQdEXBs7MIiePFYyp53CuZVYCSEiXXaGD3RoP+Ki8t2Psg bX/+R5//IRXVQRwAD9i/v2Uu9b2i7Usb6raiG+75yt5mpXFkU/ye8HASukUJ+zEtDf RPELvjxDeOA6g== From: Vincent Mailhol Date: Thu, 18 Sep 2025 18:00:27 +0900 Subject: [PATCH 4/4] can: mcba_usb: populate ndo_change_mtu() to prevent buffer overflow Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250918-can-fix-mtu-v1-4-0d1cada9393b@kernel.org> References: <20250918-can-fix-mtu-v1-0-0d1cada9393b@kernel.org> In-Reply-To: <20250918-can-fix-mtu-v1-0-0d1cada9393b@kernel.org> To: Marc Kleine-Budde , Oliver Hartkopp Cc: Arunachalam Santhanam , Akshay Bhat , Wolfgang Grandegger , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Gerhard Bertelsmann , Yasushi SHOJI , =?utf-8?q?Remigiusz_Ko=C5=82=C5=82=C4=85taj?= , linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2629; i=mailhol@kernel.org; h=from:subject:message-id; bh=jwRTUoN54HeyKKOV4Dj4gsSdmsvGsDnd8DlVRGDSbDU=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDBmnT5Wa/3W9fdJ1Pmfsm6Utj1ZGxk9zsm+6r7lgB+Pcm 5eDojZs7ChlYRDjYpAVU2RZVs7JrdBR6B126K8lzBxWJpAhDFycAjAR0WaG/wW/Ql+G9f/64zBv YUxp32L9bP/UrZ+OrlxjbPWX05p91n1Ghmdnr4fNte61cj9dc6HiXP0mz5MHYxaub63d7v08Qvr yE0YA X-Developer-Key: i=mailhol@kernel.org; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 Sending an PF_PACKET allows to bypass the CAN framework logic and to directly reach the xmit() function of a CAN driver. The only check which is performed by the PF_PACKET framework is to make sure that skb->len fits the interface's MTU. Unfortunately, because the mcba_usb driver does not populate its net_device_ops->ndo_change_mtu(), it is possible for an attacker to configure an invalid MTU by doing, for example: $ ip link set can0 mtu 9999 After doing so, the attacker could open a PF_PACKET socket using the ETH_P_CANXL protocol: socket(PF_PACKET, SOCK_RAW, htons(ETH_P_CANXL)) to inject a malicious CAN XL frames. For example: struct canxl_frame frame =3D { .flags =3D 0xff, .len =3D 2048, }; The CAN drivers' xmit() function are calling can_dev_dropped_skb() to check that the skb is valid, unfortunately under above conditions, the malicious packet is able to go through can_dev_dropped_skb() checks: 1. the skb->protocol is set to ETH_P_CANXL which is valid (the function does not check the actual device capabilities). 2. the length is a valid CAN XL length. And so, mcba_usb_start_xmit() receives a CAN XL frame which it is not able to correctly handle and will thus misinterpret it as a CAN frame. This can result in a buffer overflow. The driver will consume cf->len as-is with no further checks on these lines: usb_msg.dlc =3D cf->len; memcpy(usb_msg.data, cf->data, usb_msg.dlc); Here, cf->len corresponds to the flags field of the CAN XL frame. In our previous example, we set canxl_frame->flags to 0xff. Because the maximum expected length is 8, a buffer overflow of 247 bytes occurs! Populate net_device_ops->ndo_change_mtu() to ensure that the interface's MTU can not be set to anything bigger than CAN_MTU. By fixing the root cause, this prevents the buffer overflow. Fixes: 51f3baad7de9 ("can: mcba_usb: Add support for Microchip CAN BUS Anal= yzer") Signed-off-by: Vincent Mailhol --- drivers/net/can/usb/mcba_usb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/can/usb/mcba_usb.c b/drivers/net/can/usb/mcba_usb.c index 41c0a1c399bf36104fbf8991b537acdb01e7e950..1f9b915094e64de875adff35026= e9cd3beb0410d 100644 --- a/drivers/net/can/usb/mcba_usb.c +++ b/drivers/net/can/usb/mcba_usb.c @@ -761,6 +761,7 @@ static const struct net_device_ops mcba_netdev_ops =3D { .ndo_open =3D mcba_usb_open, .ndo_stop =3D mcba_usb_close, .ndo_start_xmit =3D mcba_usb_start_xmit, + .ndo_change_mtu =3D can_change_mtu, }; =20 static const struct ethtool_ops mcba_ethtool_ops =3D { --=20 2.49.1