]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: stop appending NUL to .sdmagic and .sbat sections 34950/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 30 Oct 2024 14:30:53 +0000 (15:30 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 31 Oct 2024 13:58:12 +0000 (14:58 +0100)
Those text sections had a trailing NUL byte. It's debatable whether this is a
good idea or not. Correctly written consumers will look at the section size so
they wouldn't need this. Shim doesn't use a trailing NUL, so let's follow suit.

Fixes https://github.com/systemd/systemd/issues/33731.

898e9edc469f87fdb6018128bac29eef0a5fe698 reworked this code, but didn't actually
change the logic. We have always been appending the trailing zero by using a
NUL-terminated string as the section contents. (I checked this with v253.18
from before the elf2efi rework.)

.sdmagic contains a string like "#### LoaderInfo: systemd-boot 257~devel ####",
which changes with each version, so previous versions would compare unequal
anyway, so we don't need to worry about backwards compatibility.

src/boot/efi/boot.c
src/fundamental/macro-fundamental.h

index a8c7b6881fc5a319aa1cc5d00db44a314f422e35..87b0232860f02093702ee25a499967273e315a9a 100644 (file)
@@ -1926,14 +1926,14 @@ static bool is_sd_boot(EFI_FILE *root_dir, const char16_t *loader_path) {
                         /* profile= */ UINT_MAX,
                         /* validate_base= */ 0,
                         &vector);
-        if (vector.memory_size != sizeof(SD_MAGIC))
+        if (vector.memory_size != STRLEN(SD_MAGIC))
                 return false;
 
         err = file_handle_read(handle, vector.file_offset, vector.file_size, &content, &read);
         if (err != EFI_SUCCESS || vector.file_size != read)
                 return false;
 
-        return memcmp(content, SD_MAGIC, sizeof(SD_MAGIC)) == 0;
+        return memcmp(content, SD_MAGIC, STRLEN(SD_MAGIC)) == 0;
 }
 
 static BootEntry* config_add_entry_loader_auto(
index 7e604b8283b59e83399d576a67e2e8dcdc1e39ee..35758b5b1897436f0459cc288091ab470c6d1ee8 100644 (file)
@@ -542,7 +542,6 @@ static inline uint64_t ALIGN_OFFSET_U64(uint64_t l, uint64_t ali) {
 #define DECLARE_NOALLOC_SECTION(name, text)   \
         asm(".pushsection " name ",\"S\"\n\t" \
             ".ascii " STRINGIFY(text) "\n\t"  \
-            ".zero 1\n\t"                     \
             ".popsection\n")
 
 #ifdef SBAT_DISTRO