From: Yadan Fan <ydfan@suse.com>
To: tsbogend@alpha.franken.de
Cc: akpm@linux-foundation.org, rppt@kernel.org, liam@infradead.org,
catalin.marinas@arm.com, jiaxun.yang@flygoat.com,
paulburton@kernel.org, linux-mips@vger.kernel.org,
linux-kernel@vger.kernel.org, ydfan@suse.com
Subject: MIPS: mm: Fix out-of-bounds write in maar_res_walk()
Date: Mon, 25 May 2026 19:06:40 +0800 [thread overview]
Message-ID: <d060de27-6fdb-452b-95f3-dbcc48db17ff@suse.com> (raw)
maar_res_walk() uses wi->num_cfg as the index into the fixed-size
wi->cfg array, but checks whether the array is full only after it has
filled the selected entry. If walk_system_ram_range() reports more than
16 memory ranges, the overflow call writes one struct maar_config past
the end of the array before WARN_ON() prevents num_cfg from advancing.
Move the full-array check before taking the array slot. Keep the
existing behavior of warning and returning 0 when the scratch array has
no room left.
Fixes: a5718fe8f70f ("MIPS: mm: Drop boot_mem_map")
Signed-off-by: Yadan Fan <ydfan@suse.com>
---
arch/mips/mm/init.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 55b25e85122a..0ba958b7ffa5 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -272,9 +272,15 @@ static int maar_res_walk(unsigned long start_pfn, unsigned long nr_pages,
void *data)
{
struct maar_walk_info *wi = data;
- struct maar_config *cfg = &wi->cfg[wi->num_cfg];
+ struct maar_config *cfg;
unsigned int maar_align;
+ /* Ensure we don't overflow the cfg array */
+ if (WARN_ON(wi->num_cfg >= ARRAY_SIZE(wi->cfg)))
+ return 0;
+
+ cfg = &wi->cfg[wi->num_cfg];
+
/* MAAR registers hold physical addresses right shifted by 4 bits */
maar_align = BIT(MIPS_MAAR_ADDR_SHIFT + 4);
@@ -283,9 +289,7 @@ static int maar_res_walk(unsigned long start_pfn, unsigned long nr_pages,
cfg->upper = ALIGN_DOWN(PFN_PHYS(start_pfn + nr_pages), maar_align) - 1;
cfg->attrs = MIPS_MAAR_S;
- /* Ensure we don't overflow the cfg array */
- if (!WARN_ON(wi->num_cfg >= ARRAY_SIZE(wi->cfg)))
- wi->num_cfg++;
+ wi->num_cfg++;
return 0;
}
--
2.51.0
next reply other threads:[~2026-05-25 11:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 11:06 Yadan Fan [this message]
2026-05-25 14:15 ` MIPS: mm: Fix out-of-bounds write in maar_res_walk() Liam R. Howlett
2026-05-26 0:51 ` Yadan Fan
2026-05-26 6:57 ` Thomas Bogendoerfer
2026-05-26 8:50 ` Yadan Fan
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=d060de27-6fdb-452b-95f3-dbcc48db17ff@suse.com \
--to=ydfan@suse.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=jiaxun.yang@flygoat.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=paulburton@kernel.org \
--cc=rppt@kernel.org \
--cc=tsbogend@alpha.franken.de \
/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