All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wandun Chen" <chenwandun1@gmail.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 4/5] of: reserved_mem: reject static regions overlapping no-map memory
Date: Sun, 20 Sep 2026 10:03:47 +0000	[thread overview]
Message-ID: <20260920100347.9D08A1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260920092852.614973-5-chenwandun1@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] of: reserved_mem: integer overflow in rmem_overlaps_check bypasses overlap detection
--

commit bab4bcea3e71f149872f45d815c003c14a811a0a
Author: Wandun Chen <chenwandun@lixiang.com>

of: reserved_mem: reject static regions overlapping no-map memory

This commit updates the reserved memory initialization to reject static no-map
regions that overlap with existing reserved no-map memory. It also skips
no-map regions during the late scan if they overlap with already reserved
ones, preventing multiple drivers from mapping the same physical memory.

Link: https://sashiko.dev/#/message/20260814084718.29C341F000E9%40smtp.kernel.org [1]

> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index 3a6c6dbfd7b11..8d2057f2ac12e 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c

[ ... ]

> @@ -266,6 +267,20 @@ static void __init __rmem_check_for_overlap(void)
>  	}
>  }
>  
> +static bool __init rmem_overlaps_check(phys_addr_t base, phys_addr_t size,
> +				       int start)
> +{
> +	int i;
> +
> +	for (i = start; i < reserved_mem_count; i++) {
> +		struct reserved_mem *r = &reserved_mem[i];
> +
> +		if (memblock_addrs_overlap(base, size, r->base, r->size))
> +			return true;

[Severity: High]
Does this code allow an integer wrap-around to bypass the overlap check?

The size variable read from the device tree is used without being bounded by
memblock_cap_size() before calling memblock_addrs_overlap().

If a crafted device tree or overlay defines a static reserved memory node
with a size large enough to cause base + size to wrap around phys_addr_t,
the internal addition in memblock_addrs_overlap() could wrap. This would
cause it to incorrectly return false, bypassing this overlap check.

The region then reaches memblock_is_region_rsrv_rmem(), which does cap the
size and finds the valid overlap marked by an earlier valid region, allowing
multiple reserved memory regions to be mapped to the exact same physical
memory.

> +	}
> +	return false;
> +}
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260920092852.614973-1-chenwandun1@gmail.com?part=4

  reply	other threads:[~2026-09-20 10:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20  9:28 [PATCH v3 0/5] of: reserved_mem: several fixes about reserved memory Wandun Chen
2026-09-20  9:28 ` [PATCH v3 1/5] of: reserved_mem: release dynamically allocated no-map region on init failure Wandun Chen
2026-09-20  9:28 ` [PATCH v3 2/5] of: reserved_mem: retain static no-map memory " Wandun Chen
2026-09-20  9:28 ` [PATCH v3 3/5] of: reserved_mem: skip init for regions whose early reservation failed Wandun Chen
2026-09-20  9:28 ` [PATCH v3 4/5] of: reserved_mem: reject static regions overlapping no-map memory Wandun Chen
2026-09-20 10:03   ` sashiko-bot [this message]
2026-09-20  9:28 ` [PATCH v3 5/5] of: reserved_mem: reject static mapped regions overlapping existing reservations Wandun Chen
2026-09-20 10:13   ` sashiko-bot
2026-09-22  8:48 ` [PATCH v3 0/5] of: reserved_mem: several fixes about reserved memory Mike Rapoport
2026-09-22  9:24   ` Wandun
2026-10-03  8:04     ` Mike Rapoport
2026-10-06 13:26       ` Marek Szyprowski
2026-10-08  6:38         ` Mike Rapoport
2026-10-08  9:43           ` Marek Szyprowski

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=20260920100347.9D08A1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=chenwandun1@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.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 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.