Skip to content

Commit

Permalink
pstore/ram: Add kmsg hlen zero check to ramoops_pstore_write()
Browse files Browse the repository at this point in the history
If zero-length header happened in ramoops_write_kmsg_hdr(), that means
we will not be able to read back dmesg record later, since it will be
treated as invalid header in ramoops_pstore_read(). So we should not
execute the following code but return the error.

Signed-off-by: Yue Hu <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
Yue Hu authored and kees committed Feb 12, 2019
1 parent 1e0f67a commit 47afd7a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fs/pstore/ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ static int notrace ramoops_pstore_write(struct pstore_record *record)

/* Build header and append record contents. */
hlen = ramoops_write_kmsg_hdr(prz, record);
if (!hlen)
return -ENOMEM;

size = record->size;
if (size + hlen > prz->buffer_size)
size = prz->buffer_size - hlen;
Expand Down

0 comments on commit 47afd7a

Please sign in to comment.