2019-02-02 17:41:15 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-01-10 18:29:07 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Linaro Ltd; <ard.biesheuvel@linaro.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/efi.h>
|
|
|
|
#include <asm/efi.h>
|
|
|
|
|
|
|
|
#include "efistub.h"
|
|
|
|
|
2019-12-24 23:10:08 +08:00
|
|
|
typedef union efi_rng_protocol efi_rng_protocol_t;
|
2019-11-06 15:06:12 +08:00
|
|
|
|
2019-12-24 23:10:08 +08:00
|
|
|
union efi_rng_protocol {
|
|
|
|
struct {
|
2019-12-24 23:10:12 +08:00
|
|
|
efi_status_t (__efiapi *get_info)(efi_rng_protocol_t *,
|
|
|
|
unsigned long *,
|
|
|
|
efi_guid_t *);
|
|
|
|
efi_status_t (__efiapi *get_rng)(efi_rng_protocol_t *,
|
|
|
|
efi_guid_t *, unsigned long,
|
|
|
|
u8 *out);
|
2019-12-24 23:10:08 +08:00
|
|
|
};
|
|
|
|
struct {
|
|
|
|
u32 get_info;
|
|
|
|
u32 get_rng;
|
|
|
|
} mixed_mode;
|
2016-01-10 18:29:07 +08:00
|
|
|
};
|
|
|
|
|
2019-12-24 23:10:19 +08:00
|
|
|
efi_status_t efi_get_random_bytes(unsigned long size, u8 *out)
|
2016-01-10 18:29:07 +08:00
|
|
|
{
|
|
|
|
efi_guid_t rng_proto = EFI_RNG_PROTOCOL_GUID;
|
|
|
|
efi_status_t status;
|
2019-12-24 23:10:08 +08:00
|
|
|
efi_rng_protocol_t *rng = NULL;
|
2016-01-10 18:29:07 +08:00
|
|
|
|
efi/libstub: Rename efi_call_early/_runtime macros to be more intuitive
The macros efi_call_early and efi_call_runtime are used to call EFI
boot services and runtime services, respectively. However, the naming
is confusing, given that the early vs runtime distinction may suggest
that these are used for calling the same set of services either early
or late (== at runtime), while in reality, the sets of services they
can be used with are completely disjoint, and efi_call_runtime is also
only usable in 'early' code.
So do a global sweep to replace all occurrences with efi_bs_call or
efi_rt_call, respectively, where BS and RT match the idiom used by
the UEFI spec to refer to boot time or runtime services.
While at it, use 'func' as the macro parameter name for the function
pointers, which is less likely to collide and cause weird build errors.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Borislav Petkov <bp@alien8.de>
Cc: James Morse <james.morse@arm.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191224151025.32482-24-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-12-24 23:10:23 +08:00
|
|
|
status = efi_bs_call(locate_protocol, &rng_proto, NULL, (void **)&rng);
|
2016-01-10 18:29:07 +08:00
|
|
|
if (status != EFI_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
2019-12-24 23:10:21 +08:00
|
|
|
return efi_call_proto(rng, get_rng, NULL, size, out);
|
2016-01-10 18:29:07 +08:00
|
|
|
}
|
2016-01-11 17:43:16 +08:00
|
|
|
|
2019-12-24 23:10:19 +08:00
|
|
|
efi_status_t efi_random_get_seed(void)
|
2016-11-13 05:32:33 +08:00
|
|
|
{
|
|
|
|
efi_guid_t rng_proto = EFI_RNG_PROTOCOL_GUID;
|
|
|
|
efi_guid_t rng_algo_raw = EFI_RNG_ALGORITHM_RAW;
|
|
|
|
efi_guid_t rng_table_guid = LINUX_EFI_RANDOM_SEED_TABLE_GUID;
|
2019-12-24 23:10:08 +08:00
|
|
|
efi_rng_protocol_t *rng = NULL;
|
2019-12-24 21:29:08 +08:00
|
|
|
struct linux_efi_random_seed *seed = NULL;
|
2016-11-13 05:32:33 +08:00
|
|
|
efi_status_t status;
|
|
|
|
|
efi/libstub: Rename efi_call_early/_runtime macros to be more intuitive
The macros efi_call_early and efi_call_runtime are used to call EFI
boot services and runtime services, respectively. However, the naming
is confusing, given that the early vs runtime distinction may suggest
that these are used for calling the same set of services either early
or late (== at runtime), while in reality, the sets of services they
can be used with are completely disjoint, and efi_call_runtime is also
only usable in 'early' code.
So do a global sweep to replace all occurrences with efi_bs_call or
efi_rt_call, respectively, where BS and RT match the idiom used by
the UEFI spec to refer to boot time or runtime services.
While at it, use 'func' as the macro parameter name for the function
pointers, which is less likely to collide and cause weird build errors.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Borislav Petkov <bp@alien8.de>
Cc: James Morse <james.morse@arm.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191224151025.32482-24-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-12-24 23:10:23 +08:00
|
|
|
status = efi_bs_call(locate_protocol, &rng_proto, NULL, (void **)&rng);
|
2016-11-13 05:32:33 +08:00
|
|
|
if (status != EFI_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
efi/libstub: Rename efi_call_early/_runtime macros to be more intuitive
The macros efi_call_early and efi_call_runtime are used to call EFI
boot services and runtime services, respectively. However, the naming
is confusing, given that the early vs runtime distinction may suggest
that these are used for calling the same set of services either early
or late (== at runtime), while in reality, the sets of services they
can be used with are completely disjoint, and efi_call_runtime is also
only usable in 'early' code.
So do a global sweep to replace all occurrences with efi_bs_call or
efi_rt_call, respectively, where BS and RT match the idiom used by
the UEFI spec to refer to boot time or runtime services.
While at it, use 'func' as the macro parameter name for the function
pointers, which is less likely to collide and cause weird build errors.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Borislav Petkov <bp@alien8.de>
Cc: James Morse <james.morse@arm.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191224151025.32482-24-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-12-24 23:10:23 +08:00
|
|
|
status = efi_bs_call(allocate_pool, EFI_RUNTIME_SERVICES_DATA,
|
|
|
|
sizeof(*seed) + EFI_RANDOM_SEED_SIZE,
|
|
|
|
(void **)&seed);
|
2016-11-13 05:32:33 +08:00
|
|
|
if (status != EFI_SUCCESS)
|
|
|
|
return status;
|
|
|
|
|
2019-12-24 23:10:21 +08:00
|
|
|
status = efi_call_proto(rng, get_rng, &rng_algo_raw,
|
2019-11-06 15:06:12 +08:00
|
|
|
EFI_RANDOM_SEED_SIZE, seed->bits);
|
|
|
|
|
2016-11-13 05:32:33 +08:00
|
|
|
if (status == EFI_UNSUPPORTED)
|
|
|
|
/*
|
|
|
|
* Use whatever algorithm we have available if the raw algorithm
|
|
|
|
* is not implemented.
|
|
|
|
*/
|
2019-12-24 23:10:21 +08:00
|
|
|
status = efi_call_proto(rng, get_rng, NULL,
|
|
|
|
EFI_RANDOM_SEED_SIZE, seed->bits);
|
2016-11-13 05:32:33 +08:00
|
|
|
|
|
|
|
if (status != EFI_SUCCESS)
|
|
|
|
goto err_freepool;
|
|
|
|
|
2017-08-25 23:50:16 +08:00
|
|
|
seed->size = EFI_RANDOM_SEED_SIZE;
|
efi/libstub: Rename efi_call_early/_runtime macros to be more intuitive
The macros efi_call_early and efi_call_runtime are used to call EFI
boot services and runtime services, respectively. However, the naming
is confusing, given that the early vs runtime distinction may suggest
that these are used for calling the same set of services either early
or late (== at runtime), while in reality, the sets of services they
can be used with are completely disjoint, and efi_call_runtime is also
only usable in 'early' code.
So do a global sweep to replace all occurrences with efi_bs_call or
efi_rt_call, respectively, where BS and RT match the idiom used by
the UEFI spec to refer to boot time or runtime services.
While at it, use 'func' as the macro parameter name for the function
pointers, which is less likely to collide and cause weird build errors.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Borislav Petkov <bp@alien8.de>
Cc: James Morse <james.morse@arm.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191224151025.32482-24-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-12-24 23:10:23 +08:00
|
|
|
status = efi_bs_call(install_configuration_table, &rng_table_guid, seed);
|
2016-11-13 05:32:33 +08:00
|
|
|
if (status != EFI_SUCCESS)
|
|
|
|
goto err_freepool;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
err_freepool:
|
efi/libstub: Rename efi_call_early/_runtime macros to be more intuitive
The macros efi_call_early and efi_call_runtime are used to call EFI
boot services and runtime services, respectively. However, the naming
is confusing, given that the early vs runtime distinction may suggest
that these are used for calling the same set of services either early
or late (== at runtime), while in reality, the sets of services they
can be used with are completely disjoint, and efi_call_runtime is also
only usable in 'early' code.
So do a global sweep to replace all occurrences with efi_bs_call or
efi_rt_call, respectively, where BS and RT match the idiom used by
the UEFI spec to refer to boot time or runtime services.
While at it, use 'func' as the macro parameter name for the function
pointers, which is less likely to collide and cause weird build errors.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Borislav Petkov <bp@alien8.de>
Cc: James Morse <james.morse@arm.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191224151025.32482-24-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2019-12-24 23:10:23 +08:00
|
|
|
efi_bs_call(free_pool, seed);
|
2016-11-13 05:32:33 +08:00
|
|
|
return status;
|
|
|
|
}
|