]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
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)
committerMarcelo Henrique Cerri <marcelo.cerri@canonical.com>
Fri, 17 Jan 2020 17:22:20 +0000 (14:22 -0300)
BugLink: https://bugs.launchpad.net/bugs/1857158
[ 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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
fs/pstore/ram.c

index 617011a789380ba18c1bef5dc1ddcd11d9feb095..0255e46fb405527030cdb9a0d94b5759b8764362 100644 (file)
@@ -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;
                }
        }