Archive-only list for syzbot
 help / color / mirror / Atom feed
From: Vincent Mailhol <mailhol@kernel.org>
To: Oliver Hartkopp <socketcan@hartkopp.net>, mkl@pengutronix.de
Cc: syzbot@lists.linux.dev, syzkaller-bugs@googlegroups.com,
	syzbot ci <syzbot+ci284feacb80736eb0@syzkaller.appspotmail.com>,
	biju.das.jz@bp.renesas.com, davem@davemloft.net, geert@glider.be,
	kernel@pengutronix.de, kuba@kernel.org,
	linux-can@vger.kernel.org, netdev@vger.kernel.org,
	stefan.maetje@esd.eu, stephane.grosjean@hms-networks.com,
	zhao.xichao@vivo.com, Vincent Mailhol <mailhol@kernel.org>
Subject: [PATCH] can: dev: fix out-of-bound read in can_set_default_mtu()
Date: Wed, 24 Sep 2025 23:35:44 +0900	[thread overview]
Message-ID: <20250924143644.17622-2-mailhol@kernel.org> (raw)
In-Reply-To: <68d3e6ce.a70a0220.4f78.0028.GAE@google.com>

Under normal usage, the virtual interfaces do not call can_setup(),
unless if trigger by a call to can_link_ops->setup().

Patch [1] did not consider this scenario resulting in an out of bound
read in can_setup() when calling can_link_ops->setup() as reported by
syzbot ci in [2].

Replacing netdev_priv() by safe_candev_priv() may look like a
potential solution at first glance but is not: can_setup() is used as
a callback function in alloc_netdev_mqs(). At the moment this callback
is called, priv is not yet fully setup and thus, safe_candev_priv()
would fail on physical interfaces. In other words, safe_candev_priv()
is solving the problem for virtual interfaces, but adding another
issue for physical interfaces.

Remove the call to can_set_default_mtu() in can_setup(). Instead,
manually set the MTU the default CAN MTU. This decorrelates the two
functions, effectively removing the conflict.

[1] can: populate the minimum and maximum MTU values
Link: https://lore.kernel.org/linux-can/20250923-can-fix-mtu-v3-3-581bde113f52@kernel.org/

[2] https://lore.kernel.org/linux-can/68d3e6ce.a70a0220.4f78.0028.GAE@google.com/

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
@Marc, please squash in

  [PATCH net-next 27/48] can: populate the minimum and maximum MTU values
---
 drivers/net/can/dev/dev.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c
index e5a82aa77958..15ccedbb3f8d 100644
--- a/drivers/net/can/dev/dev.c
+++ b/drivers/net/can/dev/dev.c
@@ -272,12 +272,13 @@ EXPORT_SYMBOL_GPL(can_bus_off);
 void can_setup(struct net_device *dev)
 {
 	dev->type = ARPHRD_CAN;
+	dev->mtu = CAN_MTU;
+	dev->min_mtu = CAN_MTU;
+	dev->max_mtu = CAN_MTU;
 	dev->hard_header_len = 0;
 	dev->addr_len = 0;
 	dev->tx_queue_len = 10;
 
-	can_set_default_mtu(dev);
-
 	/* New-style flags. */
 	dev->flags = IFF_NOARP;
 	dev->features = NETIF_F_HW_CSUM;
-- 
2.49.1


  parent reply	other threads:[~2025-09-24 14:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250924082104.595459-1-mkl@pengutronix.de>
2025-09-24 12:40 ` [syzbot ci] Re: pull-request: can-next 2025-09-24 syzbot ci
2025-09-24 13:18   ` Oliver Hartkopp
2025-09-24 13:31     ` Vincent Mailhol
2025-09-24 13:38       ` Marc Kleine-Budde
2025-09-24 13:38       ` Oliver Hartkopp
2025-09-24 14:14         ` Vincent Mailhol
2025-09-24 14:35   ` Vincent Mailhol [this message]
2025-09-24 15:13     ` [PATCH] can: dev: fix out-of-bound read in can_set_default_mtu() Marc Kleine-Budde
2025-09-24 15:21       ` Vincent Mailhol

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250924143644.17622-2-mailhol@kernel.org \
    --to=mailhol@kernel.org \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=davem@davemloft.net \
    --cc=geert@glider.be \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    --cc=stefan.maetje@esd.eu \
    --cc=stephane.grosjean@hms-networks.com \
    --cc=syzbot+ci284feacb80736eb0@syzkaller.appspotmail.com \
    --cc=syzbot@lists.linux.dev \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=zhao.xichao@vivo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox