Skip to contentSkip to conversation

efi_loader: loosen buffer parameter check in efi_file_read_int

PATCH Superseded Peng Fan (OSS) 3 participants 4 messages Apr 28, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi_loader: loosen buffer parameter check in efi_file_read_int

From: Peng Fan <[email protected]>

This is same issue as https://bugzilla.redhat.com/show_bug.cgi?id=1733817,
but that fix was wrongly partial reverted.

To Fedora shim loader, when buffer is NULL, a use-case is to call efi_file_read with *buffer_size=0 and buffer=NULL to obtain the needed size before doing the actual read.

Otherwise, we always met "Could not read \EFI\: Invalid Parameter"

Fixes db12f518edb0("efi_loader: implement non-blocking file services")
Cc Heinrich Schuchardt <[email protected]>
Cc Stefan S?rensen <[email protected]>
---
 lib/efi_loader/efi_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_file.c +1 -1
index 204105e25a..6b3f5962be 100644
@@ -554,7 +554,7 @@ static efi_status_t efi_file_read_int(struct efi_file_handle *this,
 	efi_status_t ret = EFI_SUCCESS;
 	u64 bs;
 
-	if (!this || !buffer_size || !buffer)
+	if (!this || !buffer_size)
 		return EFI_INVALID_PARAMETER;
 
 	bs = *buffer_size;
Signature · 1 line
2.30.0
#1 lore raw

PATCH 1/1 efi_loader: loosen buffer parameter check in efi_file_read_int

Quoted 10 lines · Peng Fan (OSS)

From: Peng Fan <[email protected]>

This is same issue as https://bugzilla.redhat.com/show_bug.cgi?id=1733817,
but that fix was wrongly partial reverted.

To Fedora shim loader, when buffer is NULL, a use-case is to call efi_file_read with *buffer_size=0 and buffer=NULL to obtain the needed size before doing the actual read.

Quoted 6 lines

Otherwise, we always met "Could not read \EFI\: Invalid Parameter"

Fixes db12f518edb0("efi_loader: implement non-blocking file services")
Cc Heinrich Schuchardt <[email protected]>
Cc Stefan S?rensen <[email protected]>

Tested on a patched 2021.04 with Fedora 34. Thanks!

Quoted 20 lines
---
 lib/efi_loader/efi_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_file.c +1 -2
index 204105e25a..6b3f5962be 100644
@@ -554,7 +554,7 @@ static efi_status_t efi_file_read_int(struct efi_file_handle *this,
        efi_status_t ret = EFI_SUCCESS;
        u64 bs;
 
-       if (!this || !buffer_size || !buffer)
+       if (!this || !buffer_size)
                return EFI_INVALID_PARAMETER;
 
        bs = *buffer_size;
--

2.30.0

#2 lore raw

PATCH 1/1 efi_loader: loosen buffer parameter check in efi_file_read_int

In reply to Peng Fan (OSS)
Quoted 10 lines · Peng Fan (OSS)

From: Peng Fan <[email protected]>

This is same issue as https://bugzilla.redhat.com/show_bug.cgi?id=1733817,
but that fix was wrongly partial reverted.

To Fedora shim loader, when buffer is NULL, a use-case is to call efi_file_read with *buffer_size=0 and buffer=NULL to obtain the needed size before doing the actual read.

Otherwise, we always met "Could not read \EFI\: Invalid Parameter"

The EFI specification does not require this behavior. EDK II does not implement it either. See for instance SemihostFileRead(), FvSimpleFileSystemRead().

To determine the file size you have to use GetInfo(). Please, fix the client code.

Best regards

Heinrich

Quoted 23 lines
Fixes db12f518edb0("efi_loader: implement non-blocking file services")
Cc Heinrich Schuchardt <[email protected]>
Cc Stefan S?rensen <[email protected]>
---
 lib/efi_loader/efi_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_file.c +1 -1
index 204105e25a..6b3f5962be 100644
@@ -554,7 +554,7 @@ static efi_status_t efi_file_read_int(struct efi_file_handle *this,
 	efi_status_t ret = EFI_SUCCESS;
 	u64 bs;
 
-	if (!this || !buffer_size || !buffer)
+	if (!this || !buffer_size)
 		return EFI_INVALID_PARAMETER;
 
 	bs = *buffer_size;
#3 lore raw

PATCH 1/1 efi_loader: loosen buffer parameter check in efi_file_read_int

Quoted 8 lines · Heinrich Schuchardt
Quoted 7 lines · Peng Fan (OSS)

From: Peng Fan <[email protected]>

This is same issue as https://bugzilla.redhat.com/show_bug.cgi?id=1733817,
but that fix was wrongly partial reverted.

To Fedora shim loader, when buffer is NULL, a use-case is to call efi_file_read with *buffer_size=0 and buffer=NULL to obtain the needed

An EFI binary cannot directly call efi_file_read(). It calls EFI_FILE_PROTOCOL.Read().

Quoted 3 lines
Quoted 3 lines

size before doing the actual read.

Otherwise, we always met "Could not read \EFI\: Invalid Parameter"

Please, describe the problem in UEFI terms.

Quoted 11 lines

The EFI specification does not require this behavior. EDK II does not implement it either. See for instance SemihostFileRead(), FvSimpleFileSystemRead().

To determine the file size you have to use GetInfo(). Please, fix the client code.

Best regards

Heinrich

Please, make it clear in the commit message, please, that this patch is about reading a *directory entry* and not about reading a file.

Best regards

Heinrich

Quoted 25 lines
Quoted 24 lines
Fixes db12f518edb0("efi_loader: implement non-blocking file services")
Cc Heinrich Schuchardt <[email protected]>
Cc Stefan S?rensen <[email protected]>
---
 lib/efi_loader/efi_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_file.c +1 -1
index 204105e25a..6b3f5962be 100644
@@ -554,7 +554,7 @@ static efi_status_t efi_file_read_int(struct efi_file_handle *this,
 	efi_status_t ret = EFI_SUCCESS;
 	u64 bs;
 
-	if (!this || !buffer_size || !buffer)
+	if (!this || !buffer_size)
 		return EFI_INVALID_PARAMETER;
 
 	bs = *buffer_size;