Skip to content

Commit 41e8a7c

Browse files
Dominik Brodowskiardbiesheuvel
authored andcommitted
efi/random: use arch-independent efi_call_proto()
To handle all arch-specific peculiarities when calling an EFI protocol function, a wrapper efi_call_proto() exists on all relevant architectures. On arm/arm64, this is merely a plain function call. On x86, a special EFI entry stub needs to be used, however, as the calling convention differs. To make the efi/random stub arch-independent, use efi_call_proto() instead of the existing non-portable calls to the EFI get_rng protocol function. This also requires the addition of some typedefs. Signed-off-by: Dominik Brodowski <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 8b5c712 commit 41e8a7c

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

drivers/firmware/efi/libstub/random.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99

1010
#include "efistub.h"
1111

12+
typedef struct efi_rng_protocol efi_rng_protocol_t;
13+
14+
typedef struct {
15+
u32 get_info;
16+
u32 get_rng;
17+
} efi_rng_protocol_32_t;
18+
19+
typedef struct {
20+
u64 get_info;
21+
u64 get_rng;
22+
} efi_rng_protocol_64_t;
23+
1224
struct efi_rng_protocol {
1325
efi_status_t (*get_info)(struct efi_rng_protocol *,
1426
unsigned long *, efi_guid_t *);
@@ -28,7 +40,7 @@ efi_status_t efi_get_random_bytes(efi_system_table_t *sys_table_arg,
2840
if (status != EFI_SUCCESS)
2941
return status;
3042

31-
return rng->get_rng(rng, NULL, size, out);
43+
return efi_call_proto(efi_rng_protocol, get_rng, rng, NULL, size, out);
3244
}
3345

3446
/*
@@ -161,15 +173,16 @@ efi_status_t efi_random_get_seed(efi_system_table_t *sys_table_arg)
161173
if (status != EFI_SUCCESS)
162174
return status;
163175

164-
status = rng->get_rng(rng, &rng_algo_raw, EFI_RANDOM_SEED_SIZE,
165-
seed->bits);
176+
status = efi_call_proto(efi_rng_protocol, get_rng, rng, &rng_algo_raw,
177+
EFI_RANDOM_SEED_SIZE, seed->bits);
178+
166179
if (status == EFI_UNSUPPORTED)
167180
/*
168181
* Use whatever algorithm we have available if the raw algorithm
169182
* is not implemented.
170183
*/
171-
status = rng->get_rng(rng, NULL, EFI_RANDOM_SEED_SIZE,
172-
seed->bits);
184+
status = efi_call_proto(efi_rng_protocol, get_rng, rng, NULL,
185+
EFI_RANDOM_SEED_SIZE, seed->bits);
173186

174187
if (status != EFI_SUCCESS)
175188
goto err_freepool;

0 commit comments

Comments
 (0)