
From: Yue Hu <huyue2@yulong.com> stable inclusion from stable-5.10 category: feature commit:47afd7ae65c737bfef67e9eb1424723d13b06787 issue: #I4919J -------------------------------- 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> (cherry picked from commit 47afd7ae65c737bfef67e9eb1424723d13b06787) Signed-off-by: roger <kongzhengrong@huawei.com> --- fs/pstore/ram.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index bc7af9393d8f..5d938d68b2b1 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -438,6 +438,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; -- 2.17.1