All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ryan Roberts" <ryan.roberts@arm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [RFC PATCH v1 2/8] misc/arm-cla: Add launch operation helpers
Date: Fri, 17 Jul 2026 11:01:07 +0000	[thread overview]
Message-ID: <20260717110108.B6F881F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260717104759.123203-3-ryan.roberts@arm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] A 32-bit integer overflow when calculating `reg_group + 8` causes out-of-bounds memory access on the `regs` buffer and an infinite loop for high register indices.
- [High] The safety bounds check `regidx + nregs > max_regidx` is vulnerable to a 64-bit integer overflow, allowing massive `nregs` values to bypass the limit check.
--

--- Patch [2]: [RFC PATCH v1 2/8] misc/arm-cla: Add launch operation helpers ---
commit dc6365dd6ad591fc5563520a7266898c01430558
Author: Jean-Philippe Brucker <jpb@kernel.org>

misc/arm-cla: Add launch operation helpers

CLA commands are issued by programming the LAUNCH register and polling LRESP.
This patch adds a common launch helper to perform this sequence and translates
response codes into Linux errors, along with register read and write support.

> diff --git a/drivers/misc/arm-cla/cla-ops.c b/drivers/misc/arm-cla/cla-ops.c
> new file mode 100644
> index 0000000000000..d594344a2eb45
> --- /dev/null
> +++ b/drivers/misc/arm-cla/cla-ops.c
[ ... ]
> +static int cla_op_access_reg(struct cla_dev *dev, u8 op,
> +			     enum cla_launch_data_mode data_mode,
> +			     unsigned int accid, unsigned int regidx,
> +			     size_t nregs, u64 *regs)
> +{
> +	int ret = -EINVAL;
> +	unsigned long max_regidx;
> +	struct cla_launch launch = {
> +		.op = op,
> +		.accid = accid,
> +		.data_mode = data_mode,
> +	};
> +
> +	switch (op) {
> +	case CLA_LAUNCH_OP_REGREAD:
> +	case CLA_LAUNCH_OP_REGWRITE:
> +		max_regidx = 0x100000000;
> +		break;
> +	default:
> +		WARN_ON(1);
> +		return -EINVAL;
> +	}
> +
> +	if (WARN_ON(regidx + nregs > max_regidx))

[Severity: High]
Does this check adequately protect against integer overflow? If nregs is very
large (for example, (size_t)-1), the addition of regidx and nregs can overflow
size_t. This would result in a small positive value that bypasses the
max_regidx limit.

Could this be rewritten to avoid wrap-around, perhaps by checking if nregs
is greater than max_regidx - regidx?

> +		return -EINVAL;
> +
> +	/* 1 to 8 registers accessed at a time, within the same 8-reg group */
> +	while (nregs > 0) {
> +		unsigned int reg_group = ALIGN_DOWN(regidx, 8);
> +		unsigned int max_reg = min(regidx + nregs, reg_group + 8);

[Severity: High]
Can reg_group + 8 overflow? Since regidx and reg_group are 32-bit unsigned
integers, if a caller passes a register index near the 32-bit maximum
(for example, 0xFFFFFFF8) and a small nregs value, reg_group + 8 will wrap
around to 0.

If max_reg evaluates to 0, ndata becomes 0 - regidx, which can yield a value
larger than the original nregs. Will this cause out-of-bounds memory accesses
on the regs buffer when passed to cla_op_launch(), and an infinite loop due to
underflowing nregs?

> +		unsigned int ndata = max_reg - regidx;
> +
> +		launch.ndata_m1 = ndata - 1;
> +		launch.regidx = regidx;
> +		launch.data = regs;
> +
> +		ret = cla_op_launch(dev, &launch);
> +		if (ret)
> +			break;
> +
> +		regidx += ndata;
> +		regs += ndata;
> +		nregs -= ndata;
> +	}
> +
> +	return ret;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260717104759.123203-1-ryan.roberts@arm.com?part=2

  reply	other threads:[~2026-07-17 11:01 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 10:47 [RFC PATCH v1 0/8] Arm Core Local Accelerator Driver Ryan Roberts
2026-07-17 10:47 ` [RFC PATCH v1 1/8] misc/arm-cla: Add driver skeleton and documentation Ryan Roberts
2026-07-17 10:56   ` sashiko-bot
2026-07-17 13:49   ` Arnd Bergmann
2026-07-17 15:44     ` Ryan Roberts
2026-07-17 16:10       ` Arnd Bergmann
2026-07-17 10:47 ` [RFC PATCH v1 2/8] misc/arm-cla: Add launch operation helpers Ryan Roberts
2026-07-17 11:01   ` sashiko-bot [this message]
2026-07-17 12:16   ` Arnd Bergmann
2026-07-17 10:47 ` [RFC PATCH v1 3/8] misc/arm-cla: Probe firmware-described devices Ryan Roberts
2026-07-17 10:57   ` sashiko-bot
2026-07-17 12:25   ` Arnd Bergmann
2026-07-17 12:36     ` Ryan Roberts
2026-07-17 10:47 ` [RFC PATCH v1 4/8] misc/arm-cla: Initialize devices on CPU bringup Ryan Roberts
2026-07-17 10:58   ` sashiko-bot
2026-07-17 10:47 ` [RFC PATCH v1 5/8] misc/arm-cla: Accelerator context save and restore Ryan Roberts
2026-07-17 10:58   ` sashiko-bot
2026-07-17 10:47 ` [RFC PATCH v1 6/8] misc/arm-cla: Set up memory translation context Ryan Roberts
2026-07-17 11:02   ` sashiko-bot
2026-07-17 10:47 ` [RFC PATCH v1 7/8] misc/arm-cla: Manage domain contexts Ryan Roberts
2026-07-17 11:01   ` sashiko-bot
2026-07-17 10:47 ` [RFC PATCH v1 8/8] misc/arm-cla: Add userspace interface Ryan Roberts
2026-07-17 11:10   ` sashiko-bot
2026-07-17 12:54   ` Arnd Bergmann
2026-07-17 14:35     ` Ryan Roberts
2026-07-17 15:31       ` Arnd Bergmann
2026-07-17 16:21         ` Ryan Roberts
2026-07-17 20:11           ` Arnd Bergmann
2026-07-17 11:33 ` [RFC PATCH v1 0/8] Arm Core Local Accelerator Driver Will Deacon
2026-07-17 12:09   ` Marc Zyngier
2026-07-17 12:33     ` Ryan Roberts
2026-07-17 12:30   ` Ryan Roberts
2026-07-17 13:32   ` Jason Gunthorpe
2026-07-17 13:42     ` Ryan Roberts

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=20260717110108.B6F881F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ryan.roberts@arm.com \
    --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.