[image] Always unregister currently executing image

We unregister script images during their execution, to prevent a
"boot" command from re-executing the containing script.  This also has
the side effect of preventing executing scripts from showing up within
the Linux magic initrd image (or the Multiboot module list).

Additional logic in bzimage.c and efi_file.c prevents a currently
executing kernel from showing up within the magic initrd image.
Similar logic in multiboot.c prevents the Multiboot kernel from
showing up as a Multiboot module.

This still leaves some corner cases that are not covered correctly.
For example: when using a gzip-compressed kernel image, nothing will
currently hide the original compressed image from the magic initrd.

Fix by moving the logic that temporarily unregisters the current image
from script_exec() to image_exec(), so that it applies to all image
types, and simplify the magic initrd and Multiboot module list
construction logic on the basis that no further filtering of the
registered image list is necessary.

This change has the side effect of hiding currently executing EFI
images from the virtual filesystem exposed by iPXE.  For example, when
using iPXE to boot wimboot, the wimboot binary itself will no longer
be visible within the virtual filesystem.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2023-03-06 16:28:48 +00:00
parent e51e7bbad7
commit 9e1f7a3659
5 changed files with 10 additions and 29 deletions

View File

@@ -240,10 +240,6 @@ static size_t efi_file_read_initrd ( struct efi_file_reader *reader ) {
len = 0;
for_each_image ( image ) {
/* Ignore currently executing image */
if ( image == current_image )
continue;
/* Pad to alignment boundary */
pad_len = ( ( -reader->pos ) & ( INITRD_ALIGN - 1 ) );
if ( pad_len ) {
@@ -1091,7 +1087,7 @@ int efi_file_install ( EFI_HANDLE handle ) {
* instance only if the initrd is non-empty, since Linux does
* not gracefully handle a zero-length initrd.
*/
load = ( list_is_singular ( &images ) ? NULL : &efi_file_initrd.load );
load = ( have_images() ? &efi_file_initrd.load : NULL );
if ( ( rc = efi_file_path_install ( &efi_file_initrd_path.vendor.Header,
load ) ) != 0 ) {
goto err_initrd;