summaryrefslogtreecommitdiffstats
path: root/src/boot
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2022-11-16 19:27:50 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2022-11-17 12:22:27 +0100
commit3daeef088410cdddef622007f95b0a1b4a439532 (patch)
tree5e2cf2d77f316c848ff972d0272f0244dbd00b66 /src/boot
parentMerge pull request #25096 from DaanDeMeyer/journald-log-fixes (diff)
downloadsystemd-3daeef088410cdddef622007f95b0a1b4a439532.tar.xz
systemd-3daeef088410cdddef622007f95b0a1b4a439532.zip
random-seed: handle post-merge review nits
These are various misc things that came up after merging.
Diffstat (limited to 'src/boot')
-rw-r--r--src/boot/bootctl.c2
-rw-r--r--src/boot/efi/random-seed.c6
-rw-r--r--src/boot/efi/util.h4
3 files changed, 7 insertions, 5 deletions
diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c
index e04424b379..afda914d52 100644
--- a/src/boot/bootctl.c
+++ b/src/boot/bootctl.c
@@ -1975,7 +1975,7 @@ static int verb_list(int argc, char *argv[], void *userdata) {
static int install_random_seed(const char *esp) {
_cleanup_(unlink_and_freep) char *tmp = NULL;
- unsigned char buffer[RANDOM_EFI_SEED_SIZE];
+ uint8_t buffer[RANDOM_EFI_SEED_SIZE];
_cleanup_free_ char *path = NULL;
_cleanup_close_ int fd = -1;
size_t token_size;
diff --git a/src/boot/efi/random-seed.c b/src/boot/efi/random-seed.c
index 04bfd526f8..02f4dfbc7f 100644
--- a/src/boot/efi/random-seed.c
+++ b/src/boot/efi/random-seed.c
@@ -59,7 +59,6 @@ static EFI_STATUS acquire_system_token(void **ret, UINTN *ret_size) {
assert(ret);
assert(ret_size);
- *ret_size = 0;
err = efivar_get_raw(LOADER_GUID, L"LoaderSystemToken", &data, &size);
if (err != EFI_SUCCESS) {
if (err != EFI_NOT_FOUND)
@@ -187,6 +186,7 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
/* Get some system specific seed that the installer might have placed in an EFI variable. We include
* it in our hash. This is protection against golden master image sloppiness, and it remains on the
* system, even when disk images are duplicated or swapped out. */
+ size = 0;
err = acquire_system_token(&system_token, &size);
if (mode != RANDOM_SEED_ALWAYS && (err != EFI_SUCCESS || size < DESIRED_SEED_SIZE) && !seeded_by_efi)
return err;
@@ -246,6 +246,7 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
size = sizeof(uefi_monotonic_counter);
sha256_process_bytes(&size, sizeof(size), &hash);
sha256_process_bytes(&uefi_monotonic_counter, size, &hash);
+
err = RT->GetTime(&now, NULL);
size = err == EFI_SUCCESS ? sizeof(now) : 0; /* Known to be flaky, so don't bark on error. */
sha256_process_bytes(&size, sizeof(size), &hash);
@@ -295,7 +296,8 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
if (err != EFI_SUCCESS)
return log_error_status_stall(err, L"Failed to flush random seed file: %r", err);
- err = BS->AllocatePool(EfiACPIReclaimMemory, sizeof(*new_seed_table) + DESIRED_SEED_SIZE,
+ err = BS->AllocatePool(EfiACPIReclaimMemory,
+ offsetof(struct linux_efi_random_seed, seed) + DESIRED_SEED_SIZE,
(void **) &new_seed_table);
if (err != EFI_SUCCESS)
return log_error_status_stall(err, L"Failed to allocate EFI table for random seed: %r", err);
diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h
index 15dd87f774..eed28c0342 100644
--- a/src/boot/efi/util.h
+++ b/src/boot/efi/util.h
@@ -20,7 +20,7 @@ __attribute__((noreturn)) extern void __assert_cl_failure__(void) __attribute__(
__attribute__((noreturn)) extern void __assert_cl_failure__(void);
#endif
/* assert_cl generates a later-stage compile-time assertion when constant folding occurs. */
-#define assert_cl(condition) if (!(condition)) __assert_cl_failure__()
+#define assert_cl(condition) ({ if (!(condition)) __assert_cl_failure__(); })
#else
#define assert_cl(condition) assert(condition)
#endif
@@ -60,7 +60,7 @@ static inline void freep(void *p) {
static __always_inline void erase_obj(void *p) {
size_t l;
- assert_cl(p != NULL);
+ assert_cl(p);
l = __builtin_object_size(p, 0);
assert_cl(l != (size_t) -1);
explicit_bzero_safe(p, l);