Skip to content

Commit 2515071

Browse files
superm1ij-intel
authored andcommitted
platform/x86: hp-bioscfg: Fix kernel panic in GET_INSTANCE_ID macro
The GET_INSTANCE_ID macro that caused a kernel panic when accessing sysfs attributes: 1. Off-by-one error: The loop condition used '<=' instead of '<', causing access beyond array bounds. Since array indices are 0-based and go from 0 to instances_count-1, the loop should use '<'. 2. Missing NULL check: The code dereferenced attr_name_kobj->name without checking if attr_name_kobj was NULL, causing a null pointer dereference in min_length_show() and other attribute show functions. The panic occurred when fwupd tried to read BIOS configuration attributes: Oops: general protection fault [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] RIP: 0010:min_length_show+0xcf/0x1d0 [hp_bioscfg] Add a NULL check for attr_name_kobj before dereferencing and corrects the loop boundary to match the pattern used elsewhere in the driver. Cc: stable@vger.kernel.org Fixes: 5f94f18 ("platform/x86: hp-bioscfg: bioscfg-h") Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Link: https://patch.msgid.link/20260115203725.828434-3-mario.limonciello@amd.com Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent fdee1b0 commit 2515071

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/platform/x86/hp/hp-bioscfg/bioscfg.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <linux/wmi.h>
1212
#include <linux/types.h>
13+
#include <linux/string.h>
1314
#include <linux/device.h>
1415
#include <linux/module.h>
1516
#include <linux/kernel.h>
@@ -285,8 +286,9 @@ enum hp_wmi_data_elements {
285286
{ \
286287
int i; \
287288
\
288-
for (i = 0; i <= bioscfg_drv.type##_instances_count; i++) { \
289-
if (!strcmp(kobj->name, bioscfg_drv.type##_data[i].attr_name_kobj->name)) \
289+
for (i = 0; i < bioscfg_drv.type##_instances_count; i++) { \
290+
if (bioscfg_drv.type##_data[i].attr_name_kobj && \
291+
!strcmp(kobj->name, bioscfg_drv.type##_data[i].attr_name_kobj->name)) \
290292
return i; \
291293
} \
292294
return -EIO; \

0 commit comments

Comments
 (0)