lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260201132240.2948732-1-stanksal@purdue.edu>
Date: Sun,  1 Feb 2026 13:22:40 +0000
From: Pwnverse <ritviktanksalkar@...il.com>
To: kees@...nel.org
Cc: gregkh@...uxfoundation.org,
	tony.luck@...el.com,
	gpiccoli@...lia.com,
	anton.vorontsov@...aro.org,
	linux-hardening@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	stable@...r.kernel.org,
	Sai Ritvik Tanksalkar <stanksal@...due.edu>
Subject: [PATCH v2] pstore/ram: fix buffer overflow in persistent_ram_save_old()

From: Sai Ritvik Tanksalkar <stanksal@...due.edu>

persistent_ram_save_old() can be called multiple times for the same
persistent_ram_zone (e.g., via ramoops_pstore_read -> ramoops_get_next_prz
for PSTORE_TYPE_DMESG records).

Currently, the function only allocates prz->old_log when it is NULL,
but it unconditionally updates prz->old_log_size to the current buffer
size and then performs memcpy_fromio() using this new size. If the
buffer size has grown since the first allocation (which can happen
across different kernel boot cycles), this leads to:

1. A heap buffer overflow (OOB write) in the memcpy_fromio() calls
2. A subsequent OOB read when ramoops_pstore_read() accesses the buffer
   using the incorrect (larger) old_log_size

The KASAN splat would look similar to:
  BUG: KASAN: slab-out-of-bounds in ramoops_pstore_read+0x...
  Read of size N at addr ... by task ...

Fix this by freeing and reallocating the buffer when the new size
exceeds the previously allocated size. This ensures old_log always has
sufficient space for the data being copied.

Fixes: 201e4aca5aa1 ("pstore/ram: Should update old dmesg buffer before reading")
Cc: stable@...r.kernel.org
Signed-off-by: Sai Ritvik Tanksalkar <stanksal@...due.edu>
---
v2: Fixed Signed-off-by to use real name (was using Github ID).
    Resending with proper mail client to preserve tabs.

 fs/pstore/ram_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index f1848cdd6d34..8df813a42a41 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -298,6 +298,14 @@ void persistent_ram_save_old(struct persistent_ram_zone *prz)
 	if (!size)
 		return;
 
+	/*
+	 * If the existing buffer is too small, free it so a new one is
+	 * allocated. This can happen when persistent_ram_save_old() is
+	 * called multiple times with different buffer sizes.
+	 */
+	if (prz->old_log && prz->old_log_size < size)
+		persistent_ram_free_old(prz);
+
 	if (!prz->old_log) {
 		persistent_ram_ecc_old(prz);
 		prz->old_log = kvzalloc(size, GFP_KERNEL);
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