Skip to contentSkip to conversation

efi: vars: commonize the 512-byte name buffer quirk

PATCH Superseded Jonggeun Park 3 participants 7 messages Aug 15 – Nov 28

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

PATCH 1/1 efi: vars: commonize the 512-byte name buffer quirk

Some old UEFI implementations reject GetNextVariableName() calls with a name buffer size larger than 512 bytes. Both efivar_init() and efi_pstore_read() open-code the same workaround of resetting the size to 512 on every iteration.

Introduce efivar_get_next_variable_safe() which keeps this quirk in a single place, resolving the TODO in efi-pstore.c.

No functional change intended.

---
 drivers/firmware/efi/efi-pstore.c | 16 +++++-----------
 drivers/firmware/efi/vars.c       | 21 +++++++++++++++++++++
 fs/efivarfs/vars.c                |  4 +---
 include/linux/efi.h               |  4 ++++
 4 files changed, 31 insertions(+), 14 deletions(-)
drivers/firmware/efi/efi-pstore.c +5 -11
index a5db3534f..a135d6e2f 100644
@@ -164,16 +164,6 @@ static ssize_t efi_pstore_read(struct pstore_record *record)
 	efi_status_t status;
 
 	for (;;) {
-		/*
-		 * A small set of old UEFI implementations reject sizes
-		 * above a certain threshold, the lowest seen in the wild
-		 * is 512.
-		 *
-		 * TODO: Commonize with the iteration implementation in
-		 *       fs/efivarfs to keep all the quirks in one place.
-		 */
-		varname_size = 512;
-
 		/*
 		 * If this is the first read() call in the pstore enumeration,
 		 * varname will be the empty string, and the GetNextVariable()
@@ -185,8 +175,12 @@ static ssize_t efi_pstore_read(struct pstore_record *record)
 		 * store varname in record->psi->data. Given that we only
 		 * enumerate variables with the efi-pstore GUID, there is no
 		 * need to record the guid return value.
+		 *
+		 * The 512-byte name buffer quirk is handled inside
+		 * efivar_get_next_variable_safe().
 		 */
-		status = efivar_get_next_variable(&varname_size, varname, &guid);
+		status = efivar_get_next_variable_safe(&varname_size, varname,
+						       &guid);
 		if (status == EFI_NOT_FOUND)
 			return 0;
 
drivers/firmware/efi/vars.c +21 -0
index 3700e9869..8e69f3632 100644
@@ -265,3 +265,24 @@ efi_status_t efivar_query_variable_info(u32 attr,
 			remaining_space, max_variable_size);
 }
 EXPORT_SYMBOL_NS_GPL(efivar_query_variable_info, "EFIVAR");
