Skip to contentSkip to conversation

platform/x86: hp-bioscfg: fix empty auth token overflow and clean up audit log loop

PATCH Superseded Muhammad Bilal 2 participants 9 messages Aug 18 – Oct 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover platform/x86: hp-bioscfg: fix empty auth token overflow and clean up audit log loop

Hi Ilpo,

This is v3 for the remaining two patches (patches 4 and 5) from the v2 series [2], addressing your review feedback:

- Patch 1/2 (was patch 4 in v2): Remove the special-case "if (!authlen)" return entirely in hp_calculate_security_buffer(). The generic calculation already naturally yields 20 bytes for empty strings, eliminating duplicate logic and fixing the 16-byte heap overflow (reported earlier by Josh Snyder [3]).

- Patch 2/2 (was patch 5 in v2): Remove the dead inner bounds check in audit_log_entries_show() since "count * LOG_ENTRY_SIZE > PAGE_SIZE" is already checked prior to entering the loop, and clean up the redundant "else" block after "break".

Changes in v3:
- Patch 1/2: Remove the "if (!authlen)" check completely instead of adjusting the formula, avoiding code duplication as suggested by Ilpo Järvinen.
- Patch 2/2: Remove the dead loop check and the redundant else block instead of adjusting loop boundary math.

Changes in v2:
- Squashed v1 patches 9-13 into a single patch (applied in review-ilpo-next).

Muhammad Bilal (2):
platform/x86: hp-bioscfg: fix 16-byte heap overflow for empty auth
token
platform/x86: hp-bioscfg: remove dead bounds check in
audit_log_entries_show

 drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c    | 4 ----
 drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c | 9 +++------
 2 files changed, 3 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/2 platform/x86: hp-bioscfg: fix 16-byte heap overflow for empty auth token

hp_calculate_security_buffer() special-cases an empty authentication string and returns a fixed 4 bytes (sizeof(u16) * 2). But hp_populate_security_buffer() does not special-case that same input:
for any authentication string that does not start with BEAM_PREFIX, including the empty string, it always builds "UTF_PREFIX + authentication" and converts the result to UTF-16, writing a 2-byte length header plus 2 bytes per character of "<utf-16/>" (9 characters), 20 bytes total, regardless of how long "authentication" itself is.

The caller, hp_set_attribute(), sizes its kmalloc() buffer using hp_calculate_security_buffer()'s return value, so for an empty authentication token it allocates 4 bytes for the security area but hp_populate_security_buffer() then writes 20 bytes into it, causing a 16-byte heap buffer overflow.

The authentication token used here is the current admin/setup password, which is an empty string by default until one is configured. Any write to a writable BIOS attribute while no admin password has been set reaches this path.

Fix by removing the special-case early return for an empty string in hp_calculate_security_buffer(). The generic calculation that follows already accounts for the UTF_PREFIX correctly, which naturally yields the same 20 bytes that hp_populate_security_buffer() writes for an empty string, avoiding duplicate logic for special cases.

---
Changes in v3:
- Remove the special-case return entirely instead of adjusting its formula, avoiding code duplication as suggested by Ilpo Järvinen.
- Credit Josh Snyder who previously noted this approach.

Changes in v2:
- None for this patch; resubmitted as part of the v2 series.

---
 drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c +0 -4
index 4d94e48c1a4c..136585141e6e 100644
@@ -47,10 +47,6 @@ size_t hp_calculate_security_buffer(const char *authentication)
 	if (!authentication)
 		return sizeof(u16) * 2;
 
-	authlen = strlen(authentication);
-	if (!authlen)
-		return sizeof(u16) * 2;
-
 	authlen = strlen(authentication);
 	size = sizeof(u16) + authlen * sizeof(u16);
 	if (!strstarts(authentication, BEAM_PREFIX))
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH v3 1/2] platform/x86: hp-bioscfg: fix 16-byte heap overflow for empty auth token

Quoted 51 lines · Muhammad Bilal

hp_calculate_security_buffer() special-cases an empty authentication string and returns a fixed 4 bytes (sizeof(u16) * 2). But hp_populate_security_buffer() does not special-case that same input:
for any authentication string that does not start with BEAM_PREFIX, including the empty string, it always builds "UTF_PREFIX + authentication" and converts the result to UTF-16, writing a 2-byte length header plus 2 bytes per character of "<utf-16/>" (9 characters), 20 bytes total, regardless of how long "authentication" itself is.

