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

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