From: Luca Boccassi Date: Wed, 30 Apr 2025 22:21:46 +0000 (+0100) Subject: sd-stub: fix assertion failure when cleaning up initrd pages X-Git-Tag: v258-rc1~705 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=204445454889c95aaf6add8c4d50627c0a1bcc3d;p=thirdparty%2Fsystemd.git sd-stub: fix assertion failure when cleaning up initrd pages 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 --- diff --git a/src/boot/util.h b/src/boot/util.h index 323fb5163b1..115258d5ee7 100644 --- a/src/boot/util.h +++ b/src/boot/util.h @@ -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(