Skip to contentSkip to conversation

pstore/ram: Write new dumps to start of recycled zones

PATCH In review Kees Cook 2 participants 2 messages Jan 7, 2020 – Jan 26, 2020

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 pstore/ram: Write new dumps to start of recycled zones

From: Aleksandr Yashkin <[email protected]>

[ Upstream commit 9e5f1c19800b808a37fb9815a26d382132c26c3d ]

The ram_core.c routines treat przs as circular buffers. When writing a new crash dump, the old buffer needs to be cleared so that the new dump doesn't end up in the wrong place (i.e. at the end).

The solution to this problem is to reset the circular buffer state before writing a new Oops dump.

Fixes 896fc1f0c4c6 ("pstore/ram: Switch to persistent_ram routines")
[kees: backport to v4.9]
---
 fs/pstore/ram.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
fs/pstore/ram.c +11 -0
index 59d93acc29c7..fa0e89edb62d 100644
@@ -319,6 +319,17 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
 
 	prz = cxt->przs[cxt->dump_write_cnt];
 
+	/*
+	 * Since this is a new crash dump, we need to reset the buffer in
+	 * case it still has an old dump present. Without this, the new dump
+	 * will get appended, which would seriously confuse anything trying
+	 * to check dump file contents. Specifically, ramoops_read_kmsg_hdr()
+	 * expects to find a dump header in the beginning of buffer data, so
+	 * we must to reset the buffer values, in order to ensure that the
+	 * header will be written to the beginning of the buffer.
+	 */
+	persistent_ram_zap(prz);
+
 	hlen = ramoops_write_kmsg_hdr(prz, compressed);
 	if (size + hlen > prz->buffer_size)
 		size = prz->buffer_size - hlen;
Signature · 5 lines
2.20.1


-- 
Kees Cook
#1 lore raw
Quoted 3 lines · Kees Cook

From: Aleksandr Yashkin <[email protected]>

[ Upstream commit 9e5f1c19800b808a37fb9815a26d382132c26c3d ]

This looks applicable to 3.16 as well, so I've queued it up.

Ben.

Quoted 44 lines

The ram_core.c routines treat przs as circular buffers. When writing a new crash dump, the old buffer needs to be cleared so that the new dump doesn't end up in the wrong place (i.e. at the end).

The solution to this problem is to reset the circular buffer state before writing a new Oops dump.

Fixes 896fc1f0c4c6 ("pstore/ram: Switch to persistent_ram routines")
[kees: backport to v4.9]
---
 fs/pstore/ram.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
fs/pstore/ram.c +11 -0
index 59d93acc29c7..fa0e89edb62d 100644
@@ -319,6 +319,17 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
 
 	prz = cxt->przs[cxt->dump_write_cnt];
 
+	/*
+	 * Since this is a new crash dump, we need to reset the buffer in
+	 * case it still has an old dump present. Without this, the new dump
+	 * will get appended, which would seriously confuse anything trying
+	 * to check dump file contents. Specifically, ramoops_read_kmsg_hdr()
+	 * expects to find a dump header in the beginning of buffer data, so
+	 * we must to reset the buffer values, in order to ensure that the
+	 * header will be written to the beginning of the buffer.
+	 */
+	persistent_ram_zap(prz);
+
 	hlen = ramoops_write_kmsg_hdr(prz, compressed);
 	if (size + hlen > prz->buffer_size)
 		size = prz->buffer_size - hlen;
Signature · 1 line
2.20.1
Signature · 2 lines
Ben Hutchings
The program is absolutely right; therefore, the computer must be wrong.