Skip to contentSkip to conversation

pstore/ram: Avoid NULL deref in ftrace merging failure path

PATCH New Kees Cook 1 participant 1 message Dec 4, 2018 Pstore filesystem

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 pstore/ram: Avoid NULL deref in ftrace merging failure path

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

Fixes 2fbea82bbb89 ("pstore: Merge per-CPU ftrace records into one")
Cc "Joel Fernandes (Google)" <[email protected]>
---
 fs/pstore/ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/pstore/ram.c +1 -1
index e6d9560ea455..96f7d32cd184 100644
@@ -291,6 +291,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) {
@@ -309,7 +310,6 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)
 					goto out;
 			}
 			record->id = 0;
-			prz = tmp_prz;
 		}
 	}
 
Signature · 5 lines
2.17.1


-- 
Kees Cook