From 78bb6e412ce087c6c78e956209e94f0a0d666ccc Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Wed, 13 Feb 2019 19:30:26 +0800 Subject: [PATCH] pstore/ram: Avoid NULL deref in ftrace merging failure path mainline inclusion from mainline-5.0 commit 8665569e97dd category: bugfix bugzilla: 5808 CVE: NA ------------------------------------------------- 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 Fixes: 2fbea82bbb89 ("pstore: Merge per-CPU ftrace records into one") Cc: "Joel Fernandes (Google)" Signed-off-by: Kees Cook Signed-off-by: Hou Tao Reviewed-by: Yufen Yu Signed-off-by: Yang Yingliang --- fs/pstore/ram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 67bdbd3da52e..f20ccdeb6b59 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -299,6 +299,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) GFP_KERNEL); if (!tmp_prz) return -ENOMEM; + prz = tmp_prz; free_prz = true; while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) { @@ -321,7 +322,6 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) goto out; } record->id = 0; - prz = tmp_prz; } } -- GitLab