fsverity: Support passing a signature when enabling fs-verity
authorAlexander Larsson <alexl@redhat.com>
Tue, 16 May 2023 14:31:34 +0000 (16:31 +0200)
committerAlexander Larsson <alexl@redhat.com>
Wed, 31 May 2023 08:55:14 +0000 (10:55 +0200)
The composefs code will need this.

src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo-private.h
src/libostree/ostree-repo-verity.c
src/libostree/ostree-sysroot-deploy.c

index 5cda047c6be38e9ae43bc17d288f529fd881f118..0900205fee924e8d41edc35b139234f77010b1f4 100644 (file)
@@ -184,7 +184,7 @@ _ostree_repo_commit_tmpf_final (OstreeRepo *self, const char *checksum, OstreeOb
   if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, tmpbuf, cancellable, error))
     return FALSE;
 
-  if (!_ostree_tmpf_fsverity (self, tmpf, error))
+  if (!_ostree_tmpf_fsverity (self, tmpf, NULL, error))
     return FALSE;
 
   if (!glnx_link_tmpfile_at (tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST, dest_dfd, tmpbuf,
index 5395de40f4b3cfeb0ee89d9de0d6512d6aed7a3f..98719f5a67d34164047335444c102806620ccd99 100644 (file)
@@ -390,9 +390,10 @@ gboolean _ostree_repo_maybe_regenerate_summary (OstreeRepo *self, GCancellable *
 gboolean _ostree_repo_parse_fsverity_config (OstreeRepo *self, GError **error);
 
 gboolean _ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, _OstreeFeatureSupport fsverity_requested,
-                                     gboolean *supported, GError **error);
+                                     GBytes *signature, gboolean *supported, GError **error);
 
-gboolean _ostree_tmpf_fsverity (OstreeRepo *self, GLnxTmpfile *tmpf, GError **error);
+gboolean _ostree_tmpf_fsverity (OstreeRepo *self, GLnxTmpfile *tmpf, GBytes *signature,
+                                GError **error);
 gboolean _ostree_fsverity_sign (const char *certfile, const char *keyfile,
                                 const guchar *fsverity_digest, GBytes **data_out,
                                 GCancellable *cancellable, GError **error);
index fcbdaccd9c1bef210761f4d3f70fbcfca3276276..5b2a621a7d06216145ab8b4790396693652e21e1 100644 (file)
@@ -82,7 +82,7 @@ _ostree_repo_parse_fsverity_config (OstreeRepo *self, GError **error)
  * */
 gboolean
 _ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, _OstreeFeatureSupport fsverity_requested,
-                            gboolean *supported, GError **error)
+                            GBytes *signature, gboolean *supported, GError **error)
 {
   /* Set this by default to simplify the code below */
   if (supported)
@@ -106,8 +106,8 @@ _ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, _OstreeFeatureSupport fsverity_re
   arg.block_size = 4096;                          /* FIXME query */
   arg.salt_size = 0;                              /* TODO store salt in ostree repo config */
   arg.salt_ptr = 0;
-  arg.sig_size = 0; /* We don't currently expect use of in-kernel signature verification */
-  arg.sig_ptr = 0;
+  arg.sig_size = signature ? g_bytes_get_size (signature) : 0;
+  arg.sig_ptr = signature ? (guint64)g_bytes_get_data (signature, NULL) : 0;
 
   if (ioctl (tmpf->fd, FS_IOC_ENABLE_VERITY, &arg) < 0)
     {
@@ -133,7 +133,7 @@ _ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, _OstreeFeatureSupport fsverity_re
  * as well as to support "opportunistic" use (requested and if filesystem supports).
  * */
 gboolean
-_ostree_tmpf_fsverity (OstreeRepo *self, GLnxTmpfile *tmpf, GError **error)
+_ostree_tmpf_fsverity (OstreeRepo *self, GLnxTmpfile *tmpf, GBytes *signature, GError **error)
 {
 #ifdef HAVE_LINUX_FSVERITY_H
   g_mutex_lock (&self->txn_lock);
@@ -156,7 +156,7 @@ _ostree_tmpf_fsverity (OstreeRepo *self, GLnxTmpfile *tmpf, GError **error)
     }
 
   gboolean supported = FALSE;
-  if (!_ostree_tmpf_fsverity_core (tmpf, fsverity_wanted, &supported, error))
+  if (!_ostree_tmpf_fsverity_core (tmpf, fsverity_wanted, signature, &supported, error))
     return FALSE;
 
   if (!supported)
index 425abe8bd62dab5ad077d54856a2d866d7d1612f..32bbd3358e8648879ddf49ee0f23719a27b3f9ef 100644 (file)
@@ -163,7 +163,7 @@ install_into_boot (OstreeRepo *repo, OstreeSePolicy *sepolicy, int src_dfd, cons
   _OstreeFeatureSupport boot_verity = _OSTREE_FEATURE_NO;
   if (repo->fs_verity_wanted != _OSTREE_FEATURE_NO)
     boot_verity = _OSTREE_FEATURE_MAYBE;
-  if (!_ostree_tmpf_fsverity_core (&tmp_dest, boot_verity, NULL, error))
+  if (!_ostree_tmpf_fsverity_core (&tmp_dest, boot_verity, NULL, NULL, error))
     return FALSE;
 
   if (!glnx_link_tmpfile_at (&tmp_dest, GLNX_LINK_TMPFILE_NOREPLACE, dest_dfd, dest_subpath, error))