mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bjorn Andersson <andersson@kernel.org>
To: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>,
	 linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org
Subject: Re: [PATCH v3 5/5] remoteproc: fix OOB read via signed offset in rsc_table_for_each_entry()
Date: Tue, 4 Aug 2026 17:12:05 -0500	[thread overview]
Message-ID: <anJjeJQcf18MgKRg@baldur> (raw)
In-Reply-To: <20260803114331.3277263-6-mukesh.ojha@oss.qualcomm.com>

On Mon, Aug 03, 2026 at 05:13:31PM +0530, Mukesh Ojha wrote:
> table->offset[i] is a u32 from firmware, but was stored into a signed
> int.  A crafted offset like 0xFFFFFFF0 becomes -16, placing hdr 16 bytes
> before the table buffer.  The subsequent avail check was bypassed
> because the negative int was promoted to a large size_t in the
> expression "table_sz - offset - sizeof(*hdr)", yielding a large positive
> avail and letting the out-of-bounds hdr->type read proceed undetected.
> 
> Store the offset as u32 and validate it with unsigned comparisons before
> any pointer arithmetic.
> 

Fixes: fd2c15ec1dd3 ("remoteproc: resource table overhaul")

Regards,
Bjorn

> Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
> ---
>  include/linux/rsc_table.h | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/include/linux/rsc_table.h b/include/linux/rsc_table.h
> index 0ad9122c22af..71b60125310e 100644
> --- a/include/linux/rsc_table.h
> +++ b/include/linux/rsc_table.h
> @@ -310,17 +310,22 @@ static inline int rsc_table_for_each_entry(struct resource_table *table,
>  	int i, ret;
>  
>  	for (i = 0; i < table->num; i++) {
> -		int offset = table->offset[i];
> -		struct fw_rsc_hdr *hdr = (void *)table + offset;
> -		int avail = table_sz - offset - sizeof(*hdr);
> -		int rsc_offset = offset + sizeof(*hdr);
> -		void *rsc = (void *)hdr + sizeof(*hdr);
> +		u32 offset = table->offset[i];
> +		struct fw_rsc_hdr *hdr;
> +		int avail, rsc_offset;
> +		void *rsc;
>  
> -		if (avail < 0) {
> +		if (offset < sizeof(*table) || offset >= table_sz ||
> +		    table_sz - offset < sizeof(*hdr)) {
>  			dev_err(dev, "rsc table is truncated\n");
>  			return -EINVAL;
>  		}
>  
> +		hdr = (void *)table + offset;
> +		avail = table_sz - offset - sizeof(*hdr);
> +		rsc_offset = offset + sizeof(*hdr);
> +		rsc = (void *)hdr + sizeof(*hdr);
> +
>  		ret = cb(hdr->type, rsc, rsc_offset, avail, data);
>  		if (ret)
>  			return ret;
> -- 
> 2.53.0
> 

  reply	other threads:[~2026-08-04 22:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 11:43 [PATCH v3 0/5] remoteproc: Misc. RSC table changes Mukesh Ojha
2026-08-03 11:43 ` [PATCH v3 1/5] MAINTAINERS: add rsc_table.h to remoteproc entry Mukesh Ojha
2026-08-03 11:43 ` [PATCH v3 2/5] remoteproc: fix coding style issues in remoteproc.h Mukesh Ojha
2026-08-03 11:43 ` [PATCH v3 3/5] remoteproc: replace BSD blurb with SPDX identifier " Mukesh Ojha
2026-08-03 11:43 ` [PATCH v3 4/5] remoteproc: replace BSD blurb with SPDX identifier in rsc_table.h Mukesh Ojha
2026-08-03 11:43 ` [PATCH v3 5/5] remoteproc: fix OOB read via signed offset in rsc_table_for_each_entry() Mukesh Ojha
2026-08-04 22:12   ` Bjorn Andersson [this message]
2026-08-05  3:34 ` [PATCH v3 0/5] remoteproc: Misc. RSC table changes Bjorn Andersson

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=anJjeJQcf18MgKRg@baldur \
    --to=andersson@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mukesh.ojha@oss.qualcomm.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

all inboxes | Powered by JetHome®