Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malformed section header when creating UKI with dracut and upstream systemd-stub #2284

Closed
esposem opened this issue Mar 21, 2023 · 4 comments · Fixed by #2285
Closed

Malformed section header when creating UKI with dracut and upstream systemd-stub #2284

esposem opened this issue Mar 21, 2023 · 4 comments · Fixed by #2285
Labels
bug Our bugs

Comments

@esposem
Copy link
Contributor

esposem commented Mar 21, 2023

Describe the bug

When creating an UKI with manually compiled systemd-stub (checked out at master/HEAD) and rebooting, system should boot using the given UKI.

BdsDxe: loading Boot0004 "UKI_test" from HD(2,GPT,68B2905B-DF3E-4FB3-80FA-49D1E773AA33,0x1000,0x64000)/\EFI\redhat\shimx64.efi
BdsDxe: starting Boot0004 "UKI_test" from HD(2,GPT,68B2905B-DF3E-4FB3-80FA-49D1E773AA33,0x1000,0x64000)/\EFI\redhat\shimx64.efi
EFI stub: Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path
[    0.000000] Linux version 5.14.0-284.el9.x86_64 (mockbuild@x86-vm-09.build.eng.bos.redhat.com) (gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4), GNU ld version 2.35.2-37.el9) #1 SMP PREEMPT_DYNAMIC Mon Feb 27 20:08:54 EST 2023
[    0.000000] The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the Red Hat Ecosystem Catalog, https://catalog.redhat.com.
[    0.000000] Command line:  console=tty0 console=ttyS0  

Then efibootmgr shows:

# efibootmgr
BootCurrent: 0004
Timeout: 3 seconds
BootOrder: 0004,0001,0002,0000,0003
Boot0000* UiApp
Boot0001* redhat
Boot0002* UEFI Misc Device
Boot0003* EFI Internal Shell
Boot0004* UKI_test

NOTE: it works when systemd is checked out at v252

Instead I see:

BdsDxe: loading Boot0004 "UKI_test" from HD(2,GPT,68B2905B-DF3E-4FB3-80FA-49D1E773AA33,0x1000,0x64000)/\EFI\redhat\shimx64.efi
BdsDxe: starting Boot0004 "UKI_test" from HD(2,GPT,68B2905B-DF3E-4FB3-80FA-49D1E773AA33,0x1000,0x64000)/\EFI\redhat\shimx64.efi
Section 0 has invalid base address
Malformed section header
Failed to load image: Unsupported
start_image() returned Unsupported
BdsDxe: failed to start Boot0004 "UKI_test" from HD(2,GPT,68B2905B-DF3E-4FB3-80FA-49D1E773AA33,0x1000,0x64000)/\EFI\redhat\shimx64.efi: Unsupported
BdsDxe: loading Boot0001 "redhat" from HD(2,GPT,68B2905B-DF3E-4FB3-80FA-49D1E773AA33,0x1000,0x64000)/\EFI\redhat\shimx64.efi
BdsDxe: starting Boot0001 "redhat" from HD(2,GPT,68B2905B-DF3E-4FB3-80FA-49D1E773AA33,0x1000,0x64000)/\EFI\redhat\shimx64.efi
  Booting `Red Hat Enterprise Linux (5.14.0-284.el9.x86_64) 9.3 (Plow)'

[    0.000000] Linux version 5.14.0-284.el9.x86_64 (mockbuild@x86-vm-09.build.eng.bos.redhat.com) (gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4), GNU ld version 2.35.2-37.el9) #1 SMP PREEMPT_DYNAMIC Mon Feb 27 20:08:54 EST 2023
[    0.000000] The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the Red Hat Ecosystem Catalog, https://catalog.redhat.com.
[    0.000000] Command line: BOOT_IMAGE=(hd0,gpt3)/vmlinuz-5.14.0-284.el9.x86_64 root=UUID=4490d61b-9a2c-4c9d-8c4e-f3129e6e9034 console=tty0 console=ttyS0,115200n8 no_timer_check net.ifnames=0 crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M

Then efibootmgr shows:

# efibootmgr
BootCurrent: 0001
Timeout: 3 seconds
BootOrder: 0004,0001,0002,0000,0003
Boot0000* UiApp
Boot0001* redhat
Boot0002* UEFI Misc Device
Boot0003* EFI Internal Shell
Boot0004* UKI_test

Distribution used
RHEL 9.3

Dracut version
dracut 057-21.git20230214.el9

Init system
Which init system is being used?

To Reproduce

  1. Dowload systemd
  2. ./configure -Dbootloader=true
  3. make # binary is in /mnt/systemd/build/src/boot/efi/linuxx64.efi.stub
  4. dracut --conf=/root/dracut-virt.conf --confdir=$(mktemp -d) --verbose --kver 5.14.0-284.el9.x86_64 --kmoddir=/lib/modules/5.14.0-284.el9.x86_64/ --logfile=log --uefi --kernel-image=/boot/vmlinuz-5.14.0-284.el9.x86_64 --kernel-cmdline 'console=tty0 console=ttyS0' --uefi-stub /mnt/systemd/build/src/boot/efi/linuxx64.efi.stub /boot/efi/EFI/Linux/testi.efi
  5. printf "\EFI\Linux\test.efi\0" | iconv -f ASCII -t UCS-2 > /tmp/bootarg
  6. efibootmgr -c -d /dev/vda -p 2 --append-binary-args /tmp/bootarg -L UKI_test -l "\EFI\redhat\shimx64.efi"
  7. reboot
  8. check boot loog and after login run efibootmgr

note: when using ukify instead of dracut, systemd-stub works regardless of the version it is checked out.

Expected behavior
See bug description

@esposem esposem added the bug Our bugs label Mar 21, 2023
@esposem
Copy link
Contributor Author

esposem commented Mar 21, 2023

As suggested by systemd folks in systemd/systemd#26915 (comment), copying the above issue here

@esposem
Copy link
Contributor Author

esposem commented Mar 21, 2023

Possible fix:
It seems that dracut needs to handle when ImageBase is not 0.
Alternatively, why not call ukify to create the UKI instead of reimplementing the wheel once again?

@medhefgo
Copy link

medhefgo commented Mar 21, 2023

You need latest dracut master for this to work. See #2275.

You can verify by running objdump -h on the UKI. It should complain about sections being below ImageBase.

@esposem
Copy link
Contributor Author

esposem commented Mar 22, 2023

Doesn't complain, but you're right, with upstream dracut it works fine. Closing this issue, thanks!

@esposem esposem closed this as completed Mar 22, 2023
keentux added a commit to keentux/dracut that referenced this issue Mar 22, 2023
* UEFI creation didn't handle the ImageBase data for the PE file
  generation. Create an UKI thanks a stub file with a non zero BaseImage
  logs some warning ans generate a bad file offset management. The efi
  becomes unloadable.
* This commit parse the PE file header, get the data and apply the
  ImageBase on the objcopy command.

Fixes dracutdevs#2284

Signed-off-by: Valentin Lefebvre <valentin.lefebvre@suse.com>
keentux added a commit to keentux/dracut that referenced this issue Mar 22, 2023
* UEFI creation didn't handle the ImageBase data for the PE file
  generation. Create an UKI thanks a stub file with a non zero BaseImage
  logs some warning ans generate a bad file offset management. The efi
  becomes unloadable.
* This commit parse the PE file header, get the data and apply the
  ImageBase on the objcopy command.

Fixes dracutdevs#2284

Signed-off-by: Valentin Lefebvre <valentin.lefebvre@suse.com>
keentux added a commit to keentux/dracut that referenced this issue Mar 22, 2023
* UEFI creation didn't handle the ImageBase data for the PE file
  generation. Create an UKI thanks a stub file with a non zero BaseImage
  logs some warning ans generate a bad file offset management. The efi
  becomes unloadable.
* This commit parse the PE file header, get the data and apply the
  ImageBase on the objcopy command.

Fixes dracutdevs#2284

Signed-off-by: Valentin Lefebvre <valentin.lefebvre@suse.com>
keentux added a commit to keentux/dracut that referenced this issue Mar 22, 2023
* UEFI creation didn't handle the ImageBase data for the PE file
  generation. Create an UKI thanks a stub file with a non zero BaseImage
  logs some warning ans generate a bad file offset management. The efi
  becomes unloadable.
* This commit parse the PE file header, get the data and apply the
  ImageBase on the objcopy command.

Fixes dracutdevs#2284

Signed-off-by: Valentin Lefebvre <valentin.lefebvre@suse.com>
LaszloGombos pushed a commit that referenced this issue May 9, 2023
* UEFI creation didn't handle the ImageBase data for the PE file
  generation. Create an UKI thanks a stub file with a non zero BaseImage
  logs some warning ans generate a bad file offset management. The efi
  becomes unloadable.
* This commit parse the PE file header, get the data and apply the
  ImageBase on the objcopy command.

Fixes #2284

Signed-off-by: Valentin Lefebvre <valentin.lefebvre@suse.com>
pvalena pushed a commit to pvalena/dracut that referenced this issue Jul 23, 2023
* UEFI creation didn't handle the ImageBase data for the PE file
  generation. Create an UKI thanks a stub file with a non zero BaseImage
  logs some warning ans generate a bad file offset management. The efi
  becomes unloadable.
* This commit parse the PE file header, get the data and apply the
  ImageBase on the objcopy command.

Fixes dracutdevs#2284

Signed-off-by: Valentin Lefebvre <valentin.lefebvre@suse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Our bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants