Linux Hardening
 help / color / mirror / Atom feed
From: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
To: kees@kernel.org
Cc: tony.luck@intel.com, gpiccoli@igalia.com,
	linux-hardening@vger.kernel.org, kernel-dev@igalia.com,
	kernel@gpiccoli.net
Subject: [PATCH 1/2] pstore: Consolidate compression handling in both init paths
Date: Tue, 22 Sep 2026 18:19:01 -0300	[thread overview]
Message-ID: <20260922212532.98571-2-gpiccoli@igalia.com> (raw)
In-Reply-To: <20260922212532.98571-1-gpiccoli@igalia.com>

The pstore infrastructure can be initialized in two ways: either through
the filesystem registration at pstore_init(), or via backend registration
that calls pstore_register(). At the same time, we have a peculiarity
regarding pstore compression: multiple algorithms were once supported,
but they were phased out, and only "deflate" is now supported, along
with the backward-compatible "none" value.

These two apparently unrelated topics have one (lacking) point of
convergence: the compression parameter handling is done only in the
pstore registration phase, at allocate_buf_for_compression(). Now, if
the pstore fs gets registered prior to any backend registration, which
is common in practice, some funny scenarios are possible, for example:
users can set any string for compression and it is held in the
compression parameter up to the backend registration (if any). Another
one (maybe even more odd): it's possible to set any value to this
parameter even if CONFIG_PSTORE_COMPRESS is disabled, and such a value
is kept until backend registration, which is counter-intuitive.

Bring both initialization points of pstore in sync regarding the
compression set-up, by funneling the parameter handling through a
single function called in both paths. The __always_inline attribute
usage is deliberate and necessary: the pstore code relies on the
compiler's Dead Code Elimination (DCE) to drop references to zlib
symbols that may not be built. The code checks for CONFIG_PSTORE_COMPRESS
and bails early in some functions, which leads to zlib calls becoming
dead code that is gone with DCE. So, inlining is required here to
avoid undefined references to zlib symbols not built at link time.

On top of that, also improve the compression parameter module info.

Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---
 fs/pstore/platform.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 1d76c9d92056..f3a900cf2cfb 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -89,7 +89,7 @@ MODULE_PARM_DESC(backend, "specific backend to use");
  */
 static char *compress = "deflate";
 module_param(compress, charp, 0444);
-MODULE_PARM_DESC(compress, "compression to use");
+MODULE_PARM_DESC(compress, "compression to use (deflate/none)");
 
 /* How much of the kernel log to snapshot */
 unsigned int kmsg_bytes = CONFIG_PSTORE_DEFAULT_KMSG_BYTES;
@@ -201,16 +201,12 @@ static int pstore_compress(const void *in, void *out,
 	return zstream.total_out;
 }
 
-static void allocate_buf_for_compression(void)
+static __always_inline bool compress_param_adjust(void)
 {
-	size_t compressed_size;
-	char *buf;
-
-	/* Skip if not built-in or compression disabled. */
 	if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !compress ||
 	    !strcmp(compress, "none")) {
 		compress = NULL;
-		return;
+		return false;
 	}
 
 	if (strcmp(compress, "deflate")) {
@@ -219,6 +215,16 @@ static void allocate_buf_for_compression(void)
 		compress = "deflate";
 	}
 
+	return true;
+}
+
+static void allocate_buf_for_compression(void)
+{
+	size_t compressed_size;
+	char *buf;
+
+	if (!compress_param_adjust())
+		return;
 	/*
 	 * The compression buffer only needs to be as large as the maximum
 	 * uncompressed record size, since any record that would be expanded by
@@ -747,6 +753,8 @@ static int __init pstore_init(void)
 {
 	int ret;
 
+	compress_param_adjust();
+
 	ret = pstore_init_fs();
 	if (ret)
 		free_buf_for_compression();
-- 
2.50.1


  reply	other threads:[~2026-09-22 21:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 21:19 [PATCH 0/2] Small improvements on pstore user experience Guilherme G. Piccoli
2026-09-22 21:19 ` Guilherme G. Piccoli [this message]
2026-09-22 21:19 ` [PATCH 2/2] pstore: Allow kmsg_bytes parameter to be written at runtime Guilherme G. Piccoli
2026-09-23  7:20 ` [PATCH 0/2] Small improvements on pstore user experience Kees Cook
2026-09-23 14:30   ` Guilherme G. Piccoli
2026-10-06 20:35     ` Guilherme G. Piccoli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260922212532.98571-2-gpiccoli@igalia.com \
    --to=gpiccoli@igalia.com \
    --cc=kees@kernel.org \
    --cc=kernel-dev@igalia.com \
    --cc=kernel@gpiccoli.net \
    --cc=linux-hardening@vger.kernel.org \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox