Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH 4/7] firmware: imx: ele: simplify SoC device registration
Date: Mon, 25 May 2026 08:09:01 +0000	[thread overview]
Message-ID: <20260525080902.3AFE01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260525-ele-v1-v1-4-a9570c4bffc9@nxp.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Use-After-Free and resource leak due to missing soc_device_unregister().
- [High] Information leak and functional breakage in get_se_soc_id() due to incorrect struct casting.
--

commit e7ad33f52996b1ca324a005406dedb896f547398
Author: Peng Fan <peng.fan@nxp.com>

firmware: imx: ele: simplify SoC device registration

This patch simplifies the SoC device registration for i.MX by replacing
the boolean 'soc_register' flag with a 'soc_name' string. The presence
of 'soc_name' now dictates registration, removing the need for a switch
statement.

> diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c
> --- a/drivers/firmware/imx/se_ctrl.c
> +++ b/drivers/firmware/imx/se_ctrl.c
> @@ -56,7 +56,7 @@ struct se_var_info {
>  /* contains fixed information */
>  struct se_soc_info {
>  	const u16 soc_id;
> -	const bool soc_register;
> +	const char *soc_name;
>  	const struct se_fw_img_name se_fw_img_nm;
>  };

[Severity: High]
This isn't a bug introduced by this patch, but does get_se_soc_id()
incorrectly cast the match data and leak kernel address information?

device_get_match_data() returns a pointer to struct se_if_node, but
get_se_soc_id() assigns it to a const struct se_soc_info * pointer.

Since the first member of struct se_if_node is a pointer (se_info)
rather than a u16 soc_id, will accessing se_info->soc_id read the lower
16 bits of the kernel pointer instead of the actual SoC ID?

[ ... ]
> @@ -181,14 +181,7 @@ static int get_se_soc_info(struct se_if_priv *priv, const struct se_soc_info *se
>  						FIELD_GET(DEV_GETINFO_MAJ_VER_MASK,
>  							  var_se_info.soc_rev));
>  
> -	switch (se_info->soc_id) {
> -	case SOC_ID_OF_IMX8ULP:
> -		attr->soc_id = "i.MX8ULP";
> -		break;
> -	case SOC_ID_OF_IMX93:
> -		attr->soc_id = "i.MX93";
> -		break;
> -	}
> +	attr->soc_id = se_info->soc_name;
>  
>  	err = of_property_read_string(of_root, "model", &attr->machine);
>  	if (err)

[Severity: High]
This is a pre-existing issue, but does this function leak the soc_device
and create a use-after-free vulnerability?

The attr structure is allocated with devm_kzalloc(), meaning it is freed
when the driver unbinds. However, when soc_device_register(attr) is called
later in this function, the returned struct soc_device * is discarded.

Without calling soc_device_unregister() in error paths or driver remove,
will the sysfs nodes remain active? If a read to an attribute like
/sys/devices/soc0/revision happens after the driver is unbound, will it
dereference the freed attr memory?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260525-ele-v1-v1-0-a9570c4bffc9@nxp.com?part=4

  parent reply	other threads:[~2026-05-25  8:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25  5:39 [PATCH 0/7] firmware: imx: ele: misc fixes Peng Fan (OSS)
2026-05-25  5:39 ` [PATCH 1/7] firmware: imx: ele: Correct check condition in se_if_rx_callback Peng Fan (OSS)
2026-05-25  6:23   ` sashiko-bot
2026-05-25  5:39 ` [PATCH 2/7] firmware: imx: ele: Correct ele_fw_authenticate API Peng Fan (OSS)
2026-05-25  7:02   ` sashiko-bot
2026-05-25  5:39 ` [PATCH 3/7] firmware: imx: ele: Bypass memcpy when ele_get_info() fails Peng Fan (OSS)
2026-05-25  7:37   ` sashiko-bot
2026-05-25  5:39 ` [PATCH 4/7] firmware: imx: ele: simplify SoC device registration Peng Fan (OSS)
2026-05-25  6:36   ` Pankaj Gupta
2026-05-25  8:09   ` sashiko-bot [this message]
2026-05-25  5:39 ` [PATCH 5/7] firmware: imx: ele: Correct check_hdr_exception_for_sz Peng Fan (OSS)
2026-05-25  8:49   ` sashiko-bot
2026-05-25  5:39 ` [PATCH 6/7] firmware: imx: ele: Use dev_err for error report Peng Fan (OSS)
2026-05-25  8:57   ` sashiko-bot
2026-05-25  5:39 ` [PATCH 7/7] firmware: imx: ele: Fix debug dump size handling Peng Fan (OSS)
2026-05-25  9:34   ` sashiko-bot
2026-06-01 20:03 ` [PATCH 0/7] firmware: imx: ele: misc fixes Frank.Li

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=20260525080902.3AFE01F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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