The caller, hp_set_attribute(), sizes its kmalloc() buffer using hp_calculate_security_buffer()'s return value, so for an empty authentication token it allocates 4 bytes for the security area but hp_populate_security_buffer() then writes 20 bytes into it, causing a 16-byte heap buffer overflow.

The authentication token used here is the current admin/setup password, which is an empty string by default until one is configured. Any write to a writable BIOS attribute while no admin password has been set reaches this path.

Fix by removing the special-case early return for an empty string in hp_calculate_security_buffer(). The generic calculation that follows already accounts for the UTF_PREFIX correctly, which naturally yields the same 20 bytes that hp_populate_security_buffer() writes for an empty string, avoiding duplicate logic for special cases.

---
Changes in v3:
- Remove the special-case return entirely instead of adjusting its formula, avoiding code duplication as suggested by Ilpo Järvinen.
- Credit Josh Snyder who previously noted this approach.

Changes in v2:
- None for this patch; resubmitted as part of the v2 series.

---
 drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c +0 -0
index 4d94e48c1a4c..136585141e6e 100644

drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c size_t hp_calculate_security_buffer(const char *authentication) · line 51

Quoted 9 lines
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c +0 -4
@@ -47,10 +47,6 @@ size_t hp_calculate_security_buffer(const char *authentication)
 	if (!authentication)
 		return sizeof(u16) * 2;
 
-	authlen = strlen(authentication);
-	if (!authlen)
-		return sizeof(u16) * 2;
-
 	authlen = strlen(authentication);
 	size = sizeof(u16) + authlen * sizeof(u16);

authlen is not uninitialized, so only the early return should be dropped.

I've dropped this patch from the review-ilpo-next branch.

Signature · 1 line
 i.
#3 lore raw

PATCH v4 1/1 platform/x86: hp-bioscfg: fix 16-byte heap overflow for empty auth token

hp_calculate_security_buffer() special-cases an empty authentication string and returns a fixed 4 bytes (sizeof(u16) * 2). But hp_populate_security_buffer() does not special-case that same input:
for any authentication string that does not start with BEAM_PREFIX, including the empty string, it always builds "UTF_PREFIX + authentication" and converts the result to UTF-16, writing a 2-byte length header plus 2 bytes per character of "<utf-16/>" (9 characters), 20 bytes total, regardless of how long "authentication" itself is.

The caller, hp_set_attribute(), sizes its kmalloc() buffer using hp_calculate_security_buffer()'s return value, so for an empty authentication token it allocates 4 bytes for the security area but hp_populate_security_buffer() then writes 20 bytes into it, causing a 16-byte heap buffer overflow.

The authentication token used here is the current admin/setup password, which is an empty string by default until one is configured. Any write to a writable BIOS attribute while no admin password has been set reaches this path.

Fix by removing the special-case early return for an empty string in hp_calculate_security_buffer(). The generic calculation that follows already accounts for the UTF_PREFIX correctly, which naturally yields the same 20 bytes that hp_populate_security_buffer() writes for an empty string, avoiding duplicate logic for special cases.

---
Changes in v4:
- Straight re-generation against current mainline: v3 was written against a tree state that had a duplicate "authlen = strlen(...)" assignment (one copy meant to be removed, one meant to survive), which current mainline does not have. That mismatch is why Ilpo needed "special trickery" to apply v3, and why the manually-applied result ended up with no authlen assignment at all (reported by kernel test robot). The v3 diff itself was fine, as Ilpo confirmed ("authlen is not uninitialized, so only the early return should be dropped"); this is that same one change, regenerated from scratch against the actual current tree so it applies cleanly without manual intervention.

Changes in v3:
- Remove the special-case return entirely instead of adjusting its formula, avoiding code duplication as suggested by Ilpo Järvinen.
- Credit Josh Snyder who previously noted this approach.

Changes in v2:
- None for this patch; resubmitted as part of the v2 series.

---
 drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c +0 -3
index 4d94e48..abf8ce2 100644
@@ -47,9 +47,6 @@ size_t hp_calculate_security_buffer(const char *authentication)
 		return sizeof(u16) * 2;
 
 	authlen = strlen(authentication);
-	if (!authlen)
-		return sizeof(u16) * 2;
-
 	size = sizeof(u16) + authlen * sizeof(u16);
 	if (!strstarts(authentication, BEAM_PREFIX))
 		size += strlen(UTF_PREFIX) * sizeof(u16);
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v4] platform/x86: hp-bioscfg: fix 16-byte heap overflow for empty auth token

ping.

Quoted 78 lines · Muhammad Bilal

hp_calculate_security_buffer() special-cases an empty authentication string and returns a fixed 4 bytes (sizeof(u16) * 2). But hp_populate_security_buffer() does not special-case that same input:
for any authentication string that does not start with BEAM_PREFIX, including the empty string, it always builds "UTF_PREFIX + authentication" and converts the result to UTF-16, writing a 2-byte length header plus 2 bytes per character of "<utf-16/>" (9 characters), 20 bytes total, regardless of how long "authentication" itself is.

The caller, hp_set_attribute(), sizes its kmalloc() buffer using hp_calculate_security_buffer()'s return value, so for an empty authentication token it allocates 4 bytes for the security area but hp_populate_security_buffer() then writes 20 bytes into it, causing a 16-byte heap buffer overflow.

The authentication token used here is the current admin/setup password, which is an empty string by default until one is configured. Any write to a writable BIOS attribute while no admin password has been set reaches this path.

Fix by removing the special-case early return for an empty string in hp_calculate_security_buffer(). The generic calculation that follows already accounts for the UTF_PREFIX correctly, which naturally yields the same 20 bytes that hp_populate_security_buffer() writes for an empty string, avoiding duplicate logic for special cases.

---
Changes in v4:
- Straight re-generation against current mainline: v3 was written against a tree state that had a duplicate "authlen = strlen(...)" assignment (one copy meant to be removed, one meant to survive), which current mainline does not have. That mismatch is why Ilpo needed "special trickery" to apply v3, and why the manually-applied result ended up with no authlen assignment at all (reported by kernel test robot). The v3 diff itself was fine, as Ilpo confirmed ("authlen is not uninitialized, so only the early return should be dropped"); this is that same one change, regenerated from scratch against the actual current tree so it applies cleanly without manual intervention.

Changes in v3:
- Remove the special-case return entirely instead of adjusting its formula, avoiding code duplication as suggested by Ilpo Järvinen.
- Credit Josh Snyder who previously noted this approach.

Changes in v2:
- None for this patch; resubmitted as part of the v2 series.

---
 drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c +0 -4
index 4d94e48..abf8ce2 100644
@@ -47,9 +47,6 @@ size_t hp_calculate_security_buffer(const char *authentication)
                return sizeof(u16) * 2;
 
        authlen = strlen(authentication);
-       if (!authlen)
-               return sizeof(u16) * 2;
-
        size = sizeof(u16) + authlen * sizeof(u16);
        if (!strstarts(authentication, BEAM_PREFIX))
                size += strlen(UTF_PREFIX) * sizeof(u16);
--

2.43.0

maintainer
#5 lore raw

Re: [PATCH v4] platform/x86: hp-bioscfg: fix 16-byte heap overflow for empty auth token

In reply to Muhammad Bilal
Quoted 10 lines · Muhammad Bilal

hp_calculate_security_buffer() special-cases an empty authentication string and returns a fixed 4 bytes (sizeof(u16) * 2). But hp_populate_security_buffer() does not special-case that same input:
for any authentication string that does not start with BEAM_PREFIX, including the empty string, it always builds "UTF_PREFIX + authentication" and converts the result to UTF-16, writing a 2-byte length header plus 2 bytes per character of "<utf-16/>" (9 characters), 20 bytes total, regardless of how long "authentication" itself is.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent cycle or is clearly a regression fix.

The list of commits applied:
[1/1] platform/x86: hp-bioscfg: fix 16-byte heap overflow for empty auth token

      commit: 67e222d412cc51d05380f2b7482a998cd4b4c638

--
i.

#6 lore raw

PATCH v3 2/2 platform/x86: hp-bioscfg: remove dead bounds check in audit_log_entries_show

In reply to Muhammad Bilal

audit_log_entries_show() checks "count * LOG_ENTRY_SIZE > PAGE_SIZE" prior to entering the loop. Because "count" is already bounded to fit within PAGE_SIZE, the inner loop check "(LOG_ENTRY_SIZE * i) > PAGE_SIZE" can never be reached and is dead code.

Remove the redundant inner bounds check and eliminate the unnecessary "else" block after "break" to clean up the loop control flow.

