Skip to content

Commit ee64575

Browse files
Ard BiesheuvelAlex Shi
authored andcommitted
efi: stub: implement efi_get_random_bytes() based on EFI_RNG_PROTOCOL
This exposes the firmware's implementation of EFI_RNG_PROTOCOL via a new function efi_get_random_bytes(). Reviewed-by: Matt Fleming <matt@codeblueprint.co.uk> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> (cherry picked from commit e4fbf4767440472f9d23b0f25a2b905e1c63b6a8) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent 98e23ea commit ee64575

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

drivers/firmware/efi/libstub/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE
3434
lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o string.o \
3535
$(patsubst %.c,lib-%.o,$(arm-deps))
3636

37-
lib-$(CONFIG_ARM64) += arm64-stub.o
37+
lib-$(CONFIG_ARM) += arm32-stub.o
38+
lib-$(CONFIG_ARM64) += arm64-stub.o random.o
3839
CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
3940

4041
#

drivers/firmware/efi/libstub/efistub.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
4343
unsigned long desc_size, efi_memory_desc_t *runtime_map,
4444
int *count);
4545

46+
efi_status_t efi_get_random_bytes(efi_system_table_t *sys_table,
47+
unsigned long size, u8 *out);
48+
4649
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2016 Linaro Ltd; <ard.biesheuvel@linaro.org>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
*/
9+
10+
#include <linux/efi.h>
11+
#include <asm/efi.h>
12+
13+
#include "efistub.h"
14+
15+
struct efi_rng_protocol {
16+
efi_status_t (*get_info)(struct efi_rng_protocol *,
17+
unsigned long *, efi_guid_t *);
18+
efi_status_t (*get_rng)(struct efi_rng_protocol *,
19+
efi_guid_t *, unsigned long, u8 *out);
20+
};
21+
22+
efi_status_t efi_get_random_bytes(efi_system_table_t *sys_table_arg,
23+
unsigned long size, u8 *out)
24+
{
25+
efi_guid_t rng_proto = EFI_RNG_PROTOCOL_GUID;
26+
efi_status_t status;
27+
struct efi_rng_protocol *rng;
28+
29+
status = efi_call_early(locate_protocol, &rng_proto, NULL,
30+
(void **)&rng);
31+
if (status != EFI_SUCCESS)
32+
return status;
33+
34+
return rng->get_rng(rng, NULL, size, out);
35+
}

include/linux/efi.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ typedef struct {
299299
void *open_protocol_information;
300300
void *protocols_per_handle;
301301
void *locate_handle_buffer;
302-
void *locate_protocol;
302+
efi_status_t (*locate_protocol)(efi_guid_t *, void *, void **);
303303
void *install_multiple_protocol_interfaces;
304304
void *uninstall_multiple_protocol_interfaces;
305305
void *calculate_crc32;
@@ -599,6 +599,10 @@ void efi_native_runtime_setup(void);
599599
#define EFI_PROPERTIES_TABLE_GUID \
600600
EFI_GUID( 0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5 )
601601

602+
#define EFI_RNG_PROTOCOL_GUID \
603+
EFI_GUID(0x3152bca5, 0xeade, 0x433d, \
604+
0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
605+
602606
typedef struct {
603607
efi_guid_t guid;
604608
u64 table;

0 commit comments

Comments
 (0)