[PATCH 2/2] pstore/ram: Fix region bounds check wrap
From: Raul E Rangel
Date: Wed Nov 18 2026 - 17:42:13 EST
ramoops_init_przs() checks whether a region fits only after dividing by
record_size, so an oversized region can fail with a misleading record
count error instead of reporting that there is no room. Both
ramoops_init_przs() and ramoops_init_prz() also add the region size to
the current address when checking bounds, which can wrap and accept an
out-of-bounds region.
Check the remaining space before dividing by record_size, and subtract
from the total size instead of adding to the address so the bounds
check cannot wrap.
Fixes: c628937803c6 ("pstore/ram: Fix bounds checks for mem_size, record_size, console_size and ftrace_size")
Fixes: de83209249d6 ("pstore: Make ramoops_init_przs generic for other prz arrays")
Signed-off-by: Raul E Rangel <rrangel@xxxxxxxxxxxx>
---
fs/pstore/ram.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index aa056d0395a4..651f79f3187a 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -500,6 +500,14 @@ static int ramoops_init_przs(const char *name,
return 0;
}
+ if (mem_sz > cxt->size - (*paddr - cxt->phys_addr)) {
+ dev_err(dev, "no room for %s mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
+ name,
+ mem_sz, (unsigned long long)*paddr,
+ cxt->size, (unsigned long long)cxt->phys_addr);
+ goto fail;
+ }
+
/*
* If we have a negative record size, calculate it based on
* mem_sz / *cnt. If we have a positive record size, calculate
@@ -523,14 +531,6 @@ static int ramoops_init_przs(const char *name,
}
}
- if (*paddr + mem_sz - cxt->phys_addr > cxt->size) {
- dev_err(dev, "no room for %s mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
- name,
- mem_sz, (unsigned long long)*paddr,
- cxt->size, (unsigned long long)cxt->phys_addr);
- goto fail;
- }
-
zone_sz = mem_sz / *cnt;
zone_sz = ALIGN_DOWN(zone_sz, 2);
if (!zone_sz) {
@@ -590,7 +590,7 @@ static int ramoops_init_prz(const char *name,
if (!sz)
return 0;
- if (*paddr + sz - cxt->phys_addr > cxt->size) {
+ if (sz > cxt->size - (*paddr - cxt->phys_addr)) {
dev_err(dev, "no room for %s mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
name, sz, (unsigned long long)*paddr,
cxt->size, (unsigned long long)cxt->phys_addr);
--
2.56.1.708.g77570a6a1d-goog