intel / ccc-linux-guest-hardening

Linux Security Hardening for Confidential Compute
https://intel.github.io/ccc-linux-guest-hardening-docs
MIT License
66 stars 14 forks source link

initramfs unpacking failed: invalid magic at start of compressed image #90

Closed williamcroberts closed 1 year ago

williamcroberts commented 1 year ago

initramfs unpacking failed: invalid magic at start of compressed image, see below image:

PXL_20230221_170927088

williamcroberts commented 1 year ago

I followed the steps on the README (https://github.com/intel/ccc-linux-guest-hardening#readme) and did a make deploy and the rebooted.

Wenzel commented 1 year ago

Hello @williamcroberts ! I fell like this is an issue related to an unsupported compression algorithm used by the initramfs.

williamcroberts commented 1 year ago

Hello @williamcroberts ! I fell like this is an issue related to an unsupported compression algorithm used by the initramfs.

Why does make deploy pick a bad initramfs algorithm?

williamcroberts commented 1 year ago

Ok So it re-uses the existing initramfs, I thought it was generating a new one. So if the initramfs is ahead of the kernel, boom.

il-steffen commented 1 year ago

On debian/ubuntu the image is generated by initramfs-tools helpers. We don't do the full deploy with kernel install very often but it may be related to recent updates in Ubuntu or using a "too new" distro version.

You can change the default compression algo in /etc/initramfs-tools/

williamcroberts commented 1 year ago

So the workaround for others is to verify the compression algorithm in /etc/initramfs-tools/initramfs.conf (at least in ubuntu-22.04) and check the algorithm used for the COMPRESS variable. Mine was on zstd, changing it to lz4 and rebuilding the initramfs via sudo update-initramfs -c -k all and re-deploying.

tz0 commented 1 year ago

I tried a fresh install using make deploy on a local machine and can boot into the SDV emulation kernel. My compression is xz.

image_2023-02-28_17-22-22
williamcroberts commented 1 year ago

Ok I was able to boot the environment, I did the following:

  1. Did a fresh install of Ubuntu 22.04
  2. Updated my init-ramfs compression algorithm from zstd to lz4
  3. did the make deploy
  4. rebooted

As a side note, many of the apps don't work as it complains about cgroup operation not being supported. Probably a mismatch between userspace and kernel version.

williamcroberts commented 1 year ago

Following the instructions here:

and adding systemd.unified_cgroup_hierarchy=0 to my kernel cmd line by following the instructions here:

ereshetova commented 1 year ago

I think we need a doc update to highlight this problem. I have run into the same on my machine.

ereshetova commented 1 year ago

So the steps to fix this (minimal set):

  1. Edit /etc/initramfs-tools/initramfs.conf to change the algorithm from zstd to lz4
  2. Rebuild the initramfs as 'sudo update-initramfs -c -k all'
  3. Reboot

Nothing else is needed, you should be able to boot to the kafl kernel sucessfully.

@tz0 could you please make a quick PR with the above instructions for workarounds to the docs? I have verified that the previous sequence works on my ubuntu 22 LTS

williamcroberts commented 1 year ago

The other thing is, where does this host kernel come from? Can we enable ztsd support in it?

Wenzel commented 1 year ago

@williamcroberts this host kernel comes from our kafl.linux releases

ZSTD compression is only supported starting with kernels 5.8 or newer. (our latest SDV enabled kAFL kernel for TDX is 5.6)

the mainline kAFL already supports kernel 5.10.73, and will soon release a 6.0.0 kernel as well.

Can we enable ztsd support in it?

It will be enabled by default, as long as you use a 5.8+ kernel

image

We can of course document this. And to fix this issue permanently, we have to upgrade our SDV enabled kernel to 5.10.73, or even 6.0.0 https://github.com/intel/ccc-linux-guest-hardening/blob/master/deploy/roles/bkc/meta/main.yml#L10

il-steffen commented 1 year ago

This is what Daniel + Pawan were working on, to lift the "SDV" host kernel to 6.x.

tz0 commented 1 year ago

So the steps to fix this (minimal set):

  1. Edit /etc/initramfs-tools/initramfs.conf to change the algorithm from zstd to lz4
  2. Rebuild the initramfs as 'sudo update-initramfs -c -k all'
  3. Reboot

Nothing else is needed, you should be able to boot to the kafl kernel sucessfully.

@tz0 could you please make a quick PR with the above instructions for workarounds to the docs? I have verified that the previous sequence works on my ubuntu 22 LTS

Yes. Updated the README.md for the above. PR#94

ereshetova commented 1 year ago

I merged the above PR. Now can close the issue.