efi_loader: check update capsule parameters
PATCH 1/1 efi_loader: check update capsule parameters
UpdateCapsule() must return EFI_INVALID_PARAMETER in a number of cases, listed by the UEFI specification and tested by the SCT. Add a common function to do that.
This fixes SCT UpdateCapsule_Conf failures.
--- include/efi_loader.h | 24 ++++++++++++++++++++++++ lib/efi_loader/efi_capsule.c | 8 ++++---- lib/efi_loader/efi_runtime.c | 8 ++++++++ 3 files changed, 36 insertions(+), 4 deletions(-)
include/efi_loader.h +24 -0
@@ -910,6 +910,30 @@ extern const struct efi_firmware_management_protocol efi_fmp_fit;extern const struct efi_firmware_management_protocol efi_fmp_raw;/* Capsule update */ +static inline efi_status_t +efi_valid_update_capsule_params (struct efi_capsule_header + **capsule_header_array, +efi_uintn_t capsule_count, +u64 scatter_gather_list) +{ +u32 flags; + +if (!capsule_count) +return EFI_INVALID_PARAMETER ; + + flags = capsule_header_array[0 ]->flags; + +if (((flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET ) && + !scatter_gather_list) || + ((flags &CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE ) && + !(flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET )) || + ((flags &CAPSULE_FLAGS_INITIATE_RESET ) && + !(flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET ))) +return EFI_INVALID_PARAMETER ; + +return EFI_SUCCESS ; +} + efi_status_t EFIAPI efi_update_capsule( struct efi_capsule_header **capsule_header_array, efi_uintn_t capsule_count,
lib/efi_loader/efi_capsule.c +4 -4
@@ -442,12 +442,12 @@ efi_status_t EFIAPI efi_update_capsule(EFI_ENTRY ("%p, %zu, %llu\n" , capsule_header_array, capsule_count, scatter_gather_list); -if (!capsule_count) { - ret =EFI_INVALID_PARAMETER ; + ret =efi_valid_update_capsule_params (capsule_header_array, + capsule_count, + scatter_gather_list); +if (ret !=EFI_SUCCESS ) goto out; - } - ret =EFI_SUCCESS ;for (i =0 , capsule = *capsule_header_array; i < capsule_count; i++, capsule = *(++capsule_header_array)) {/* sanity check */
lib/efi_loader/efi_runtime.c +8 -0
@@ -467,6 +467,14 @@ efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported( efi_uintn_t capsule_count, u64 scatter_gather_list) { +efi_status_t ret; + + ret =efi_valid_update_capsule_params (capsule_header_array, + capsule_count, + scatter_gather_list); +if (ret !=EFI_SUCCESS ) +return ret; +return EFI_UNSUPPORTED ; }
Signature · 1 line
2.30.2
Quoted 24 lines · Vincent Stehlé
UpdateCapsule()must returnEFI_INVALID_PARAMETERin a number of cases, listed by the UEFI specification and tested by the SCT. Add a common function to do that.This fixes SCT
UpdateCapsule_Conffailures.Reviewed-by Grant Likely <[email protected]>Signed-off-by Vincent Stehlé <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Alexander Graf <[email protected]>--- include/efi_loader.h | 24 ++++++++++++++++++++++++ lib/efi_loader/efi_capsule.c | 8 ++++---- lib/efi_loader/efi_runtime.c | 8 ++++++++ 3 files changed, 36 insertions(+), 4 deletions(-)include/efi_loader.h +0
-0@@ -910,6 +910,30 @@ extern const struct efi_firmware_management_protocol efi_fmp_fit;extern const struct efi_firmware_management_protocol efi_fmp_raw;/* Capsule update */
include/efi_loader.h extern const struct efi_firmware_management_protocol efi_fmp_fit; · line 922
Quoted 10 lines
include/efi_loader.h +10
-0+static inline efi_status_t +efi_valid_update_capsule_params (struct efi_capsule_header + **capsule_header_array, +efi_uintn_t capsule_count, +u64 scatter_gather_list) +{ +u32 flags; + +if (!capsule_count) +return EFI_INVALID_PARAMETER ;
If capsule count > 1, don't you have to check all capsules headers?
include/efi_loader.h extern const struct efi_firmware_management_protocol efi_fmp_fit; · line 932
Quoted 10 lines
include/efi_loader.h +10
-0+ + flags = capsule_header_array[0 ]->flags; + +if (((flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET ) && + !scatter_gather_list) || + ((flags &CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE ) && + !(flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET )) || + ((flags &CAPSULE_FLAGS_INITIATE_RESET ) && + !(flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET ))) +return EFI_INVALID_PARAMETER ;
What happens if capsule(0) has CAPSULE_FLAGS_INITIATE_RESET and capsule(4) has !CAPSULE_FLAGS_PERSIST_ACROSS_RESET?
Best regards
Heinrich
Quoted 48 lines
include/efi_loader.h +4
-0+ +return EFI_SUCCESS ; +} + efi_status_t EFIAPI efi_update_capsule( struct efi_capsule_header **capsule_header_array, efi_uintn_t capsule_count,lib/efi_loader/efi_capsule.c +4
-4@@ -442,12 +442,12 @@ efi_status_t EFIAPI efi_update_capsule(EFI_ENTRY ("%p, %zu, %llu\n" , capsule_header_array, capsule_count, scatter_gather_list); -if (!capsule_count) { - ret =EFI_INVALID_PARAMETER ; + ret =efi_valid_update_capsule_params (capsule_header_array, + capsule_count, + scatter_gather_list); +if (ret !=EFI_SUCCESS ) goto out; - } - ret =EFI_SUCCESS ;for (i =0 , capsule = *capsule_header_array; i < capsule_count; i++, capsule = *(++capsule_header_array)) {/* sanity check */ lib/efi_loader/efi_runtime.c +8
-0@@ -467,6 +467,14 @@ efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported( efi_uintn_t capsule_count, u64 scatter_gather_list) { +efi_status_t ret; + + ret =efi_valid_update_capsule_params (capsule_header_array, + capsule_count, + scatter_gather_list); +if (ret !=EFI_SUCCESS ) +return ret; +return EFI_UNSUPPORTED ; }
Hi Vincent,
Thank you for the update.
Quoted 6 lines · Heinrich Schuchardt
Cc Takahiro, Sughosh, IliasQuoted 3 lines · Vincent Stehlé
UpdateCapsule()must returnEFI_INVALID_PARAMETERin a number of cases, listed by the UEFI specification and tested by the SCT. Add a common function to do that.
First of all, I would like to make clear one thing:
My initial implementation of capsule support does *not* intend to support "UpdateCapsule" as runtime API. Instead, the sole objective is to provide "delivery of capsules via file" (or capsule on disk) method.
This is because the initially-expected use case was that we would adopt capsules as an alternative for updating UEFI variables without using SetVariable runtime API. (This idea is no longer upheld, though.)
This is why the API does not handle nor check parameters in the current code. I even regret to have added EFI_RUNTIME_UPDATE_CAPSULE option, which makes people confused.
Nevertheless, I'm more than happy if other folks implement full semantics of UpdateCapsule.
Quoted 84 lines
Quoted 20 lines
This fixes SCT
UpdateCapsule_Conffailures.Reviewed-by Grant Likely <[email protected]>Signed-off-by Vincent Stehlé <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Alexander Graf <[email protected]>--- include/efi_loader.h | 24 ++++++++++++++++++++++++ lib/efi_loader/efi_capsule.c | 8 ++++---- lib/efi_loader/efi_runtime.c | 8 ++++++++ 3 files changed, 36 insertions(+), 4 deletions(-)include/efi_loader.h +0
-0@@ -910,6 +910,30 @@ extern const struct efi_firmware_management_protocol efi_fmp_fit;extern const struct efi_firmware_management_protocol efi_fmp_raw;/* Capsule update */ include/efi_loader.h extern const struct efi_firmware_management_protocol efi_fmp_fit; · line 922
Quoted 10 lines
include/efi_loader.h +10
-0+static inline efi_status_t +efi_valid_update_capsule_params (struct efi_capsule_header + **capsule_header_array, +efi_uintn_t capsule_count, +u64 scatter_gather_list) +{ +u32 flags; + +if (!capsule_count) +return EFI_INVALID_PARAMETER ;If capsule count > 1, don't you have to check all capsules headers?
include/efi_loader.h extern const struct efi_firmware_management_protocol efi_fmp_fit; · line 932
Quoted 10 lines
include/efi_loader.h +10
-0+ + flags = capsule_header_array[0 ]->flags; + +if (((flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET ) && + !scatter_gather_list) || + ((flags &CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE ) && + !(flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET )) || + ((flags &CAPSULE_FLAGS_INITIATE_RESET ) && + !(flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET ))) +return EFI_INVALID_PARAMETER ;What happens if capsule(0) has
CAPSULE_FLAGS_INITIATE_RESETand capsule(4) has !CAPSULE_FLAGS_PERSIST_ACROSS_RESET?Best regards
Heinrich
Quoted 33 lines
include/efi_loader.h +4
-0+ +return EFI_SUCCESS ; +} + efi_status_t EFIAPI efi_update_capsule( struct efi_capsule_header **capsule_header_array, efi_uintn_t capsule_count,lib/efi_loader/efi_capsule.c +4
-4@@ -442,12 +442,12 @@ efi_status_t EFIAPI efi_update_capsule(EFI_ENTRY ("%p, %zu, %llu\n" , capsule_header_array, capsule_count, scatter_gather_list); -if (!capsule_count) { - ret =EFI_INVALID_PARAMETER ; + ret =efi_valid_update_capsule_params (capsule_header_array, + capsule_count, + scatter_gather_list); +if (ret !=EFI_SUCCESS ) goto out; - } - ret =EFI_SUCCESS ;for (i =0 , capsule = *capsule_header_array; i < capsule_count; i++, capsule = *(++capsule_header_array)) {/* sanity check */ lib/efi_loader/efi_runtime.c +0
-0@@ -467,6 +467,14 @@ efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported(
Quoted 8 lines
lib/efi_loader/efi_runtime.c efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported( · line 474
Quoted 8 lines
lib/efi_loader/efi_runtime.c +5
-0efi_uintn_t capsule_count, u64 scatter_gather_list) { +efi_status_t ret; + + ret =efi_valid_update_capsule_params (capsule_header_array, + capsule_count, + scatter_gather_list);
This is "efi_update_capsule_unsupported" function. We don't have to check parameters.
-Takahiro Akashi
Quoted 8 lines
Quoted 7 lines
lib/efi_loader/efi_runtime.c +3
-0+if (ret !=EFI_SUCCESS ) +return ret; +return EFI_UNSUPPORTED ; }
Quoted 126 lines · AKASHI Takahiro
Hi Vincent,
Thank you for the update.
Quoted 6 lines · Heinrich Schuchardt
Cc Takahiro, Sughosh, IliasQuoted 3 lines · Vincent Stehlé
UpdateCapsule()must returnEFI_INVALID_PARAMETERin a number of cases, listed by the UEFI specification and tested by the SCT. Add a common function to do that.First of all, I would like to make clear one thing:
My initial implementation of capsule support does *not* intend to support "UpdateCapsule" as runtime API. Instead, the sole objective is to provide "delivery of capsules via file" (or capsule on disk) method.This is because the initially-expected use case was that we would adopt capsules as an alternative for updating UEFI variables without using SetVariable runtime API. (This idea is no longer upheld, though.)
This is why the API does not handle nor check parameters in the current code. I even regret to have added
EFI_RUNTIME_UPDATE_CAPSULEoption, which makes people confused.Nevertheless, I'm more than happy if other folks implement full semantics of UpdateCapsule.
Quoted 84 lines
Quoted 20 lines
This fixes SCT
UpdateCapsule_Conffailures.Reviewed-by Grant Likely <[email protected]>Signed-off-by Vincent Stehlé <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Alexander Graf <[email protected]>--- include/efi_loader.h | 24 ++++++++++++++++++++++++ lib/efi_loader/efi_capsule.c | 8 ++++---- lib/efi_loader/efi_runtime.c | 8 ++++++++ 3 files changed, 36 insertions(+), 4 deletions(-)include/efi_loader.h +0
-0@@ -910,6 +910,30 @@ extern const struct efi_firmware_management_protocol efi_fmp_fit;extern const struct efi_firmware_management_protocol efi_fmp_raw;/* Capsule update */ include/efi_loader.h extern const struct efi_firmware_management_protocol efi_fmp_fit; · line 922
Quoted 10 lines
include/efi_loader.h +10
-0+static inline efi_status_t +efi_valid_update_capsule_params (struct efi_capsule_header + **capsule_header_array, +efi_uintn_t capsule_count, +u64 scatter_gather_list) +{ +u32 flags; + +if (!capsule_count) +return EFI_INVALID_PARAMETER ;If capsule count > 1, don't you have to check all capsules headers?
include/efi_loader.h extern const struct efi_firmware_management_protocol efi_fmp_fit; · line 932
Quoted 10 lines
include/efi_loader.h +10
-0+ + flags = capsule_header_array[0 ]->flags; + +if (((flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET ) && + !scatter_gather_list) || + ((flags &CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE ) && + !(flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET )) || + ((flags &CAPSULE_FLAGS_INITIATE_RESET ) && + !(flags &CAPSULE_FLAGS_PERSIST_ACROSS_RESET ))) +return EFI_INVALID_PARAMETER ;What happens if capsule(0) has
CAPSULE_FLAGS_INITIATE_RESETand capsule(4) has !CAPSULE_FLAGS_PERSIST_ACROSS_RESET?Best regards
Heinrich
Quoted 33 lines
include/efi_loader.h +4
-0+ +return EFI_SUCCESS ; +} + efi_status_t EFIAPI efi_update_capsule( struct efi_capsule_header **capsule_header_array, efi_uintn_t capsule_count,lib/efi_loader/efi_capsule.c +4
-4@@ -442,12 +442,12 @@ efi_status_t EFIAPI efi_update_capsule(EFI_ENTRY ("%p, %zu, %llu\n" , capsule_header_array, capsule_count, scatter_gather_list); -if (!capsule_count) { - ret =EFI_INVALID_PARAMETER ; + ret =efi_valid_update_capsule_params (capsule_header_array, + capsule_count, + scatter_gather_list); +if (ret !=EFI_SUCCESS ) goto out; - } - ret =EFI_SUCCESS ;for (i =0 , capsule = *capsule_header_array; i < capsule_count; i++, capsule = *(++capsule_header_array)) {/* sanity check */ lib/efi_loader/efi_runtime.c +0
-0@@ -467,6 +467,14 @@ efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported(Quoted 8 lines
lib/efi_loader/efi_runtime.c efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported( · line 474
Quoted 8 lines
lib/efi_loader/efi_runtime.c +5
-0efi_uintn_t capsule_count, u64 scatter_gather_list) { +efi_status_t ret; + + ret =efi_valid_update_capsule_params (capsule_header_array, + capsule_count, + scatter_gather_list);This is "
efi_update_capsule_unsupported" function. We don't have to check parameters.
Quoted 1 line
-Takahiro Akashi
Hello Vincent,
I will mark this patch as "changes requested". Please, send an updated version.
Best regards
Heinrich
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
lib/efi_loader/efi_runtime.c +3
-0+if (ret !=EFI_SUCCESS ) +return ret; +return EFI_UNSUPPORTED ; }