|
| 1 | +%global debug_package %{nil} |
| 2 | +%global sha512hmac bash %{_sourcedir}/sha512hmac-openssl.sh |
| 3 | +%ifarch x86_64 |
| 4 | +%global buildarch x86_64 |
| 5 | +%endif |
| 6 | +%define uname_r %{version}-%{release} |
| 7 | +Summary: Signed MSHV-enabled Linux Kernel for %{buildarch} systems |
| 8 | +Name: kernel-mshv-signed-%{buildarch} |
| 9 | +Version: 5.15.157.mshv1 |
| 10 | +Release: 3%{?dist} |
| 11 | +License: GPLv2 |
| 12 | +Vendor: Microsoft Corporation |
| 13 | +Distribution: Azure Linux |
| 14 | +Group: System Environment/Kernel |
| 15 | +URL: https://github.com/microsoft/CBL-Mariner-Linux-Kernel |
| 16 | +# This spec purpose is to take an input kernel rpm and input secure-boot-signed |
| 17 | +# kernel binary from the same build and generate a new "kernel" rpm with the |
| 18 | +# signed kernel binary + all of the other original kernel files, triggers, |
| 19 | +# scriptlets, requires, provides, etc. |
| 20 | +# |
| 21 | +# We need to ensure the kernel modules and kernel binary used are from the exact |
| 22 | +# same build because at build time the kernel modules are signed with an |
| 23 | +# ephemeral key that the kernel enrolls in its keyring. We enforce kernel |
| 24 | +# module signature checking when we enable security features like kernel |
| 25 | +# lockdown so our kernel can only load those specific kernel modules at runtime. |
| 26 | +# |
| 27 | +# Additionally, to complete the UEFI Secure Boot chain, we must PE-sign the |
| 28 | +# kernel binary. Ideally we would enable secure-boot signing tools like pesign |
| 29 | +# or sbsign to be callable from inside the rpmbuild environment, that way we can |
| 30 | +# secure-boot sign the kernel binary during the kernel's rpmbuild. It is best |
| 31 | +# practice to sign as soon as possible. However there are issues getting that |
| 32 | +# secure boot signing infrastructure in place today. Hence we sign the |
| 33 | +# resulting kernel binary and "repackage" the kernel RPM (something rpm itself |
| 34 | +# actively tries to make sure you never do...generally for good reasons). |
| 35 | +# |
| 36 | +# To achive this repackaging, this spec creates a new subpackage named |
| 37 | +# "kernel-mshv". To retain all of the initial kernel-mshv package behaviors, we make sure |
| 38 | +# the subpackage has the same requires, provides, triggers, post steps, and |
| 39 | +# files as the original kernel package. |
| 40 | +# |
| 41 | +# This specific repackaging implementation leaves room for us to enable the |
| 42 | +# more ideal secure-boot signing flow in the future without introducing any |
| 43 | +# sort of breaking change or new packaging. Users still install a "kernel-mshv" |
| 44 | +# package like they normally would. |
| 45 | +# |
| 46 | +# Maintenance Notes: |
| 47 | +# - This spec's "version" and "release" must reflect the unsigned version that |
| 48 | +# was signed. An important consequence is that when making a change to this |
| 49 | +# spec or the normal kernel spec, the other spec's version version/release must |
| 50 | +# be increased to keep the two versions consistent. |
| 51 | +# |
| 52 | +# - Make sure the kernel subpackage's Requires, Provides, triggers, post/postun |
| 53 | +# scriptlets, and files match the normal kernel-mshv spec's. The kernel subpackage |
| 54 | +# should contain the same content as the input kernel package but replace the |
| 55 | +# kernel binary with our signed kernel binary. Since all the requires, provides, |
| 56 | +# etc are the same, this new kernel package can be a direct replacement for the |
| 57 | +# normal kernel package and RPM will resolve packages with kernel dependencies |
| 58 | +# correctly. |
| 59 | +# |
| 60 | +# To populate the input sources: |
| 61 | +# 1. Build the unsigned packages as normal |
| 62 | +# 2. Sign the desired binary |
| 63 | +# 3. Place the unsigned package and signed binary in this spec's folder |
| 64 | +# 4. Build this spec |
| 65 | +Source0: kernel-mshv-%{version}-%{release}.%{buildarch}.rpm |
| 66 | +Source1: vmlinuz-%{uname_r} |
| 67 | +BuildRequires: cpio |
| 68 | +BuildRequires: openssl |
| 69 | +BuildRequires: sed |
| 70 | + |
| 71 | +%description |
| 72 | +This package contains the MSHV-enabled Linux kernel package with kernel-mshv signed with the production key |
| 73 | + |
| 74 | +%package -n kernel-mshv |
| 75 | +Summary: MSHV-enabled Linux Kernel |
| 76 | +Group: System Environment/Kernel |
| 77 | +Requires: filesystem |
| 78 | +Requires: kmod |
| 79 | +Requires(post): coreutils |
| 80 | +Requires(postun): coreutils |
| 81 | +%{?grub2_configuration_requires} |
| 82 | +ExclusiveArch: x86_64 |
| 83 | + |
| 84 | +%description -n kernel-mshv |
| 85 | +The kernel package contains the signed MSHV-enabled Linux kernel. |
| 86 | + |
| 87 | +%prep |
| 88 | + |
| 89 | +%build |
| 90 | +mkdir rpm_contents |
| 91 | +pushd rpm_contents |
| 92 | + |
| 93 | +# This spec's whole purpose is to inject the signed kernel binary |
| 94 | +rpm2cpio %{SOURCE0} | cpio -idmv |
| 95 | +cp %{SOURCE1} ./boot/vmlinuz-%{uname_r} |
| 96 | + |
| 97 | +popd |
| 98 | + |
| 99 | +%install |
| 100 | +pushd rpm_contents |
| 101 | + |
| 102 | +# Don't use * wildcard. It does not copy over hidden files in the root folder... |
| 103 | +cp -rp ./. %{buildroot}/ |
| 104 | + |
| 105 | +popd |
| 106 | + |
| 107 | +%triggerin -n kernel-mshv -- initramfs |
| 108 | +mkdir -p %{_localstatedir}/lib/rpm-state/initramfs/pending |
| 109 | +touch %{_localstatedir}/lib/rpm-state/initramfs/pending/%{uname_r} |
| 110 | +echo "initrd generation of kernel %{uname_r} will be triggered later" >&2 |
| 111 | + |
| 112 | +%triggerun -n kernel-mshv -- initramfs |
| 113 | +rm -rf %{_localstatedir}/lib/rpm-state/initramfs/pending/%{uname_r} |
| 114 | +rm -rf /boot/efi/initrd.img-%{uname_r} |
| 115 | +echo "initrd of kernel %{uname_r} removed" >&2 |
| 116 | + |
| 117 | +%postun -n kernel-mshv |
| 118 | +%grub2_postun |
| 119 | + |
| 120 | +%post -n kernel-mshv |
| 121 | +/sbin/depmod -a %{uname_r} |
| 122 | +%grub2_post |
| 123 | + |
| 124 | +%files -n kernel-mshv |
| 125 | +%defattr(-,root,root) |
| 126 | +%license COPYING |
| 127 | +%exclude %dir /usr/lib/debug |
| 128 | +/boot/System.map-%{uname_r} |
| 129 | +/boot/config-%{uname_r} |
| 130 | +/boot/vmlinuz-%{uname_r} |
| 131 | +/boot/efi/vmlinuz-%{uname_r} |
| 132 | +%config(noreplace) %{_sysconfdir}/default/grub.d/50_mariner_mshv.cfg |
| 133 | +%config %{_sysconfdir}/grub.d/50_mariner_mshv_menuentry |
| 134 | +%defattr(0644,root,root) |
| 135 | +/lib/modules/%{uname_r}/* |
| 136 | +%exclude /lib/modules/%{uname_r}/build |
| 137 | + |
| 138 | +%changelog |
| 139 | +* Fri Jan 24 2025 Cameron Baird <cameronbaird@microsoft.com> - 5.15.157.mshv1-3 |
| 140 | +- Original version for Azure Linux. |
| 141 | +- license: MIT |
| 142 | +- License verified |
0 commit comments