From: Yue Hu Date: Fri, 1 Feb 2019 03:27:32 +0000 (+0800) Subject: pstore/ram: Add kmsg hlen zero check to ramoops_pstore_write() X-Git-Tag: v5.1-rc1~97^2~1 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=47afd7ae65c737bfef67e9eb1424723d13b06787;p=linux.git 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 Signed-off-by: Kees Cook --- diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index d06e2f3e3bec..ec0e1da0596a 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -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;