Commit 7e8cc8dc authored by Kees Cook's avatar Kees Cook

pstore: Always allocate buffer for decompression

Currently, pstore_mkfile() performs a memcpy() of the record contents,
so it can live anywhere. However, this is needlessly wasteful. In
preparation of pstore_mkfile() keeping the record contents, always
allocate a buffer for the contents.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent 76cc9580
...@@ -768,6 +768,7 @@ EXPORT_SYMBOL_GPL(pstore_unregister); ...@@ -768,6 +768,7 @@ EXPORT_SYMBOL_GPL(pstore_unregister);
static void decompress_record(struct pstore_record *record) static void decompress_record(struct pstore_record *record)
{ {
int unzipped_len; int unzipped_len;
char *decompressed;
/* Only PSTORE_TYPE_DMESG support compression. */ /* Only PSTORE_TYPE_DMESG support compression. */
if (!record->compressed || record->type != PSTORE_TYPE_DMESG) { if (!record->compressed || record->type != PSTORE_TYPE_DMESG) {
...@@ -783,17 +784,29 @@ static void decompress_record(struct pstore_record *record) ...@@ -783,17 +784,29 @@ static void decompress_record(struct pstore_record *record)
unzipped_len = pstore_decompress(record->buf, big_oops_buf, unzipped_len = pstore_decompress(record->buf, big_oops_buf,
record->size, big_oops_buf_sz); record->size, big_oops_buf_sz);
if (unzipped_len > 0) { if (unzipped_len <= 0) {
if (record->ecc_notice_size) pr_err("decompression failed: %d\n", unzipped_len);
memcpy(big_oops_buf + unzipped_len, return;
record->buf + record->size, }
/* Build new buffer for decompressed contents. */
decompressed = kmalloc(unzipped_len + record->ecc_notice_size,
GFP_KERNEL);
if (!decompressed) {
pr_err("decompression ran out of memory\n");
return;
}
memcpy(decompressed, big_oops_buf, unzipped_len);
/* Append ECC notice to decompressed buffer. */
memcpy(decompressed + unzipped_len, record->buf + record->size,
record->ecc_notice_size); record->ecc_notice_size);
/* Swap out compresed contents with decompressed contents. */
kfree(record->buf); kfree(record->buf);
record->buf = big_oops_buf; record->buf = decompressed;
record->size = unzipped_len; record->size = unzipped_len;
record->compressed = false; record->compressed = false;
} else
pr_err("decompression failed: %d\n", unzipped_len);
} }
/* /*
...@@ -819,13 +832,10 @@ void pstore_get_records(int quiet) ...@@ -819,13 +832,10 @@ void pstore_get_records(int quiet)
decompress_record(&record); decompress_record(&record);
rc = pstore_mkfile(&record); rc = pstore_mkfile(&record);
/* Free buffer other than big oops */
if (record.buf != big_oops_buf)
kfree(record.buf);
if (rc && (rc != -EEXIST || !quiet)) if (rc && (rc != -EEXIST || !quiet))
failed++; failed++;
kfree(record.buf);
memset(&record, 0, sizeof(record)); memset(&record, 0, sizeof(record));
record.psi = psi; record.psi = psi;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment