linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] pstore/ram: Validate ECC parameters against Reed-Solomon constraint
@ 2025-06-23  7:22 Naoya Tezuka
  0 siblings, 0 replies; only message in thread
From: Naoya Tezuka @ 2025-06-23  7:22 UTC (permalink / raw)
  To: Kees Cook, Tony Luck, Guilherme G . Piccoli
  Cc: Tzung-Bi Shih, linux-hardening, linux-kernel, Naoya Tezuka

The Reed-Solomon library enforces the constraint `n <= 2^m - 1` via a
BUG_ON() [1], where `n` is `block_size + ecc_size` and `m` is `symsize`
for the pstore RAM backend. A driver providing invalid parameters can
trigger this, leading to a kernel panic. For more details on the theory
behind, see [2].

This issue was discovered during developing chromeos_pstore driver [3].

Add a check to validate this constraint before initializing Reed-Solomon
codec. On failure, return -EINVAL to prevent the panic.

[1] https://elixir.bootlin.com/linux/v6.15/source/lib/reed_solomon/decode_rs.c#L43
[2] https://www.cs.cmu.edu/~guyb/realworld/reedsolomon/reed_solomon_codes.html
[3] https://lore.kernel.org/lkml/20250610050458.4014083-1-naoyatezuka@chromium.org/

Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: Naoya Tezuka <naoyatezuka@chromium.org>
---
Changes in v3:
- Fix missing closing parenthesis in pr_err() format string.
- Use [3] instead of Link: tag in commit message as suggested.
- Add Reviewed-by tag from Tzung-Bi Shih.
- Add changelog for v2 submission, which was previously omitted.

- Link to v2: https://lore.kernel.org/lkml/20250623062827.133373-1-naoyatezuka@chromium.org/

Changes in v2:
- Provide a link to BUG_ON() in commit message.
- Refine commit message as suggested.

- Link to v1: https://lore.kernel.org/lkml/20250620054757.1006729-1-naoyatezuka@chromium.org/
---
 fs/pstore/ram_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index f1848cdd6d34..64fa55daa47f 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -212,6 +212,14 @@ static int persistent_ram_init_ecc(struct persistent_ram_zone *prz,
 		return -EINVAL;
 	}
 
+	if (prz->ecc_info.block_size + prz->ecc_info.ecc_size >
+	    (1 << prz->ecc_info.symsize) - 1) {
+		pr_err("%s: invalid ecc parameters (block_size = %d, ecc_size = %d, symsize = %d)\n",
+		       __func__, prz->ecc_info.block_size,
+		       prz->ecc_info.ecc_size, prz->ecc_info.symsize);
+		return -EINVAL;
+	}
+
 	prz->buffer_size -= ecc_total;
 	prz->par_buffer = buffer->data + prz->buffer_size;
 	prz->par_header = prz->par_buffer +
-- 
2.50.0.rc2.701.gf1e915cc24-goog


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-06-23  7:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-23  7:22 [PATCH v3] pstore/ram: Validate ECC parameters against Reed-Solomon constraint Naoya Tezuka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).