Skip to contentSkip to conversation

efivarfs: fix off-by-one in efivar_validate() variable name matching

PATCH Applied Zhang Chujun 2 participants 2 messages Nov 20 – Nov 24

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

PATCH 1/1 efivarfs: fix off-by-one in efivar_validate() variable name matching

From: zhangchujun <[email protected]>

efivar_validate() passes utf8_size + 1 to variable_matches(), including the terminating NUL in the name length. However, variable_matches() expects the number of non-NUL characters.

As a result, exact-name entries in variable_validate[] fail to match, causing some variables to use the wrong validator or bypass their intended validation.

Fixes 630ba0cc7a6d ("efi: Fix out-of-bounds read in variable_matches()")
fs/efivarfs/vars.c +1 -1
index 6833c3d24b54..9f18bf48615c 100644
@@ -274,7 +274,7 @@ efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
 		if (efi_guidcmp(vendor, variable_validate[i].vendor))
 			continue;
 
-		if (variable_matches(utf8_name, utf8_size+1, name, &match)) {
+		if (variable_matches(utf8_name, utf8_size, name, &match)) {
 			if (variable_validate[i].validate == NULL)
 				break;
 			kfree(utf8_name);
Signature · 1 line
2.50.1.windows.1
maintainer Applied
#1 lore raw

(cc Peter)

Quoted 27 lines · Zhang Chujun

From: zhangchujun <[email protected]>

efivar_validate() passes utf8_size + 1 to variable_matches(), including the terminating NUL in the name length. However, variable_matches() expects the number of non-NUL characters.

As a result, exact-name entries in variable_validate[] fail to match, causing some variables to use the wrong validator or bypass their intended validation.

Fixes 630ba0cc7a6d ("efi: Fix out-of-bounds read in variable_matches()")
fs/efivarfs/vars.c +1 -1
index 6833c3d24b54..9f18bf48615c 100644
@@ -274,7 +274,7 @@ efivar_validate(efi_guid_t vendor, efi_char16_t 
 *var_name, u8 *data,
 		if (efi_guidcmp(vendor, variable_validate[i].vendor))
 			continue;
 
-		if (variable_matches(utf8_name, utf8_size+1, name, &match)) {
+		if (variable_matches(utf8_name, utf8_size, name, &match)) {
 			if (variable_validate[i].validate == NULL)
 				break;
Quoted 1 line

kfree(utf8_name);

Queued as a fix, thanks.