]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-stub: fix assertion failure when cleaning up initrd pages
authorLuca Boccassi <luca.boccassi@gmail.com>
Wed, 30 Apr 2025 22:21:46 +0000 (23:21 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 May 2025 04:09:21 +0000 (13:09 +0900)
When linux_exec() fails, the initrd pages cleanup attempts to run,
and an assertion is triggered:

../src/boot/linux.c:125@linux_exec: Error loading kernel image: Security violation
../src/boot/util.h:81@cleanup_pages: Error freeing pages: Not found
../src/boot/log.c:30@efi_assert: systemd-boot: Assertion 'r == EFI_SUCCESS' failed at ../src/boot/util.h:82@cleanup_pages, halting.

(log message is new)

This was introduced by https://github.com/systemd/systemd/pull/36715

Before that change, given the argument to xmalloc_pages() was passed as EFI_SIZE_TO_PAGES(n_pages), that's
what ended up in Pages.n_pages. After this change, n_pages gets assigned without being transformed by
EFI_SIZE_TO_PAGES, so the cleanup can find them again. That change causes the assertion failure to trigger.
Changing this to .n_pages = EFI_SIZE_TO_PAGES(n_pages) fixes the assertion.

Follow-up for c5a50467921f615846b3bbe3c3ff592953a6163a

src/boot/util.h

index 323fb5163b14307a490af13fa58521a4200d1e1b..115258d5ee74517bcd87a5480dc0ffd164f52d4d 100644 (file)
@@ -112,7 +112,7 @@ static inline Pages xmalloc_initrd_pages(size_t n_pages) {
                         &addr) == EFI_SUCCESS)
                 return (Pages) {
                         .addr = addr,
-                        .n_pages = n_pages,
+                        .n_pages = EFI_SIZE_TO_PAGES(n_pages),
                 };
 #endif
         return xmalloc_pages(