[PATCH v5 7/9] platform/x86: hp-bioscfg: validate SPM state returned by firmware

From: Muhammad Bilal

Date: Wed Oct 07 2026 - 10:03:17 EST


status_show() indexes the 3-entry spm_state_types[] with the state byte
returned by firmware. update_spm_state() stores the same byte, which
key_mechanism_show() uses to index the 3-entry spm_mechanism_types[].
Neither is range checked, so a state above 2 makes the world-readable
status and key_mechanism files print a string from a pointer read past
the array.

Return -EIO for an out of range state.

Compile tested only.

Fixes: b2715aa2e135 ("platform/x86: hp-bioscfg: spmobj-attributes")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Muhammad Bilal <meatuni001@xxxxxxxxx>
---
Changes in v5:
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c
index 2d4a3720f80c..25477ecf8822 100644
--- a/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c
+++ b/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c
@@ -6,6 +6,7 @@
* Copyright (c) 2022 HP Development Company, L.P.
*/

+#include <linux/array_size.h>
#include "bioscfg.h"

static const char * const spm_state_types[] = {
@@ -118,6 +119,9 @@ static ssize_t update_spm_state(void)
if (ret < 0)
return ret;

+ if (data.state >= ARRAY_SIZE(spm_mechanism_types))
+ return -EIO;
+
bioscfg_drv.spm_data.mechanism = data.state;
if (bioscfg_drv.spm_data.mechanism)
bioscfg_drv.spm_data.is_enabled = 1;
@@ -153,6 +157,9 @@ static ssize_t status_show(struct kobject *kobj, struct kobj_attribute
if (ret < 0)
return ret;

+ if (data.state >= ARRAY_SIZE(spm_state_types))
+ return -EIO;
+
/*
* 'status' is a read-only file that returns ASCII text in
* JSON format reporting the status information.
--
2.55.0