Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhentao Guo" <zhentao.guo@amlogic.com>
Cc: linux-amlogic@lists.infradead.org, devicetree@vger.kernel.org,
	neil.armstrong@linaro.org, conor+dt@kernel.org,
	media-ci@linuxtv.org, robh@kernel.org
Subject: Re: [PATCH v6 2/6] firmware: meson: sm: video firmware loading via secure monitor
Date: Fri, 24 Jul 2026 07:24:58 +0000	[thread overview]
Message-ID: <20260724072459.59CC71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724-b4-s4-vdec-upstream-v6-2-6072a7ee7428@amlogic.com>

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

New issues:
- [Low] The patch series splits the addition of a new SMC command across two commits in the wrong order, breaking the build and git bisect.

Pre-existing issues:
- [High] meson_sm_call always returns 0 on success of command dispatch, masking the actual SMC return code and leading to ignored firmware errors.
- [High] Missing locking in meson_sm_call_write and meson_sm_call_read allows concurrent threads to corrupt shared memory.
- [High] meson_sm_map_shmem fails to handle SMCCC error codes, passing invalid physical addresses like 0xFFFFFFFF to ioremap_cache.
- [High] meson_sm_get returns a pointer to devres-managed memory without holding a device reference, causing a UAF if the driver is unbound.
--

--- Patch [2]: [PATCH v6 2/6] firmware: meson: sm: video firmware loading via secure monitor ---
commit 712790e34d92d775f45e1b4ef265054cbaf878df
Author: Zhentao Guo <zhentao.guo@amlogic.com>

firmware: meson: sm: video firmware loading via secure monitor

Add SM_LOAD_VIDEO_FW to the secure monitor command enum to allow decoder
drivers to load firmware through the meson_sm interface.

> diff --git a/include/linux/firmware/meson/meson_sm.h b/include/linux/firmware/meson/meson_sm.h
> index 3ebc2bd9a9760..3b90b49d05529 100644
> --- a/include/linux/firmware/meson/meson_sm.h
> +++ b/include/linux/firmware/meson/meson_sm.h
> @@ -15,6 +15,7 @@ enum {
>  	SM_THERMAL_CALIB_READ,
>  	SM_A1_PWRC_SET,
>  	SM_A1_PWRC_GET,
> +	SM_LOAD_VIDEO_FW,

[Severity: Low]
Does this patch fix a build break introduced earlier in the series?

If SM_LOAD_VIDEO_FW was used in drivers/firmware/meson/meson_sm.c in a prior
commit before being declared here in the enum, it would break git bisect.

>  };
>  
>  struct meson_sm_firmware;

[Severity: High]
This isn't a bug introduced by this patch, but does meson_sm_call() mask SMC
errors?

drivers/firmware/meson/meson_sm.c:meson_sm_call() {
    ...
    lret = __meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);

    if (ret)
        *ret = lret;

    return 0;
}

If a caller passes NULL for ret, the function always returns 0. Should it
propagate or validate lret when ret is NULL?

[Severity: High]
This is a pre-existing issue, but does the shared memory access lack
synchronization?

drivers/firmware/meson/meson_sm.c:meson_sm_call_write() {
    ...
    memcpy(fw->sm_shmem_in_base, buffer, size);

    if (meson_sm_call(fw, cmd_index, &written, arg0, arg1, ...) < 0)
    ...
}

And similarly in meson_sm_call_read():

drivers/firmware/meson/meson_sm.c:meson_sm_call_read() {
    ...
    if (meson_sm_call(fw, cmd_index, &size, arg0, arg1, ...) < 0)
        return -EINVAL;
    ...
    if (buffer)
        memcpy(buffer, fw->sm_shmem_out_base, size);
    ...
}

Can concurrent threads race here, overwriting shared memory before another
thread finishes reading its response?

[Severity: High]
This is a pre-existing issue, but could this fail to handle SMCCC error codes
correctly?

drivers/firmware/meson/meson_sm.c:meson_sm_map_shmem() {
    u32 sm_phy_base;

    sm_phy_base = __meson_sm_call(cmd_shmem, 0, 0, 0, 0, 0);
    if (!sm_phy_base)
        return NULL;

    return ioremap_cache(sm_phy_base, size);
}

If the secure monitor returns a negative error code, sm_phy_base (u32) becomes
0xFFFFFFFF. Will ioremap_cache() attempt to map this invalid physical address?

[Severity: High]
This isn't a bug introduced by this patch, but can this result in a dangling
pointer when returning devres-managed memory?

drivers/firmware/meson/meson_sm.c:meson_sm_get() {
    struct platform_device *pdev = of_find_device_by_node(sm_node);
    struct meson_sm_firmware *fw;
    ...
    fw = platform_get_drvdata(pdev);

    put_device(&pdev->dev);

    return fw;
}

Since fw is allocated with devm_kzalloc() bound to the meson-sm device, if the
driver is unbound via sysfs, devres frees the memory. Do consumer drivers
retain a dangling pointer to fw after put_device() drops the reference?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724-b4-s4-vdec-upstream-v6-0-6072a7ee7428@amlogic.com?part=2

  reply	other threads:[~2026-07-24  7:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24  7:04 [PATCH v6 0/6] Add Amlogic stateless H.264 video decoder for S4 Zhentao Guo via B4 Relay
2026-07-24  7:04 ` [PATCH v6 1/6] firmware: meson: sm: Add video firmware loading SMC call Zhentao Guo via B4 Relay
2026-07-24  7:16   ` sashiko-bot
2026-07-24  7:04 ` [PATCH v6 2/6] firmware: meson: sm: video firmware loading via secure monitor Zhentao Guo via B4 Relay
2026-07-24  7:24   ` sashiko-bot [this message]
2026-07-24 10:22   ` Ferass El Hafidi
2026-07-24  7:04 ` [PATCH v6 3/6] media: dt-bindings: Add Amlogic V4L2 video decoder Zhentao Guo via B4 Relay
2026-07-24  7:13   ` sashiko-bot
2026-07-24  7:04 ` [PATCH v6 4/6] decoder: Add V4L2 stateless H.264 decoder driver Zhentao Guo via B4 Relay
2026-07-24  7:28   ` sashiko-bot
2026-07-24  7:04 ` [PATCH v6 5/6] arm64: dts: amlogic: Add video decoder driver support for S4 SOCs Zhentao Guo via B4 Relay
2026-07-24  7:16   ` sashiko-bot
2026-07-24  7:04 ` [PATCH v6 6/6] arm64: defconfig: Enable CONFIG_VIDEO_AMLOGIC_VDEC Zhentao Guo via B4 Relay
2026-07-24 10:13 ` [PATCH v6 0/6] Add Amlogic stateless H.264 video decoder for S4 Ferass El Hafidi

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=20260724072459.59CC71F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=media-ci@linuxtv.org \
    --cc=neil.armstrong@linaro.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhentao.guo@amlogic.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