---
Changes in v3:
- Remove the dead inner loop check completely instead of adjusting the boundary arithmetic, as noted by Ilpo Järvinen.
- Remove the redundant else block after break.

Changes in v2:
- None for this patch; resubmitted as part of the v2 series.

---
 drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c +8 -10
index b57e42f29282..3b20757a3e74 100644
@@ -93,15 +93,12 @@ static ssize_t audit_log_entries_show(struct kobject *kobj,
 					   HPWMI_SURESTART,
 					   audit_log_buffer, 1, 128);
 
-		if (ret < 0 || (LOG_ENTRY_SIZE * i) > PAGE_SIZE) {
-			/*
-			 * Encountered a failure while reading
-			 * individual logs. Only a partial list of
-			 * audit log will be returned.
-			 */
+		/*
+		 * Encountered a failure while reading individual logs.
+		 * Only a partial list of audit log will be returned.
+		 */
+		if (ret < 0)
 			break;
-		} else {
-			memcpy(buf, audit_log_buffer, LOG_ENTRY_SIZE);
-			buf += LOG_ENTRY_SIZE;
-		}
+
+		memcpy(buf, audit_log_buffer, LOG_ENTRY_SIZE);
+		buf += LOG_ENTRY_SIZE;

}

return i * LOG_ENTRY_SIZE;

Signature · 1 line
2.43.0
maintainer
#7 lore raw

Re: [PATCH v3 2/2] platform/x86: hp-bioscfg: remove dead bounds check in audit_log_entries_show

Quoted 45 lines · Muhammad Bilal

audit_log_entries_show() checks "count * LOG_ENTRY_SIZE > PAGE_SIZE" prior to entering the loop. Because "count" is already bounded to fit within PAGE_SIZE, the inner loop check "(LOG_ENTRY_SIZE * i) > PAGE_SIZE" can never be reached and is dead code.

Remove the redundant inner bounds check and eliminate the unnecessary "else" block after "break" to clean up the loop control flow.

---
Changes in v3:
- Remove the dead inner loop check completely instead of adjusting the boundary arithmetic, as noted by Ilpo Järvinen.
- Remove the redundant else block after break.

Changes in v2:
- None for this patch; resubmitted as part of the v2 series.

---
 drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c +5 -6
index b57e42f29282..3b20757a3e74 100644
@@ -93,15 +93,12 @@ static ssize_t audit_log_entries_show(struct kobject *kobj,
 					   HPWMI_SURESTART,
 					   audit_log_buffer, 1, 128);
 
-		if (ret < 0 || (LOG_ENTRY_SIZE * i) > PAGE_SIZE) {
-			/*
-			 * Encountered a failure while reading
-			 * individual logs. Only a partial list of
-			 * audit log will be returned.
-			 */
+		/*
+		 * Encountered a failure while reading individual logs.
+		 * Only a partial list of audit log will be returned.
+		 */
+		if (ret < 0)
 			break;

drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c static ssize_t audit_log_entries_show(struct kobject *kobj,

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c +3 -4
-		} else {
-			memcpy(buf, audit_log_buffer, LOG_ENTRY_SIZE);
-			buf += LOG_ENTRY_SIZE;
-		}
+
+		memcpy(buf, audit_log_buffer, LOG_ENTRY_SIZE);
+		buf += LOG_ENTRY_SIZE;
 	}
 
 	return i * LOG_ENTRY_SIZE;

Patch 1 didn't apply without special trickery, this patch 2 doesn't even get that far:

checking file drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c
patch: **** malformed patch at line 65: }

:-(

Signature · 1 line
 i.
maintainer
#8 lore raw
In reply to Muhammad Bilal
Quoted 10 lines · Muhammad Bilal

This is v3 for the remaining two patches (patches 4 and 5) from the v2 series [2], addressing your review feedback:

- Patch 1/2 (was patch 4 in v2): Remove the special-case "if (!authlen)" return entirely in hp_calculate_security_buffer(). The generic calculation already naturally yields 20 bytes for empty strings, eliminating duplicate logic and fixing the 16-byte heap overflow (reported earlier by Josh Snyder [3]).

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent cycle or is clearly a regression fix.

The list of commits applied:
[1/2] platform/x86: hp-bioscfg: fix 16-byte heap overflow for empty auth token

      commit: 5714a846afa8d7b8363aa134d4acbd129f68d049

[2/2] platform/x86: hp-bioscfg: remove dead bounds check in audit_log_entries_show
(no commit info)

--
i.