dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rob Herring (Arm)" <robh@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 04/22] accel: ethosu: Disable clocks on PM setup failure
Date: Tue, 08 Sep 2026 22:18:17 +0000	[thread overview]
Message-ID: <20260908221817.F25721F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260908-ethosu-fixes-v3-4-490fe215286f@kernel.org>

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

Pre-existing issues:
- [High] The IRQ handler accesses hardware registers unconditionally without verifying if the device is active via pm_runtime_get_if_active(), risking a system crash on spurious interrupts.
- [High] DRM scheduler is finalized before its file-bound entities are destroyed, resulting in a Use-After-Free.
- [High] NPU SRAM is not cleared between consecutive jobs from different processes, leading to data leakage.
- [High] Missing upper bound check against UAPI array size leads to out-of-bounds read/write in `ethosu_ioctl_perfmon_create`.
- [High] Unvalidated hardware register `QREAD` used as an array index causes out-of-bounds memory read in `ethosu_job_timedout`.
--

commit 9bfcf97ff7178db9d34db7f9533d5df371a4f57c
Author: Rob Herring (Arm) <robh@kernel.org>

accel: ethosu: Disable clocks on PM setup failure

ethosu_init() enables the clocks directly to reset and query the NPU
before runtime PM takes over. If runtime-PM setup fails, the error path
returns while those clocks remain enabled. Disable the clocks before
returning the setup error to balance the initial direct resume.

> diff --git a/drivers/accel/ethosu/ethosu_drv.c b/drivers/accel/ethosu/ethosu_drv.c
> index 2c8d735767b2a..9d063daa1aa7d 100644
> --- a/drivers/accel/ethosu/ethosu_drv.c
> +++ b/drivers/accel/ethosu/ethosu_drv.c
> @@ -311,8 +311,10 @@ static int ethosu_init(struct ethosu_device *ethosudev)
>  	pm_runtime_set_autosuspend_delay(ethosudev->base.dev, 50);
>  	pm_runtime_use_autosuspend(ethosudev->base.dev);
>  	ret = devm_pm_runtime_set_active_enabled(ethosudev->base.dev);
> -	if (ret)
> +	if (ret) {
> +		ethosu_device_suspend(ethosudev->base.dev);
>  		return ret;
> +	}
>  	pm_runtime_get_noresume(ethosudev->base.dev);
>  
>  	ethosudev->npu_info.id = id = readl_relaxed(ethosudev->regs + NPU_REG_ID);


