From df28afe9b2de9e480121c25f222fa487fed927ce Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 9 Feb 2025 09:53:39 +0100 Subject: [PATCH 1/4] bootctl: fix potential uninitialized memory access And while we are at it, let' get rid of have_xyz_partition_uuid variables, to simplify things. --- src/bootctl/bootctl-status.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/bootctl/bootctl-status.c b/src/bootctl/bootctl-status.c index 75ffb9fdba..1fe2de0b23 100644 --- a/src/bootctl/bootctl-status.c +++ b/src/bootctl/bootctl-status.c @@ -476,10 +476,9 @@ int verb_status(int argc, char *argv[], void *userdata) { for (size_t i = 0; i < ELEMENTSOF(loader_flags); i++) print_yes_no_line(i == 0, FLAGS_SET(loader_features, loader_flags[i].flag), loader_flags[i].name); - sd_id128_t loader_partition_uuid; - bool have_loader_partition_uuid = efi_loader_get_device_part_uuid(&loader_partition_uuid) >= 0; - - print_yes_no_line(false, have_loader_partition_uuid, "Boot loader set ESP information"); + sd_id128_t loader_partition_uuid = SD_ID128_NULL; + (void) efi_loader_get_device_part_uuid(&loader_partition_uuid); + print_yes_no_line(/* first= */ false, !sd_id128_is_null(loader_partition_uuid), "Boot loader set partition information"); if (current_entry) printf("Current Entry: %s\n", current_entry); @@ -488,14 +487,14 @@ int verb_status(int argc, char *argv[], void *userdata) { if (oneshot_entry && !streq_ptr(oneshot_entry, default_entry)) printf("OneShot Entry: %s\n", oneshot_entry); - if (have_loader_partition_uuid && !sd_id128_is_null(esp_uuid) && !sd_id128_equal(esp_uuid, loader_partition_uuid)) - printf("WARNING: The boot loader reports a different partition UUID than the detected ESP ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR")!\n", - SD_ID128_FORMAT_VAL(loader_partition_uuid), SD_ID128_FORMAT_VAL(esp_uuid)); + if (!sd_id128_is_null(loader_partition_uuid)) { + if (!sd_id128_is_null(esp_uuid) && !sd_id128_equal(esp_uuid, loader_partition_uuid)) + printf("WARNING: The boot loader reports a different partition UUID than the detected ESP ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR")!\n", + SD_ID128_FORMAT_VAL(loader_partition_uuid), SD_ID128_FORMAT_VAL(esp_uuid)); - if (!sd_id128_is_null(loader_partition_uuid)) printf(" Partition: /dev/disk/by-partuuid/" SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(loader_partition_uuid)); - else + } else printf(" Partition: n/a\n"); printf(" Loader: %s%s\n", special_glyph(SPECIAL_GLYPH_TREE_RIGHT), strna(loader_path)); printf("\n"); @@ -507,17 +506,18 @@ int verb_status(int argc, char *argv[], void *userdata) { for (size_t i = 0; i < ELEMENTSOF(stub_flags); i++) print_yes_no_line(i == 0, FLAGS_SET(stub_features, stub_flags[i].flag), stub_flags[i].name); - sd_id128_t stub_partition_uuid; - bool have_stub_partition_uuid = efi_stub_get_device_part_uuid(&stub_partition_uuid) >= 0; + sd_id128_t stub_partition_uuid = SD_ID128_NULL; + (void) efi_stub_get_device_part_uuid(&stub_partition_uuid); + + if (!sd_id128_is_null(stub_partition_uuid)) { + if (!(!sd_id128_is_null(esp_uuid) && sd_id128_equal(esp_uuid, stub_partition_uuid)) && + !(!sd_id128_is_null(xbootldr_uuid) && sd_id128_equal(xbootldr_uuid, stub_partition_uuid))) + printf("WARNING: The stub loader reports a different UUID than the detected ESP or XBOOTDLR partition ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR"/"SD_ID128_UUID_FORMAT_STR")!\n", + SD_ID128_FORMAT_VAL(stub_partition_uuid), SD_ID128_FORMAT_VAL(esp_uuid), SD_ID128_FORMAT_VAL(xbootldr_uuid)); - if (have_stub_partition_uuid && (!(!sd_id128_is_null(esp_uuid) && sd_id128_equal(esp_uuid, stub_partition_uuid)) && - !(!sd_id128_is_null(xbootldr_uuid) && sd_id128_equal(xbootldr_uuid, stub_partition_uuid)))) - printf("WARNING: The stub loader reports a different UUID than the detected ESP or XBOOTDLR partition ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR"/"SD_ID128_UUID_FORMAT_STR")!\n", - SD_ID128_FORMAT_VAL(stub_partition_uuid), SD_ID128_FORMAT_VAL(esp_uuid), SD_ID128_FORMAT_VAL(xbootldr_uuid)); - if (!sd_id128_is_null(stub_partition_uuid)) printf(" Partition: /dev/disk/by-partuuid/" SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(stub_partition_uuid)); - else + } else printf(" Partition: n/a\n"); printf(" Stub: %s%s\n", special_glyph(SPECIAL_GLYPH_TREE_RIGHT), strna(stub_path)); printf("\n"); From 26bfd97216ab55664214d1e0fac7065e5573a36b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 9 Feb 2025 23:21:08 +0100 Subject: [PATCH 2/4] bootctl: also shown whether stub loader partition data was passed Let's make the stub and loader output sections more alike, and say in both cases whether we recieved that data from the boot phase or not the same way. --- src/bootctl/bootctl-status.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootctl/bootctl-status.c b/src/bootctl/bootctl-status.c index 1fe2de0b23..9d32bdb95f 100644 --- a/src/bootctl/bootctl-status.c +++ b/src/bootctl/bootctl-status.c @@ -508,6 +508,7 @@ int verb_status(int argc, char *argv[], void *userdata) { sd_id128_t stub_partition_uuid = SD_ID128_NULL; (void) efi_stub_get_device_part_uuid(&stub_partition_uuid); + print_yes_no_line(/* first= */ false, !sd_id128_is_null(stub_partition_uuid), "Stub loader set partition information"); if (!sd_id128_is_null(stub_partition_uuid)) { if (!(!sd_id128_is_null(esp_uuid) && sd_id128_equal(esp_uuid, stub_partition_uuid)) && From df418fa234a5b12e302a336df82c97f33871ae35 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 9 Feb 2025 23:23:38 +0100 Subject: [PATCH 3/4] bootctl: suppress output of empty partition info if we also have no idea about EFI binary path So far we'd output both the partition and the binary path always, even if we didn't know either (but in that case show empty information). Let's address this, and show partition info only if we know it, or if we know the EFI binary path, but suppress both if we know neither. Note that we'll show the partition info if we don't know it still if we know the EFI binary path used for boot, since it is relative to the partition of course, and hence it's really strange to know one but not the other, hence it deserves some mentioning in the output. --- src/bootctl/bootctl-status.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bootctl/bootctl-status.c b/src/bootctl/bootctl-status.c index 9d32bdb95f..a9fc43e417 100644 --- a/src/bootctl/bootctl-status.c +++ b/src/bootctl/bootctl-status.c @@ -494,9 +494,11 @@ int verb_status(int argc, char *argv[], void *userdata) { printf(" Partition: /dev/disk/by-partuuid/" SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(loader_partition_uuid)); - } else + } else if (loader_path) printf(" Partition: n/a\n"); - printf(" Loader: %s%s\n", special_glyph(SPECIAL_GLYPH_TREE_RIGHT), strna(loader_path)); + + if (loader_path) + printf(" Loader: %s%s\n", special_glyph(SPECIAL_GLYPH_TREE_RIGHT), strna(loader_path)); printf("\n"); } @@ -518,9 +520,11 @@ int verb_status(int argc, char *argv[], void *userdata) { printf(" Partition: /dev/disk/by-partuuid/" SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(stub_partition_uuid)); - } else + } else if (stub_path) printf(" Partition: n/a\n"); - printf(" Stub: %s%s\n", special_glyph(SPECIAL_GLYPH_TREE_RIGHT), strna(stub_path)); + + if (stub_path) + printf(" Stub: %s%s\n", special_glyph(SPECIAL_GLYPH_TREE_RIGHT), strna(stub_path)); printf("\n"); } From af5b961ad8f22be04f47c1c0e729b1e6fd78b423 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 9 Feb 2025 23:34:29 +0100 Subject: [PATCH 4/4] bootctl: minor reordering of fields in output Let's move the currently used/default/oneshot entry output after the basic info about the boot loader itself, since conceptually these are objects kinda "one level down" from the boot loader perspective. Hence, let's *first* show all info about the boot loader itself before we display the objects it manages. This is just a trivial change in output, just swaps th elines for these fields with the ones showing where the boot loader is installed. --- src/bootctl/bootctl-status.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/bootctl/bootctl-status.c b/src/bootctl/bootctl-status.c index a9fc43e417..e9f3a6f5b5 100644 --- a/src/bootctl/bootctl-status.c +++ b/src/bootctl/bootctl-status.c @@ -480,13 +480,6 @@ int verb_status(int argc, char *argv[], void *userdata) { (void) efi_loader_get_device_part_uuid(&loader_partition_uuid); print_yes_no_line(/* first= */ false, !sd_id128_is_null(loader_partition_uuid), "Boot loader set partition information"); - if (current_entry) - printf("Current Entry: %s\n", current_entry); - if (default_entry) - printf("Default Entry: %s\n", default_entry); - if (oneshot_entry && !streq_ptr(oneshot_entry, default_entry)) - printf("OneShot Entry: %s\n", oneshot_entry); - if (!sd_id128_is_null(loader_partition_uuid)) { if (!sd_id128_is_null(esp_uuid) && !sd_id128_equal(esp_uuid, loader_partition_uuid)) printf("WARNING: The boot loader reports a different partition UUID than the detected ESP ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR")!\n", @@ -499,6 +492,14 @@ int verb_status(int argc, char *argv[], void *userdata) { if (loader_path) printf(" Loader: %s%s\n", special_glyph(SPECIAL_GLYPH_TREE_RIGHT), strna(loader_path)); + + if (current_entry) + printf("Current Entry: %s\n", current_entry); + if (default_entry) + printf("Default Entry: %s\n", default_entry); + if (oneshot_entry && !streq_ptr(oneshot_entry, default_entry)) + printf("OneShot Entry: %s\n", oneshot_entry); + printf("\n"); }