+
+/*
+ * efivar_get_next_variable_safe() - enumerate the next name/vendor pair
+ *
+ * Wrapper around efivar_get_next_variable() that keeps the 512-byte name
+ * buffer quirk in one place. Some old UEFI implementations reject name buffer
+ * sizes larger than 512 bytes (the lowest seen in the wild), so this always
+ * requests 512 bytes; callers must provide a buffer of at least that size.
+ *
+ * Must be called with efivars_lock held.
+ */
+efi_status_t efivar_get_next_variable_safe(unsigned long *name_size,
+					   efi_char16_t *name,
+					   efi_guid_t *vendor)
+{
+	BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
+	*name_size = 512;
+
+	return efivar_get_next_variable(name_size, name, vendor);
+}
+EXPORT_SYMBOL_NS_GPL(efivar_get_next_variable_safe, "EFIVAR");
fs/efivarfs/vars.c +1 -3
index 6833c3d24..ee55a26cb 100644
@@ -398,10 +398,8 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
 	 */
 
 	do {
-		variable_name_size = 512;
-		BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
 
-		status = efivar_get_next_variable(&variable_name_size,
+		status = efivar_get_next_variable_safe(&variable_name_size,
 						  variable_name,
 						  &vendor_guid);
 		switch (status) {
include/linux/efi.h +4 -0
index ccbc35479..f36505aa0 100644
@@ -1076,6 +1076,10 @@ efi_status_t efivar_get_variable(efi_char16_t *name, efi_guid_t *vendor,
 efi_status_t efivar_get_next_variable(unsigned long *name_size,
 				      efi_char16_t *name, efi_guid_t *vendor);
 
+efi_status_t efivar_get_next_variable_safe(unsigned long *name_size,
+					   efi_char16_t *name,
+					   efi_guid_t *vendor);
+
 efi_status_t efivar_set_variable_locked(efi_char16_t *name, efi_guid_t *vendor,
 					u32 attr, unsigned long data_size,
 					void *data, bool nonblocking);
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Hello Jonggeun,

Quoted 80 lines · Jonggeun Park

Some old UEFI implementations reject GetNextVariableName() calls with a name buffer size larger than 512 bytes. Both efivar_init() and efi_pstore_read() open-code the same workaround of resetting the size to 512 on every iteration.

Introduce efivar_get_next_variable_safe() which keeps this quirk in a single place, resolving the TODO in efi-pstore.c.

No functional change intended.

---
 drivers/firmware/efi/efi-pstore.c | 16 +++++-----------
 drivers/firmware/efi/vars.c       | 21 +++++++++++++++++++++
 fs/efivarfs/vars.c                |  4 +---
 include/linux/efi.h               |  4 ++++
 4 files changed, 31 insertions(+), 14 deletions(-)
drivers/firmware/efi/efi-pstore.c +0 -10
index a5db3534f..a135d6e2f 100644
@@ -164,16 +164,6 @@ static ssize_t efi_pstore_read(struct 
 pstore_record *record)
 	efi_status_t status;
 
 	for (;;) {
-		/*
-		 * A small set of old UEFI implementations reject sizes
-		 * above a certain threshold, the lowest seen in the wild
-		 * is 512.
-		 *
-		 * TODO: Commonize with the iteration implementation in
-		 *       fs/efivarfs to keep all the quirks in one place.
-		 */
-		varname_size = 512;
-
 		/*
 		 * If this is the first read() call in the pstore enumeration,
drivers/firmware/efi/efi-pstore.c +5 -1
 		 * varname will be the empty string, and the GetNextVariable()
@@ -185,8 +175,12 @@ static ssize_t efi_pstore_read(struct 
 pstore_record *record)
 		 * store varname in record->psi->data. Given that we only
 		 * enumerate variables with the efi-pstore GUID, there is no
 		 * need to record the guid return value.
+		 *
+		 * The 512-byte name buffer quirk is handled inside
+		 * efivar_get_next_variable_safe().
 		 */
-		status = efivar_get_next_variable(&varname_size, varname, &guid);
+		status = efivar_get_next_variable_safe(&varname_size, varname,
+						       &guid);
 		if (status == EFI_NOT_FOUND)
 			return 0;
drivers/firmware/efi/vars.c +3 -0
index 3700e9869..8e69f3632 100644
@@ -265,3 +265,24 @@ efi_status_t efivar_query_variable_info(u32 attr,
 			remaining_space, max_variable_size);
 }
 EXPORT_SYMBOL_NS_GPL(efivar_query_variable_info, "EFIVAR");
+
+/*
+ * efivar_get_next_variable_safe() - enumerate the next name/vendor 

pair
+ *
+ * Wrapper around efivar_get_next_variable() that keeps the 512-byte name
+ * buffer quirk in one place. Some old UEFI implementations reject name buffer
+ * sizes larger than 512 bytes (the lowest seen in the wild), so this always
+ * requests 512 bytes; callers must provide a buffer of at least that size.
+ *
+ * Must be called with efivars_lock held.
+ */

drivers/firmware/efi/vars.c efi_status_t efivar_query_variable_info(u32 attr, · line 288

Quoted 10 lines
drivers/firmware/efi/vars.c +10 -0
+efi_status_t efivar_get_next_variable_safe(unsigned long *name_size,
+					   efi_char16_t *name,
+					   efi_guid_t *vendor)
+{
+	BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
+	*name_size = 512;
+
+	return efivar_get_next_variable(name_size, name, vendor);
+}
+EXPORT_SYMBOL_NS_GPL(efivar_get_next_variable_safe, "EFIVAR");

Don't add a new function here - just move the logic into the existing efivar_get_next_variable(), which has only two callers.

#2 lore raw

PATCH v2 1/1 efi: vars: commonize the 512-byte name buffer quirk

In reply to Jonggeun Park

Some old UEFI implementations reject GetNextVariableName() calls with a name buffer size larger than 512 bytes. Both efivar_init() and efi_pstore_read() open-code the same workaround of resetting the size to 512 on every iteration.

Move this workaround into efivar_get_next_variable(), which keeps this quirk in one place, resolving the TODO in efi-pstore.c.

No functional change intended.

---
v2:
- Move the workaround into the existing efivar_get_next_variable().

---
 drivers/firmware/efi/efi-pstore.c | 10 ----------
 drivers/firmware/efi/vars.c       |  7 +++++++
 fs/efivarfs/vars.c                | 12 +-----------
 3 files changed, 8 insertions(+), 21 deletions(-)
drivers/firmware/efi/efi-pstore.c +0 -10
index a5db3534f..4f2594d08 100644
@@ -164,16 +164,6 @@ static ssize_t efi_pstore_read(struct pstore_record *record)
 	efi_status_t status;
 
 	for (;;) {
-		/*
-		 * A small set of old UEFI implementations reject sizes
-		 * above a certain threshold, the lowest seen in the wild
-		 * is 512.
-		 *
-		 * TODO: Commonize with the iteration implementation in
-		 *       fs/efivarfs to keep all the quirks in one place.
-		 */
-		varname_size = 512;
-
 		/*
 		 * If this is the first read() call in the pstore enumeration,
 		 * varname will be the empty string, and the GetNextVariable()
drivers/firmware/efi/vars.c +7 -0
index 3700e9869..0f95fc60d 100644
@@ -191,11 +191,18 @@ EXPORT_SYMBOL_NS_GPL(efivar_get_variable, "EFIVAR");
 /*
  * efivar_get_next_variable() - enumerate the next name/vendor pair
  *
+ * A small set of old UEFI implementations reject sizes above a certain
+ * threshold, the lowest seen in the wild is 512. Set the name buffer size
+ * to 512 on each call.
+ *
  * Must be called with efivars_lock held.
  */
 efi_status_t efivar_get_next_variable(unsigned long *name_size,
 				      efi_char16_t *name, efi_guid_t *vendor)
 {
+	BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
+	*name_size = 512;
+
 	return __efivars->ops->get_next_variable(name_size, name, vendor);
 }
 EXPORT_SYMBOL_NS_GPL(efivar_get_next_variable, "EFIVAR");
fs/efivarfs/vars.c +1 -11
index 6833c3d24..5a01833a6 100644
@@ -391,18 +391,8 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
 	if (err)
 		goto free;
 
-	/*
-	 * A small set of old UEFI implementations reject sizes
-	 * above a certain threshold, the lowest seen in the wild
-	 * is 512.
-	 */
-
 	do {
-		variable_name_size = 512;
-		BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
-
-		status = efivar_get_next_variable(&variable_name_size,
-						  variable_name,
+		status = efivar_get_next_variable(&variable_name_size, variable_name,
 						  &vendor_guid);
 		switch (status) {
 		case EFI_SUCCESS:
Signature · 1 line
2.43.0
maintainer
#3 lore raw

Thanks for respinning this.

Some additional thoughts below.

Quoted 60 lines · Jonggeun Park

Some old UEFI implementations reject GetNextVariableName() calls with a name buffer size larger than 512 bytes. Both efivar_init() and efi_pstore_read() open-code the same workaround of resetting the size to 512 on every iteration.

Move this workaround into efivar_get_next_variable(), which keeps this quirk in one place, resolving the TODO in efi-pstore.c.

No functional change intended.

---
v2:
- Move the workaround into the existing efivar_get_next_variable().

---
 drivers/firmware/efi/efi-pstore.c | 10 ----------
 drivers/firmware/efi/vars.c       |  7 +++++++
 fs/efivarfs/vars.c                | 12 +-----------
 3 files changed, 8 insertions(+), 21 deletions(-)
drivers/firmware/efi/efi-pstore.c +0 -10
index a5db3534f..4f2594d08 100644
@@ -164,16 +164,6 @@ static ssize_t efi_pstore_read(struct 
 pstore_record *record)
 	efi_status_t status;
 
 	for (;;) {
-		/*
-		 * A small set of old UEFI implementations reject sizes
-		 * above a certain threshold, the lowest seen in the wild
-		 * is 512.
-		 *
-		 * TODO: Commonize with the iteration implementation in
-		 *       fs/efivarfs to keep all the quirks in one place.
-		 */
-		varname_size = 512;
-
 		/*
 		 * If this is the first read() call in the pstore enumeration,
drivers/firmware/efi/efi-pstore.c +0 -0
 		 * varname will be the empty string, and the GetNextVariable()
drivers/firmware/efi/vars.c +2 -0
index 3700e9869..0f95fc60d 100644
@@ -191,11 +191,18 @@ EXPORT_SYMBOL_NS_GPL(efivar_get_variable, 
 "EFIVAR");
 /*
  * efivar_get_next_variable() - enumerate the next name/vendor pair
  *
+ * A small set of old UEFI implementations reject sizes above a certain
+ * threshold, the lowest seen in the wild is 512. Set the name buffer 

size
+ * to 512 on each call.
+ *
* Must be called with efivars_lock held.
*/
efi_status_t efivar_get_next_variable(unsigned long *name_size,

drivers/firmware/efi/vars.c EXPORT_SYMBOL_NS_GPL(efivar_get_variable, "EFIVAR"); · line 205

Quoted 5 lines
drivers/firmware/efi/vars.c +3 -0
 				      efi_char16_t *name, efi_guid_t *vendor)
 {
+	BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
+	*name_size = 512;
+

This should really be

  *name_size = min(*name_size, 512UL);

so that a smaller buffer size provided by the caller is respected.

That also removes the need for the BUILD_BUG_ON().

No need to send a v3, I can fix that up when applying.

Quoted 30 lines
drivers/firmware/efi/vars.c +0 -0
 	return __efivars->ops->get_next_variable(name_size, name, vendor);
 }
 EXPORT_SYMBOL_NS_GPL(efivar_get_next_variable, "EFIVAR");
fs/efivarfs/vars.c +1 -11
index 6833c3d24..5a01833a6 100644
@@ -391,18 +391,8 @@ int efivar_init(int (*func)(efi_char16_t *, 
 efi_guid_t, unsigned long, void *),
 	if (err)
 		goto free;
 
-	/*
-	 * A small set of old UEFI implementations reject sizes
-	 * above a certain threshold, the lowest seen in the wild
-	 * is 512.
-	 */
-
 	do {
-		variable_name_size = 512;
-		BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
-
-		status = efivar_get_next_variable(&variable_name_size,
-						  variable_name,
+		status = efivar_get_next_variable(&variable_name_size, variable_name,
 						  &vendor_guid);
 		switch (status) {

case EFI_SUCCESS:

Signature · 1 line
2.43.0
#4 lore raw
Quoted 73 lines · On Thu, 03 Sep 2026 22:03:18 +0200 "Ard Biesheuvel" <[email protected]> wrote:

Thanks for respinning this.

Some additional thoughts below.

Quoted 60 lines · Jonggeun Park

Some old UEFI implementations reject GetNextVariableName() calls with a name buffer size larger than 512 bytes. Both efivar_init() and efi_pstore_read() open-code the same workaround of resetting the size to 512 on every iteration.

Move this workaround into efivar_get_next_variable(), which keeps this quirk in one place, resolving the TODO in efi-pstore.c.

No functional change intended.

---
v2:
- Move the workaround into the existing efivar_get_next_variable().

---
 drivers/firmware/efi/efi-pstore.c | 10 ----------
 drivers/firmware/efi/vars.c       |  7 +++++++
 fs/efivarfs/vars.c                | 12 +-----------
 3 files changed, 8 insertions(+), 21 deletions(-)
drivers/firmware/efi/efi-pstore.c +0 -10
index a5db3534f..4f2594d08 100644
@@ -164,16 +164,6 @@ static ssize_t efi_pstore_read(struct 
 pstore_record *record)
 	efi_status_t status;
 
 	for (;;) {
-		/*
-		 * A small set of old UEFI implementations reject sizes
-		 * above a certain threshold, the lowest seen in the wild
-		 * is 512.
-		 *
-		 * TODO: Commonize with the iteration implementation in
-		 *       fs/efivarfs to keep all the quirks in one place.
-		 */
-		varname_size = 512;
-
 		/*
 		 * If this is the first read() call in the pstore enumeration,
drivers/firmware/efi/efi-pstore.c +0 -0
 		 * varname will be the empty string, and the GetNextVariable()
drivers/firmware/efi/vars.c +2 -0
index 3700e9869..0f95fc60d 100644
@@ -191,11 +191,18 @@ EXPORT_SYMBOL_NS_GPL(efivar_get_variable, 
 "EFIVAR");
 /*
  * efivar_get_next_variable() - enumerate the next name/vendor pair
  *
+ * A small set of old UEFI implementations reject sizes above a certain
+ * threshold, the lowest seen in the wild is 512. Set the name buffer 

size
+ * to 512 on each call.
+ *
* Must be called with efivars_lock held.
*/
efi_status_t efivar_get_next_variable(unsigned long *name_size,

drivers/firmware/efi/vars.c EXPORT_SYMBOL_NS_GPL(efivar_get_variable, "EFIVAR"); · line 205

Quoted 5 lines
drivers/firmware/efi/vars.c +3 -0
 				      efi_char16_t *name, efi_guid_t *vendor)
 {
+	BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
+	*name_size = 512;
+  

This should really be

Quoted 1 line
  *name_size = min(*name_size, 512UL);

You don't need the UL suffix.

Quoted 38 lines

so that a smaller buffer size provided by the caller is respected.

That also removes the need for the BUILD_BUG_ON().

No need to send a v3, I can fix that up when applying.

Quoted 30 lines
drivers/firmware/efi/vars.c +0 -0
 	return __efivars->ops->get_next_variable(name_size, name, vendor);
 }
 EXPORT_SYMBOL_NS_GPL(efivar_get_next_variable, "EFIVAR");
fs/efivarfs/vars.c +1 -11
index 6833c3d24..5a01833a6 100644
@@ -391,18 +391,8 @@ int efivar_init(int (*func)(efi_char16_t *, 
 efi_guid_t, unsigned long, void *),
 	if (err)
 		goto free;
 
-	/*
-	 * A small set of old UEFI implementations reject sizes
-	 * above a certain threshold, the lowest seen in the wild
-	 * is 512.
-	 */
-
 	do {
-		variable_name_size = 512;
-		BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
-
-		status = efivar_get_next_variable(&variable_name_size,
-						  variable_name,
+		status = efivar_get_next_variable(&variable_name_size, variable_name,
 						  &vendor_guid);
 		switch (status) {

case EFI_SUCCESS:

Signature · 1 line
2.43.0  
#5 lore raw

Hi Ard,

I'd like to kindly follow up on this patch.

Could you please let me know if anything else is needed from my side?

Thanks for your time.

Best regards,
Jonggeun Park

2026년 9월 4일 (금) 오전 6:28, David Laight <[email protected]>님이 작성:

Quoted 120 lines
Quoted 73 lines · On Thu, 03 Sep 2026 22:03:18 +0200 "Ard Biesheuvel" <[email protected]> wrote:

Thanks for respinning this.

Some additional thoughts below.

Quoted 62 lines · Jonggeun Park

Some old UEFI implementations reject GetNextVariableName() calls with a name buffer size larger than 512 bytes. Both efivar_init() and efi_pstore_read() open-code the same workaround of resetting the size to 512 on every iteration.

Move this workaround into efivar_get_next_variable(), which keeps this quirk in one place, resolving the TODO in efi-pstore.c.

No functional change intended.

---
v2:
- Move the workaround into the existing efivar_get_next_variable().

---
 drivers/firmware/efi/efi-pstore.c | 10 ----------
 drivers/firmware/efi/vars.c       |  7 +++++++
 fs/efivarfs/vars.c                | 12 +-----------
 3 files changed, 8 insertions(+), 21 deletions(-)
drivers/firmware/efi/efi-pstore.c +0 -10
index a5db3534f..4f2594d08 100644
@@ -164,16 +164,6 @@ static ssize_t efi_pstore_read(struct
 pstore_record *record)
    efi_status_t status;
 
    for (;;) {
-           /*
-            * A small set of old UEFI implementations reject sizes
-            * above a certain threshold, the lowest seen in the wild
-            * is 512.
-            *
-            * TODO: Commonize with the iteration implementation in
-            *       fs/efivarfs to keep all the quirks in one place.
-            */
-           varname_size = 512;
-
            /*
             * If this is the first read() call in the pstore enumeration,

* varname will be the empty string, and the GetNextVariable()

drivers/firmware/efi/vars.c +2 -0
index 3700e9869..0f95fc60d 100644
@@ -191,11 +191,18 @@ EXPORT_SYMBOL_NS_GPL(efivar_get_variable,
 "EFIVAR");
 /*
  * efivar_get_next_variable() - enumerate the next name/vendor pair
  *
+ * A small set of old UEFI implementations reject sizes above a certain
+ * threshold, the lowest seen in the wild is 512. Set the name buffer

size
+ * to 512 on each call.
+ *
* Must be called with efivars_lock held.
*/
efi_status_t efivar_get_next_variable(unsigned long *name_size,

                                  efi_char16_t *name, efi_guid_t *vendor)

{

drivers/firmware/efi/vars.c EXPORT_SYMBOL_NS_GPL(efivar_get_variable, "EFIVAR"); · line 205

Quoted 3 lines
drivers/firmware/efi/vars.c +3 -0
+   BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
+   *name_size = 512;
+

This should really be

Quoted 1 line
  *name_size = min(*name_size, 512UL);

You don't need the UL suffix.

Quoted 38 lines

so that a smaller buffer size provided by the caller is respected.

That also removes the need for the BUILD_BUG_ON().

No need to send a v3, I can fix that up when applying.

Quoted 30 lines
    return __efivars->ops->get_next_variable(name_size, name, vendor);

}
EXPORT_SYMBOL_NS_GPL(efivar_get_next_variable, "EFIVAR");

fs/efivarfs/vars.c +1 -11
index 6833c3d24..5a01833a6 100644
@@ -391,18 +391,8 @@ int efivar_init(int (*func)(efi_char16_t *,
 efi_guid_t, unsigned long, void *),
    if (err)
            goto free;
 
-   /*
-    * A small set of old UEFI implementations reject sizes
-    * above a certain threshold, the lowest seen in the wild
-    * is 512.
-    */
-
    do {
-           variable_name_size = 512;
-           BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
-
-           status = efivar_get_next_variable(&variable_name_size,
-                                             variable_name,
+           status = efivar_get_next_variable(&variable_name_size, variable_name,
                                              &vendor_guid);
            switch (status) {

case EFI_SUCCESS:
--
2.43.0

maintainer
#6 lore raw
Quoted 6 lines · Jonggeun Park

Hi Ard,

I'd like to kindly follow up on this patch.

Could you please let me know if anything else is needed from my side?

I don't think the patch is good. And my advice actually makes it worse.

*name_size = 512;

is not correct because efivar_get_next_variable() does not know the size of the caller's buffer, and it might be smaller, which is why I proposed

*name_size = min(*name_size, 512);

but this is even worse, because the value may be the size of the variable name returned by the previous call, not the size of the caller's buffer. And the patch actually removes the only assignment in efi-pstore, and so efivar_get_next_variable() has no way of knowing the size of the actual buffer.

IOW, the callers must keep setting the buffer size before each call. That way, the min() variant is correct, and we can move the BUILD_BUG() into efivar_get_next_variable() too. But it does not remove a lot of duplication.

Quoted 121 lines

2026년 9월 4일 (금) 오전 6:28, David Laight <[email protected]>님이 작성:

Quoted 120 lines
Quoted 73 lines · On Thu, 03 Sep 2026 22:03:18 +0200 "Ard Biesheuvel" <[email protected]> wrote:

Thanks for respinning this.

Some additional thoughts below.

Quoted 62 lines · Jonggeun Park

Some old UEFI implementations reject GetNextVariableName() calls with a name buffer size larger than 512 bytes. Both efivar_init() and efi_pstore_read() open-code the same workaround of resetting the size to 512 on every iteration.

Move this workaround into efivar_get_next_variable(), which keeps this quirk in one place, resolving the TODO in efi-pstore.c.

No functional change intended.

---
v2:
- Move the workaround into the existing efivar_get_next_variable().

---
 drivers/firmware/efi/efi-pstore.c | 10 ----------
 drivers/firmware/efi/vars.c       |  7 +++++++
 fs/efivarfs/vars.c                | 12 +-----------
 3 files changed, 8 insertions(+), 21 deletions(-)
drivers/firmware/efi/efi-pstore.c +0 -10
index a5db3534f..4f2594d08 100644
@@ -164,16 +164,6 @@ static ssize_t efi_pstore_read(struct
 pstore_record *record)
    efi_status_t status;
 
    for (;;) {
-           /*
-            * A small set of old UEFI implementations reject sizes
-            * above a certain threshold, the lowest seen in the wild
-            * is 512.
-            *
-            * TODO: Commonize with the iteration implementation in
-            *       fs/efivarfs to keep all the quirks in one place.
-            */
-           varname_size = 512;
-
            /*
             * If this is the first read() call in the pstore enumeration,

* varname will be the empty string, and the GetNextVariable()

drivers/firmware/efi/vars.c +2 -0
index 3700e9869..0f95fc60d 100644
@@ -191,11 +191,18 @@ EXPORT_SYMBOL_NS_GPL(efivar_get_variable,
 "EFIVAR");
 /*
  * efivar_get_next_variable() - enumerate the next name/vendor pair
  *
+ * A small set of old UEFI implementations reject sizes above a certain
+ * threshold, the lowest seen in the wild is 512. Set the name buffer

size
+ * to 512 on each call.
+ *
* Must be called with efivars_lock held.
*/
efi_status_t efivar_get_next_variable(unsigned long *name_size,

                                  efi_char16_t *name, efi_guid_t *vendor)

{

drivers/firmware/efi/vars.c EXPORT_SYMBOL_NS_GPL(efivar_get_variable, "EFIVAR"); · line 205

Quoted 3 lines
drivers/firmware/efi/vars.c +3 -0
+   BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
+   *name_size = 512;
+

This should really be

Quoted 1 line
  *name_size = min(*name_size, 512UL);

You don't need the UL suffix.

Quoted 38 lines

so that a smaller buffer size provided by the caller is respected.

That also removes the need for the BUILD_BUG_ON().

No need to send a v3, I can fix that up when applying.

Quoted 30 lines
    return __efivars->ops->get_next_variable(name_size, name, vendor);

}
EXPORT_SYMBOL_NS_GPL(efivar_get_next_variable, "EFIVAR");

fs/efivarfs/vars.c +1 -11
index 6833c3d24..5a01833a6 100644
@@ -391,18 +391,8 @@ int efivar_init(int (*func)(efi_char16_t *,
 efi_guid_t, unsigned long, void *),
    if (err)
            goto free;
 
-   /*
-    * A small set of old UEFI implementations reject sizes
-    * above a certain threshold, the lowest seen in the wild
-    * is 512.
-    */
-
    do {
-           variable_name_size = 512;
-           BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
-
-           status = efivar_get_next_variable(&variable_name_size,
-                                             variable_name,
+           status = efivar_get_next_variable(&variable_name_size, variable_name,
                                              &vendor_guid);
            switch (status) {

case EFI_SUCCESS:
--
2.43.0