Re: [PATCH 5/5] ARM: NOMMU: pmsa-v8: Fix off-by-one in __pmsav8_setup_region()
From: Vladimir Murzin
Date: Wed Nov 25 2026 - 08:21:01 EST
On 11/25/26 02:57, Brad Hawthorne wrote:
> __pmsav8_setup_region() rejects "number > mpu_max_regions", which lets
> number == mpu_max_regions through. Regions are numbered from 0, so
> that number names a region the MPU does not have. Reject it.
>
> A Cortex-M33 can be built with 4 regions. Under QEMU (mps2-an505) with
> a 4-region MPU, QEMU logs "MPU region out of range 4/4" and the kernel
> takes an unhandled exception during the setup. With this patch the
> setup warns "MPU region initialization failure! -2" and the kernel
> faults later, in memblock_alloc_try_nid(), because RAM that region
> would have mapped has none. On an RP2350 board (Cortex-M33, 8 regions)
> the boot is unchanged.
>
> This patch was written with an AI coding assistant (Claude Opus 5.5,
> Anthropic): it found the bug in review, wrote the fix, the QEMU tests,
> the board test and this changelog, and ran them; I reviewed the
> reasoning and the test results.
>
> Fixes: 046835b4aa22 ("ARM: 8757/1: NOMMU: Support PMSAv8 MPU")
> Signed-off-by: Brad Hawthorne <brad@xxxxxx>
> ---
> arch/arm/mm/pmsa-v8.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/mm/pmsa-v8.c b/arch/arm/mm/pmsa-v8.c
> index 28cdc5468406..e5353a030731 100644
> --- a/arch/arm/mm/pmsa-v8.c
> +++ b/arch/arm/mm/pmsa-v8.c
> @@ -140,7 +140,7 @@ static int __init __mpu_max_regions(void)
>
> static int __init __pmsav8_setup_region(unsigned int number, u32 bar, u32 lar)
> {
> - if (number > mpu_max_regions
> + if (number >= mpu_max_regions
> || number >= MPU_MAX_REGIONS)
> return -ENOENT;
>
> -- 2.43.0
Reviewed-by: Vladimir Murzin <vladimir.murzin@xxxxxxx>