Commit 5b07aaca authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'pstore-v6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull pstore updates from Kees Cook:

 - Greatly simplify compression support (Ard Biesheuvel)

 - Avoid crashes for corrupted offsets when prz size is 0 (Enlin Mu)

 - Expand range of usable record sizes (Yuxiao Zhang)

 - Fix kernel-doc warning (Matthew Wilcox)

* tag 'pstore-v6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  pstore: Fix kernel-doc warning
  pstore: Support record sizes larger than kmalloc() limit
  pstore/ram: Check start of empty przs during init
  pstore: Replace crypto API compression with zlib_deflate library calls
  pstore: Remove worst-case compression size logic
parents 547635c6 af58740d
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-2.0-only
config PSTORE config PSTORE
tristate "Persistent store support" tristate "Persistent store support"
select CRYPTO if PSTORE_COMPRESS
default n default n
help help
This option enables generic access to platform level This option enables generic access to platform level
...@@ -22,99 +21,18 @@ config PSTORE_DEFAULT_KMSG_BYTES ...@@ -22,99 +21,18 @@ config PSTORE_DEFAULT_KMSG_BYTES
Defines default size of pstore kernel log storage. Defines default size of pstore kernel log storage.
Can be enlarged if needed, not recommended to shrink it. Can be enlarged if needed, not recommended to shrink it.
config PSTORE_DEFLATE_COMPRESS
tristate "DEFLATE (ZLIB) compression"
default y
depends on PSTORE
select CRYPTO_DEFLATE
help
This option enables DEFLATE (also known as ZLIB) compression
algorithm support.
config PSTORE_LZO_COMPRESS
tristate "LZO compression"
depends on PSTORE
select CRYPTO_LZO
help
This option enables LZO compression algorithm support.
config PSTORE_LZ4_COMPRESS
tristate "LZ4 compression"
depends on PSTORE
select CRYPTO_LZ4
help
This option enables LZ4 compression algorithm support.
config PSTORE_LZ4HC_COMPRESS
tristate "LZ4HC compression"
depends on PSTORE
select CRYPTO_LZ4HC
help
This option enables LZ4HC (high compression) mode algorithm.
config PSTORE_842_COMPRESS
bool "842 compression"
depends on PSTORE
select CRYPTO_842
help
This option enables 842 compression algorithm support.
config PSTORE_ZSTD_COMPRESS
bool "zstd compression"
depends on PSTORE
select CRYPTO_ZSTD
help
This option enables zstd compression algorithm support.
config PSTORE_COMPRESS config PSTORE_COMPRESS
def_bool y bool "Pstore compression (deflate)"
depends on PSTORE depends on PSTORE
depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS || \ select ZLIB_INFLATE
PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS || \ select ZLIB_DEFLATE
PSTORE_842_COMPRESS || PSTORE_ZSTD_COMPRESS default y
choice
prompt "Default pstore compression algorithm"
depends on PSTORE_COMPRESS
help help
This option chooses the default active compression algorithm. Whether pstore records should be compressed before being written to
This change be changed at boot with "pstore.compress=..." on the backing store. This is implemented using the zlib 'deflate'
the kernel command line. algorithm, using the library implementation instead of using the full
blown crypto API. This reduces the risk of secondary oopses or other
Currently, pstore has support for 6 compression algorithms: problems while pstore is recording panic metadata.
deflate, lzo, lz4, lz4hc, 842 and zstd.
The default compression algorithm is deflate.
config PSTORE_DEFLATE_COMPRESS_DEFAULT
bool "deflate" if PSTORE_DEFLATE_COMPRESS
config PSTORE_LZO_COMPRESS_DEFAULT
bool "lzo" if PSTORE_LZO_COMPRESS
config PSTORE_LZ4_COMPRESS_DEFAULT
bool "lz4" if PSTORE_LZ4_COMPRESS
config PSTORE_LZ4HC_COMPRESS_DEFAULT
bool "lz4hc" if PSTORE_LZ4HC_COMPRESS
config PSTORE_842_COMPRESS_DEFAULT
bool "842" if PSTORE_842_COMPRESS
config PSTORE_ZSTD_COMPRESS_DEFAULT
bool "zstd" if PSTORE_ZSTD_COMPRESS
endchoice
config PSTORE_COMPRESS_DEFAULT
string
depends on PSTORE_COMPRESS
default "deflate" if PSTORE_DEFLATE_COMPRESS_DEFAULT
default "lzo" if PSTORE_LZO_COMPRESS_DEFAULT
default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
default "842" if PSTORE_842_COMPRESS_DEFAULT
default "zstd" if PSTORE_ZSTD_COMPRESS_DEFAULT
config PSTORE_CONSOLE config PSTORE_CONSOLE
bool "Log kernel console messages" bool "Log kernel console messages"
......
...@@ -54,7 +54,7 @@ static void free_pstore_private(struct pstore_private *private) ...@@ -54,7 +54,7 @@ static void free_pstore_private(struct pstore_private *private)
if (!private) if (!private)
return; return;
if (private->record) { if (private->record) {
kfree(private->record->buf); kvfree(private->record->buf);
kfree(private->record->priv); kfree(private->record->priv);
kfree(private->record); kfree(private->record);
} }
......
This diff is collapsed.
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/mm.h>
#include "internal.h" #include "internal.h"
#include "ram_internal.h" #include "ram_internal.h"
...@@ -268,7 +269,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) ...@@ -268,7 +269,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)
/* ECC correction notice */ /* ECC correction notice */
record->ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0); record->ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0);
record->buf = kmalloc(size + record->ecc_notice_size + 1, GFP_KERNEL); record->buf = kvzalloc(size + record->ecc_notice_size + 1, GFP_KERNEL);
if (record->buf == NULL) { if (record->buf == NULL) {
size = -ENOMEM; size = -ENOMEM;
goto out; goto out;
...@@ -282,7 +283,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) ...@@ -282,7 +283,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)
out: out:
if (free_prz) { if (free_prz) {
kfree(prz->old_log); kvfree(prz->old_log);
kfree(prz); kfree(prz);
} }
...@@ -833,7 +834,7 @@ static int ramoops_probe(struct platform_device *pdev) ...@@ -833,7 +834,7 @@ static int ramoops_probe(struct platform_device *pdev)
*/ */
if (cxt->pstore.flags & PSTORE_FLAGS_DMESG) { if (cxt->pstore.flags & PSTORE_FLAGS_DMESG) {
cxt->pstore.bufsize = cxt->dprzs[0]->buffer_size; cxt->pstore.bufsize = cxt->dprzs[0]->buffer_size;
cxt->pstore.buf = kzalloc(cxt->pstore.bufsize, GFP_KERNEL); cxt->pstore.buf = kvzalloc(cxt->pstore.bufsize, GFP_KERNEL);
if (!cxt->pstore.buf) { if (!cxt->pstore.buf) {
pr_err("cannot allocate pstore crash dump buffer\n"); pr_err("cannot allocate pstore crash dump buffer\n");
err = -ENOMEM; err = -ENOMEM;
...@@ -866,7 +867,7 @@ static int ramoops_probe(struct platform_device *pdev) ...@@ -866,7 +867,7 @@ static int ramoops_probe(struct platform_device *pdev)
return 0; return 0;
fail_buf: fail_buf:
kfree(cxt->pstore.buf); kvfree(cxt->pstore.buf);
fail_clear: fail_clear:
cxt->pstore.bufsize = 0; cxt->pstore.bufsize = 0;
fail_init: fail_init:
...@@ -881,7 +882,7 @@ static void ramoops_remove(struct platform_device *pdev) ...@@ -881,7 +882,7 @@ static void ramoops_remove(struct platform_device *pdev)
pstore_unregister(&cxt->pstore); pstore_unregister(&cxt->pstore);
kfree(cxt->pstore.buf); kvfree(cxt->pstore.buf);
cxt->pstore.bufsize = 0; cxt->pstore.bufsize = 0;
ramoops_free_przs(cxt); ramoops_free_przs(cxt);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/mm.h>
#include <asm/page.h> #include <asm/page.h>
#include "ram_internal.h" #include "ram_internal.h"
...@@ -24,12 +25,10 @@ ...@@ -24,12 +25,10 @@
/** /**
* struct persistent_ram_buffer - persistent circular RAM buffer * struct persistent_ram_buffer - persistent circular RAM buffer
* *
* @sig: * @sig: Signature to indicate header (PERSISTENT_RAM_SIG xor PRZ-type value)
* signature to indicate header (PERSISTENT_RAM_SIG xor PRZ-type value) * @start: First valid byte in the buffer.
* @start: * @size: Number of valid bytes in the buffer.
* offset into @data where the beginning of the stored bytes begin * @data: The contents of the buffer.
* @size:
* number of valid bytes stored in @data
*/ */
struct persistent_ram_buffer { struct persistent_ram_buffer {
uint32_t sig; uint32_t sig;
...@@ -301,7 +300,7 @@ void persistent_ram_save_old(struct persistent_ram_zone *prz) ...@@ -301,7 +300,7 @@ void persistent_ram_save_old(struct persistent_ram_zone *prz)
if (!prz->old_log) { if (!prz->old_log) {
persistent_ram_ecc_old(prz); persistent_ram_ecc_old(prz);
prz->old_log = kmalloc(size, GFP_KERNEL); prz->old_log = kvzalloc(size, GFP_KERNEL);
} }
if (!prz->old_log) { if (!prz->old_log) {
pr_err("failed to allocate buffer\n"); pr_err("failed to allocate buffer\n");
...@@ -385,7 +384,7 @@ void *persistent_ram_old(struct persistent_ram_zone *prz) ...@@ -385,7 +384,7 @@ void *persistent_ram_old(struct persistent_ram_zone *prz)
void persistent_ram_free_old(struct persistent_ram_zone *prz) void persistent_ram_free_old(struct persistent_ram_zone *prz)
{ {
kfree(prz->old_log); kvfree(prz->old_log);
prz->old_log = NULL; prz->old_log = NULL;
prz->old_log_size = 0; prz->old_log_size = 0;
} }
...@@ -519,7 +518,7 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig, ...@@ -519,7 +518,7 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig,
sig ^= PERSISTENT_RAM_SIG; sig ^= PERSISTENT_RAM_SIG;
if (prz->buffer->sig == sig) { if (prz->buffer->sig == sig) {
if (buffer_size(prz) == 0) { if (buffer_size(prz) == 0 && buffer_start(prz) == 0) {
pr_debug("found existing empty buffer\n"); pr_debug("found existing empty buffer\n");
return 0; return 0;
} }
......
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