All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Link Mauve" <linkmauve@linkmauve.fr>
Cc: neil.armstrong@linaro.org, Frank.Li@kernel.org,
	imx@lists.linux.dev, ojeda@kernel.org,
	linux-amlogic@lists.infradead.org
Subject: Re: [PATCH v3 4/4] firmware: meson: pass a const buffer to meson_sm_call_write()
Date: Thu, 16 Jul 2026 14:36:51 +0000	[thread overview]
Message-ID: <20260716143651.6A5741F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716142415.28718-5-linkmauve@linkmauve.fr>

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

Pre-existing issues:
- [High] `meson_sm_call()` propagates SMC failures via its output parameter `*ret` but unconditionally returns 0 on success. Callers incorrectly check the return value instead of validating the output parameter, leading to silently ignored errors and state corruption.
- [High] Missing mutual exclusion in `meson_sm_call_read` and `meson_sm_call_write` when accessing the shared IO memory buffers `fw->sm_shmem_in_base` and `fw->sm_shmem_out_base`.
--

--- Patch [4]: [PATCH v3 4/4] firmware: meson: pass a const buffer to meson_sm_call_write() ---
commit dafeddcc00e60d8baf4fc20e8f8f2f6286a33db3
Author: Link Mauve <linkmauve@linkmauve.fr>

firmware: meson: pass a const buffer to meson_sm_call_write()

This commit updates the meson_sm_call_write() signature to accept a
const void *buffer instead of void *buffer. It also removes unnecessary
casts to (u8 *) in meson_efuse_read() and meson_efuse_write() when
passing the buffer to the SMC call functions.

> diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c
> index ab9751a59b552..5d4da2e3c3a94 100644
> --- a/drivers/firmware/meson/meson_sm.c
> +++ b/drivers/firmware/meson/meson_sm.c
> @@ -196,7 +196,7 @@ EXPORT_SYMBOL(meson_sm_call_read);
>   *
>   * Return:	size of sent data on success, a negative value on error
>   */
> -int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
> +int meson_sm_call_write(struct meson_sm_firmware *fw, const void *buffer,
>  			unsigned int size, unsigned int cmd_index, u32 arg0,
>  			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
>  {

[Severity: High]
This is a pre-existing issue, but while reviewing this function, is there a
missing lock when accessing shared IO memory?

In meson_sm_call_write(), we copy data to shared IO memory and execute
an SMC call:

	memcpy(fw->sm_shmem_in_base, buffer, size);

	if (meson_sm_call(fw, cmd_index, &written, arg0, arg1, arg2, arg3, arg4) < 0)

If multiple threads call meson_sm_call_write() or meson_sm_call_read()
concurrently, could they clobber the shared IO memory buffers before the
Secure Monitor executes the command? Access to fw->sm_shmem_in_base and
fw->sm_shmem_out_base does not appear to be serialized with a mutex.

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

Looking at meson_sm_call_write(), it checks the return value:

	if (meson_sm_call(fw, cmd_index, &written, arg0, arg1, arg2, arg3, arg4) < 0)
		return -EINVAL;

However, meson_sm_call() unconditionally returns 0:

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;

Because it always returns 0, callers checking the return value instead of
the output parameter will silently ignore errors. Could this cause drivers
like meson-efuse or amlogic_thermal to treat error codes as valid data and
corrupt state?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716142415.28718-1-linkmauve@linkmauve.fr?part=4

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Link Mauve" <linkmauve@linkmauve.fr>
Cc: neil.armstrong@linaro.org, Frank.Li@kernel.org,
	imx@lists.linux.dev, ojeda@kernel.org,
	linux-amlogic@lists.infradead.org
Subject: Re: [PATCH v3 4/4] firmware: meson: pass a const buffer to meson_sm_call_write()
Date: Thu, 16 Jul 2026 14:36:51 +0000	[thread overview]
Message-ID: <20260716143651.6A5741F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716142415.28718-5-linkmauve@linkmauve.fr>

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

Pre-existing issues:
- [High] `meson_sm_call()` propagates SMC failures via its output parameter `*ret` but unconditionally returns 0 on success. Callers incorrectly check the return value instead of validating the output parameter, leading to silently ignored errors and state corruption.
- [High] Missing mutual exclusion in `meson_sm_call_read` and `meson_sm_call_write` when accessing the shared IO memory buffers `fw->sm_shmem_in_base` and `fw->sm_shmem_out_base`.
--

--- Patch [4]: [PATCH v3 4/4] firmware: meson: pass a const buffer to meson_sm_call_write() ---
commit dafeddcc00e60d8baf4fc20e8f8f2f6286a33db3
Author: Link Mauve <linkmauve@linkmauve.fr>

firmware: meson: pass a const buffer to meson_sm_call_write()

This commit updates the meson_sm_call_write() signature to accept a
const void *buffer instead of void *buffer. It also removes unnecessary
casts to (u8 *) in meson_efuse_read() and meson_efuse_write() when
passing the buffer to the SMC call functions.

> diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c
> index ab9751a59b552..5d4da2e3c3a94 100644
> --- a/drivers/firmware/meson/meson_sm.c
> +++ b/drivers/firmware/meson/meson_sm.c
> @@ -196,7 +196,7 @@ EXPORT_SYMBOL(meson_sm_call_read);
>   *
>   * Return:	size of sent data on success, a negative value on error
>   */
> -int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
> +int meson_sm_call_write(struct meson_sm_firmware *fw, const void *buffer,
>  			unsigned int size, unsigned int cmd_index, u32 arg0,
>  			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
>  {

[Severity: High]
This is a pre-existing issue, but while reviewing this function, is there a
missing lock when accessing shared IO memory?

In meson_sm_call_write(), we copy data to shared IO memory and execute
an SMC call:

	memcpy(fw->sm_shmem_in_base, buffer, size);

	if (meson_sm_call(fw, cmd_index, &written, arg0, arg1, arg2, arg3, arg4) < 0)

If multiple threads call meson_sm_call_write() or meson_sm_call_read()
concurrently, could they clobber the shared IO memory buffers before the
Secure Monitor executes the command? Access to fw->sm_shmem_in_base and
fw->sm_shmem_out_base does not appear to be serialized with a mutex.

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

Looking at meson_sm_call_write(), it checks the return value:

	if (meson_sm_call(fw, cmd_index, &written, arg0, arg1, arg2, arg3, arg4) < 0)
		return -EINVAL;

However, meson_sm_call() unconditionally returns 0:

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;

Because it always returns 0, callers checking the return value instead of
the output parameter will silently ignore errors. Could this cause drivers
like meson-efuse or amlogic_thermal to treat error codes as valid data and
corrupt state?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716142415.28718-1-linkmauve@linkmauve.fr?part=4

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2026-07-16 14:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 14:24 [PATCH v3 0/4] nvmem: fix a const-unsoundness in reg_write Link Mauve
2026-07-16 14:24 ` Link Mauve
2026-07-16 14:24 ` [PATCH v3 1/4] nvmem: core: deprecate reg_write callback and add reg_write_const Link Mauve
2026-07-16 14:24   ` Link Mauve
2026-07-16 14:24 ` [PATCH v3 2/4] nvmem: make all reg_write callbacks take const void * Link Mauve
2026-07-16 14:24   ` Link Mauve
2026-07-16 14:37   ` sashiko-bot
2026-07-16 14:37     ` sashiko-bot
2026-07-16 14:24 ` [PATCH v3 3/4] nvmem: apple-spmi: improve calling safety with wrapper functions Link Mauve
2026-07-16 14:24   ` Link Mauve
2026-07-16 18:07   ` Andy Shevchenko
2026-07-16 18:07     ` Andy Shevchenko
2026-07-16 14:24 ` [PATCH v3 4/4] firmware: meson: pass a const buffer to meson_sm_call_write() Link Mauve
2026-07-16 14:24   ` Link Mauve
2026-07-16 14:36   ` sashiko-bot [this message]
2026-07-16 14:36     ` sashiko-bot
2026-07-16 15:23 ` [PATCH v3 0/4] nvmem: fix a const-unsoundness in reg_write Gary Guo
2026-07-16 15:23   ` Gary Guo
2026-07-16 18:09 ` Andy Shevchenko
2026-07-16 18:09   ` Andy Shevchenko

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=20260716143651.6A5741F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=linkmauve@linkmauve.fr \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=ojeda@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.