From: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
To: Guangshuo Li <lgs201920130244@gmail.com>,
support@ems-wuensche.com, Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Sebastian Haas <haas@ems-wuensche.com>,
Markus Plessing <plessing@ems-wuensche.com>,
Wolfgang Grandegger <wg@grandegger.com>,
linux-can@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: Re: [PATCH] can: sja1000: ems_pci: fix UAF in channel cleanup
Date: Thu, 3 Dec 2026 09:30:16 +0100 [thread overview]
Message-ID: <a2b5ea55-f164-4c64-a445-e04e4ec9bd82@ems-wuensche.com> (raw)
In-Reply-To: <20261026122616.97845-1-lgs201920130244@gmail.com>
Acked-By: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
Thank you Guangshuo Li!
--
Mit freundlichen Gruessen / Best Regards
Gerhard Uttenthaler
Am 26.10.26 um 13:26 schrieb Guangshuo Li:
> When a CAN channel is absent or register_sja1000dev() fails, the
> driver frees the network device but leaves its pointer in the
> card->net_dev array.
>
> The cleanup path iterates over card->channels, which counts only
> successfully registered channels, while the array is indexed by
> physical channel number. This mismatch can cause the cleanup path
> to access an already-freed network device and skip registered
> devices at higher array indices.
>
> Set the array entries to NULL after freeing their devices and
> iterate over the entire array during cleanup. This prevents
> use-after-free and ensures that all registered channels are
> properly released.
>
> This issue was found by our static analysis tool under development.
>
> Fixes: a61a8423c71d ("can: SJA1000 driver for EMS PCI cards")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> drivers/net/can/sja1000/ems_pci.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/can/sja1000/ems_pci.c b/drivers/net/can/sja1000/ems_pci.c
> index 986fc8786fac..ff680486a299 100644
> --- a/drivers/net/can/sja1000/ems_pci.c
> +++ b/drivers/net/can/sja1000/ems_pci.c
> @@ -213,7 +213,7 @@ static void ems_pci_del_card(struct pci_dev *pdev)
> struct net_device *dev;
> int i = 0;
>
> - for (i = 0; i < card->channels; i++) {
> + for (i = 0; i < ARRAY_SIZE(card->net_dev); i++) {
> dev = card->net_dev[i];
>
> if (!dev)
> @@ -399,6 +399,7 @@ static int ems_pci_add_card(struct pci_dev *pdev,
> "Registering device failed: %pe\n",
> ERR_PTR(err));
> free_sja1000dev(dev);
> + card->net_dev[i] = NULL;
> goto failure_cleanup;
> }
>
> @@ -408,6 +409,7 @@ static int ems_pci_add_card(struct pci_dev *pdev,
> i + 1, priv->reg_base, dev->irq);
> } else {
> free_sja1000dev(dev);
> + card->net_dev[i] = NULL;
> }
> }
>
--
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106
Phone: +49-8441-490260
Fax : +49-8441-81860
http://www.ems-wuensche.com
prev parent reply other threads:[~2026-12-03 8:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 12:26 Guangshuo Li
2026-12-03 8:30 ` Gerhard Uttenthaler [this message]
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=a2b5ea55-f164-4c64-a445-e04e4ec9bd82@ems-wuensche.com \
--to=uttenthaler@ems-wuensche.com \
--cc=davem@davemloft.net \
--cc=haas@ems-wuensche.com \
--cc=lgs201920130244@gmail.com \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=plessing@ems-wuensche.com \
--cc=stable@vger.kernel.org \
--cc=support@ems-wuensche.com \
--cc=wg@grandegger.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
all inboxes | Powered by JetHome®