pstore/ram: Avoid NULL deref in ftrace merging failure path
authorKees Cook <keescook@chromium.org>
Tue, 4 Dec 2018 00:39:01 +0000 (16:39 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 13 Dec 2019 07:52:24 +0000 (08:52 +0100)
commit6b6f6030afd29f3470a3cf2630d9afdc1ec8a241
tree87c8d87b6f4deab2f20e84aad12da990f62a8994
parent9c6ca33f12cd4b678676c0a9e152c0e2c4e2a277
pstore/ram: Avoid NULL deref in ftrace merging failure path

[ Upstream commit 8665569e97dd52920713b95675409648986b5b0d ]

Given corruption in the ftrace records, it might be possible to allocate
tmp_prz without assigning prz to it, but still marking it as needing to
be freed, which would cause at least a NULL dereference.

smatch warnings:
fs/pstore/ram.c:340 ramoops_pstore_read() error: we previously assumed 'prz' could be null (see line 255)

https://lists.01.org/pipermail/kbuild-all/2018-December/055528.html

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 2fbea82bbb89 ("pstore: Merge per-CPU ftrace records into one")
Cc: "Joel Fernandes (Google)" <joel@joelfernandes.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/pstore/ram.c