Skip to content

Commit

Permalink
pstore/ram: Write new dumps to start of recycled zones
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Aleksandr Yashkin <a.yashkin@inango-systems.com>
Signed-off-by: Nikolay Merinov <n.merinov@inango-systems.com>
Signed-off-by: Ariel Gilman <a.gilman@inango-systems.com>
Link: https://lore.kernel.org/r/20191223133816.28155-1-n.merinov@inango-systems.com
Fixes: 896fc1f ("pstore/ram: Switch to persistent_ram routines")
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
  • Loading branch information
Aleksandr Yashkin authored and Kees Cook committed Jan 2, 2020
1 parent 8df955a commit 9e5f1c1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fs/pstore/ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,17 @@ static int notrace ramoops_pstore_write(struct pstore_record *record)

prz = cxt->dprzs[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);

/* Build header and append record contents. */
hlen = ramoops_write_kmsg_hdr(prz, record);
if (!hlen)
Expand Down

0 comments on commit 9e5f1c1

Please sign in to comment.