Blame SOURCES/0002-libpriv-kernel-Hack-around-vmlinuz-path-in-HMAC-file.patch

3e75cf
From fec61ce5778910bac7779191ee8deeb0a24593c8 Mon Sep 17 00:00:00 2001
3e75cf
From: Jonathan Lebon <jonathan@jlebon.com>
3e75cf
Date: Tue, 29 Oct 2019 16:40:39 -0400
3e75cf
Subject: [PATCH 2/2] libpriv/kernel: Hack around vmlinuz path in HMAC file
3e75cf
3e75cf
As mentioned in the comment block:
3e75cf
3e75cf
```
3e75cf
If there's an HMAC file, fix the path to the kernel in it to be
3e75cf
relative. Right now, the kernel spec encodes `/boot/vmlinux-$kver`,
3e75cf
which of course not going to work for us. We should work towards making
3e75cf
this change directly into the kernel spec.
3e75cf
```
3e75cf
3e75cf
For background, see this comment and following:
3e75cf
https://github.com/ostreedev/ostree/pull/1962#issuecomment-547488164
3e75cf
---
3e75cf
 src/libpriv/rpmostree-kernel.c | 32 ++++++++++++++++++++++++++++++++
3e75cf
 1 file changed, 32 insertions(+)
3e75cf
3e75cf
diff --git a/src/libpriv/rpmostree-kernel.c b/src/libpriv/rpmostree-kernel.c
3e75cf
index 2266f9c7..2bea504c 100644
3e75cf
--- a/src/libpriv/rpmostree-kernel.c
3e75cf
+++ b/src/libpriv/rpmostree-kernel.c
3e75cf
@@ -393,6 +393,38 @@ rpmostree_finalize_kernel (int rootfs_dfd,
3e75cf
         return glnx_throw_errno_prefix (error, "linkat(%s)", kernel_modules_path);
3e75cf
     }
3e75cf
 
3e75cf
+  /* If there's an HMAC file, fix the path to the kernel in it to be relative. Right now,
3e75cf
+   * the kernel spec encodes `/boot/vmlinux-$kver`, which of course not going to work for
3e75cf
+   * us. We should work towards making this change directly into the kernel spec. */
3e75cf
+  g_autofree char *hmac_path = g_build_filename (modules_bootdir, ".vmlinuz.hmac", NULL);
3e75cf
+  if (!glnx_fstatat_allow_noent (rootfs_dfd, hmac_path, NULL, 0, error))
3e75cf
+    return FALSE;
3e75cf
+  if (errno == 0)
3e75cf
+    {
3e75cf
+      g_autofree char *contents = glnx_file_get_contents_utf8_at (rootfs_dfd, hmac_path,
3e75cf
+                                                                  NULL, cancellable, error);
3e75cf
+      if (contents == NULL)
3e75cf
+        return FALSE;
3e75cf
+
3e75cf
+      /* rather than trying to parse and understand the *sum format, just hackily replace */
3e75cf
+      g_autofree char *old_path = g_strconcat ("  /boot/vmlinuz-", kver, NULL);
3e75cf
+      g_autofree char *new_path = g_strconcat ("  vmlinuz-", kver, NULL);
3e75cf
+      g_autofree char *new_contents =
3e75cf
+        rpmostree_str_replace (contents, old_path, new_path, error);
3e75cf
+      if (!new_contents)
3e75cf
+        return FALSE;
3e75cf
+
3e75cf
+      /* sanity check there are no '/' in there; that way too we just error out if the path
3e75cf
+       * or format changes (but really, this should be a temporary hack...) */
3e75cf
+      if (strchr (new_contents, '/') != 0)
3e75cf
+        return glnx_throw (error, "Unexpected / in .vmlinuz.hmac: %s", new_contents);
3e75cf
+
3e75cf
+      if (!glnx_file_replace_contents_at (rootfs_dfd, hmac_path,
3e75cf
+                                          (guint8*)new_contents, -1, 0,
3e75cf
+                                          cancellable, error))
3e75cf
+        return FALSE;
3e75cf
+    }
3e75cf
+
3e75cf
   /* Replace the initramfs */
3e75cf
   g_autofree char *initramfs_modules_path = g_build_filename (modules_bootdir, "initramfs.img", NULL);
3e75cf
   if (unlinkat (rootfs_dfd, initramfs_modules_path, 0) < 0)
3e75cf
-- 
3e75cf
2.21.0
3e75cf