Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Yue Hu and committed by
Kees Cook
47afd7ae 1e0f67a9

+3
+3
fs/pstore/ram.c
··· 425 425 426 426 /* Build header and append record contents. */ 427 427 hlen = ramoops_write_kmsg_hdr(prz, record); 428 + if (!hlen) 429 + return -ENOMEM; 430 + 428 431 size = record->size; 429 432 if (size + hlen > prz->buffer_size) 430 433 size = prz->buffer_size - hlen;