> drivers/accel/ethosu/ethosu_job.c:ethosu_job_irq_handler()
> {
> 	struct ethosu_device *dev = data;
> 	u32 status = readl_relaxed(dev->regs + NPU_REG_STATUS);
> 
> 	if (!(status & STATUS_IRQ_RAISED))
> 		return IRQ_NONE;

[Severity: High]
This is a pre-existing issue, but does this IRQ handler need to verify if
the device is active?

If a spurious interrupt occurs while the device is in the RPM_SUSPENDED
state with clocks disabled, will this unclocked register access result in a
synchronous external abort and a kernel panic?

Should this check pm_runtime_get_if_active() before accessing the register?


> drivers/accel/ethosu/ethosu_job.c:ethosu_job_fini()
> {
> 	drm_sched_fini(&dev->sched);
> }
> 
> [ ... ]
> 
> drivers/accel/ethosu/ethosu_job.c:ethosu_job_close()
> {
> 	struct drm_sched_entity *entity = &ethosu_priv->sched_entity;
> 
> 	drm_sched_entity_destroy(entity);
> }

[Severity: High]
This is a pre-existing issue, but does this lead to a use-after-free when
closing file descriptors?

When the device is unbound, ethosu_remove() tears down the scheduler.
However, if a userspace process holds a file descriptor open, its
sched_entity remains active.

When the file descriptor is later closed, ethosu_job_close() calls
drm_sched_entity_destroy().

Will drm_sched_entity_destroy() attempt to access the already destroyed
and freed scheduler via entity->rq->sched, causing a panic?


> drivers/accel/ethosu/ethosu_job.c:ethosu_job_hw_submit()
> {
> 	[ ... ]
> 
> 	if (job->sram_size) {
> 		writel_relaxed(lower_32_bits(dev->sramphys),
> 			       dev->regs + NPU_REG_BASEP(ETHOSU_SRAM_REGION));

[Severity: High]
This is a pre-existing issue, but is there a data leakage risk here?

The NPU SRAM is shared globally across jobs. It appears it is only cleared
during ethosu_device_reset() when runtime PM resumes. Because the driver
uses a 50ms autosuspend delay, consecutive jobs submitted within 50ms do
not trigger a suspend/resume cycle and the SRAM is not cleared.

Can a malicious process submit a job immediately after another process's
job and craft a command stream to DMA the contents of the
ETHOSU_SRAM_REGION to its own memory, exfiltrating the previous process's
weights or intermediate activations?


> drivers/accel/ethosu/ethosu_perfmon.c:ethosu_ioctl_perfmon_create()
> {
> 	/* Number of monitored counters cannot exceed HW limits. */
> 	if (req->ncounters > ethosu->npu_info.pmu_counters)
> 		return -EINVAL;
> 
> 	[ ... ]
> 
> 	perfmon = kzalloc_flex(*perfmon, values, req->ncounters);
> 	if (!perfmon)
> 		return -ENOMEM;
> 
> 	for (i = 0; i < req->ncounters - 1; i++)
> 		perfmon->counters[i] = req->counters[i];

[Severity: High]
This is a pre-existing issue, but does this lack an upper bound check on
the UAPI array size?

The function validates req->ncounters against the hardware-reported count
rather than the static UAPI array size limit
(DRM_ETHOSU_MAX_PERF_EVENT_COUNTERS, which is 8).

If the hardware reports more than 8 counters, and userspace passes
req->ncounters > 8, will this loop read past the end of the req->counters
array and write past the end of the perfmon->counters array, corrupting the
dynamically allocated values array?


> drivers/accel/ethosu/ethosu_job.c:ethosu_job_timedout()
> {
> 	[ ... ]
> 
> 	cmdaddr = readl_relaxed(dev->regs + NPU_REG_QREAD);
> 
> 	[ ... ]
> 
> 	dev_err(dev->base.dev, "NPU sched timed out: NPU %s, cmdstream offset 0x%x: 0x%x\n",
> 		running ? "running" : "stopped",
> 		cmdaddr, bocmds[cmdaddr / 4]);

[Severity: High]
This is a pre-existing issue, but can this cause an out-of-bounds memory
read?

Since cmdaddr is read directly from the hardware and entirely unvalidated,
if userspace crafts a malformed command stream that hangs the NPU and
leaves QREAD with a large value, will cmdaddr / 4 exceed the bounds of the
mapped bocmds buffer and cause an invalid memory access?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260908-ethosu-fixes-v3-0-490fe215286f@kernel.org?part=4

  reply	other threads:[~2026-09-08 22:18 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 22:04 [PATCH v3 00/22] accel: ethosu: Another batch of fixes Rob Herring (Arm)
2026-09-08 22:04 ` [PATCH v3 01/22] accel: ethosu: Suspend after initialization Rob Herring (Arm)
2026-09-08 22:18   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 02/22] accel: ethosu: Ensure suspended on removal Rob Herring (Arm)
2026-09-08 22:19   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 03/22] accel: ethosu: Fix probe error cleanup Rob Herring (Arm)
2026-09-08 22:18   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 04/22] accel: ethosu: Disable clocks on PM setup failure Rob Herring (Arm)
2026-09-08 22:18   ` sashiko-bot [this message]
2026-09-08 22:04 ` [PATCH v3 05/22] accel: ethosu: Quiesce jobs before scheduler teardown Rob Herring (Arm)
2026-09-08 22:20   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 06/22] accel: ethosu: Prevent command stream export Rob Herring (Arm)
2026-09-08 22:04 ` [PATCH v3 07/22] accel: ethosu: Move DMA mode to src/dst struct Rob Herring (Arm)
2026-09-08 22:04 ` [PATCH v3 08/22] accel: ethosu: Track command stream register setup Rob Herring (Arm)
2026-09-08 22:04 ` [PATCH v3 09/22] accel: ethosu: Factor buffer bounds checks Rob Herring (Arm)
2026-09-08 22:04 ` [PATCH v3 10/22] accel: ethosu: Fix NHCWB16 bounds calculation Rob Herring (Arm)
2026-09-08 22:19   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 11/22] accel: ethosu: Validate secondary streams Rob Herring (Arm)
2026-09-08 22:22   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 12/22] accel: ethosu: Reject unsupported commands Rob Herring (Arm)
2026-09-08 22:04 ` [PATCH v3 13/22] accel: ethosu: Validate all feature map tiles Rob Herring (Arm)
2026-09-08 22:14   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 14/22] accel: ethosu: Account for feature map element size Rob Herring (Arm)
2026-09-08 22:20   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 15/22] accel: ethosu: Validate convolution parameter Rob Herring (Arm)
2026-09-08 22:04 ` [PATCH v3 16/22] accel: ethosu: Account for kernel dilation in IFM size Rob Herring (Arm)
2026-09-08 22:14   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 17/22] accel: ethosu: Reject reserved command encodings Rob Herring (Arm)
2026-09-08 22:04 ` [PATCH v3 18/22] accel: ethosu: Validate accumulator input Rob Herring (Arm)
2026-09-08 22:23   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 19/22] accel: ethosu: Restrict dynamic IFM2 weights Rob Herring (Arm)
2026-09-08 22:24   ` sashiko-bot
2026-09-08 22:04 ` [PATCH v3 20/22] accel: ethosu: Split U65 and U85 DMA length validation Rob Herring (Arm)
2026-09-08 22:04 ` [PATCH v3 21/22] accel: ethosu: Validate OFM transpose Rob Herring (Arm)
2026-09-08 22:04 ` [PATCH v3 22/22] accel: ethosu: Validate resize operations Rob Herring (Arm)

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=20260908221817.F25721F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox