Skip to contentSkip to conversation

pstore: Fix leaked pstore_record in pstore_get_backend_records()

PATCH Applied Douglas Anderson 2 participants 2 messages May 30, 2017 – May 31, 2017 Pstore filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pstore: Fix leaked pstore_record in pstore_get_backend_records()

When the "if (record->size <= 0)" test is true in pstore_get_backend_records() it's pretty clear that nobody holds a reference to the allocated pstore_record, yet we don't free it.

Let's free it.

Fixes 2a2b0acf768c ("pstore: Allocate records on heap instead of stack")
---
 fs/pstore/platform.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/pstore/platform.c +3 -1
index d468eec9b8a6..9defe98ff8b1 100644
@@ -846,8 +846,10 @@ void pstore_get_backend_records(struct pstore_info *psi,
 		record->size = psi->read(record);
 
 		/* No more records left in backend? */
-		if (record->size <= 0)
+		if (record->size <= 0) {
+			kfree(record);
 			break;
+		}
 
 		decompress_record(record);
 		rc = pstore_mkfile(root, record);
Signature · 1 line
2.13.0.219.gdb65acc882-goog
Applied
#1 lore raw
Quoted 8 lines · Douglas Anderson

When the "if (record->size <= 0)" test is true in pstore_get_backend_records() it's pretty clear that nobody holds a reference to the allocated pstore_record, yet we don't free it.

Let's free it.

Fixes 2a2b0acf768c ("pstore: Allocate records on heap instead of stack")

Thanks! Applied for -next.

-Kees

Quoted 23 lines
---
 fs/pstore/platform.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/pstore/platform.c +3 -2
index d468eec9b8a6..9defe98ff8b1 100644
@@ -846,8 +846,10 @@ void pstore_get_backend_records(struct pstore_info *psi,
                record->size = psi->read(record);
 
                /* No more records left in backend? */
-               if (record->size <= 0)
+               if (record->size <= 0) {
+                       kfree(record);
                        break;
+               }
 
                decompress_record(record);
                rc = pstore_mkfile(root, record);
--

2.13.0.219.gdb65acc882-goog

Signature · 2 lines
Kees Cook
Pixel Security