pstore/ram: Add kmsg hlen zero check to ramoops_pstore_write()

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 <huyue2@yulong.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
Yue Hu 2019-02-01 11:27:32 +08:00 committed by Kees Cook
parent 1e0f67a96a
commit 47afd7ae65
1 changed files with 3 additions and 0 deletions

View File

@ -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;