From b075e5500132c3440bb1e449de7536e430cced66 Mon Sep 17 00:00:00 2001 From: Yue Hu Date: Fri, 1 Feb 2019 11:27:32 +0800 Subject: [PATCH] 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 --- fs/pstore/ram.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index cb8deb69529e..98f37312c0ce 100755 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -448,6 +448,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;