Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor composefs warnings #2994

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 27 additions & 35 deletions src/switchroot/ostree-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ validate_signature (GBytes *data, GVariant *signatures, GPtrArray *pubkeys)

return FALSE;
}

// Output a friendly message based on an errno for common cases
static const char *
composefs_error_message (int errsv)
{
switch (errsv)
{
case ENOVERITY:
return "fsverity not enabled on composefs image";
case EWRONGVERITY:
return "Wrong fsverity digest in composefs image";
case ENOSIGNATURE:
return "Missing signature for fsverity in composefs image";
default:
return strerror (errsv);
}
}

#endif

typedef struct
Expand Down Expand Up @@ -436,6 +454,11 @@ main (int argc, char *argv[])
1,
};

cfs_options.flags = LCFS_MOUNT_FLAGS_READONLY;
cfs_options.image_mountdir = OSTREE_COMPOSEFS_LOWERMNT;
if (mkdirat (AT_FDCWD, OSTREE_COMPOSEFS_LOWERMNT, 0700) < 0)
err (EXIT_FAILURE, "Failed to create %s", OSTREE_COMPOSEFS_LOWERMNT);

g_autofree char *expected_digest = NULL;

if (composefs_config->is_signed)
Expand Down Expand Up @@ -474,27 +497,11 @@ main (int argc, char *argv[])

expected_digest = g_malloc (OSTREE_SHA256_STRING_LEN + 1);
ot_bin2hex (expected_digest, cfs_digest_buf, g_variant_get_size (cfs_digest_v));
}

cfs_options.flags = LCFS_MOUNT_FLAGS_READONLY;
cfs_options.image_mountdir = OSTREE_COMPOSEFS_LOWERMNT;
if (mkdirat (AT_FDCWD, OSTREE_COMPOSEFS_LOWERMNT, 0700) < 0)
err (EXIT_FAILURE, "Failed to create %s", OSTREE_COMPOSEFS_LOWERMNT);

if (expected_digest != NULL)
{
cfs_options.flags |= LCFS_MOUNT_FLAGS_REQUIRE_VERITY;
g_print ("composefs: Verifying digest: %s\n", expected_digest);
cfs_options.expected_fsverity_digest = expected_digest;
}
else
{
// If we're not verifying a digest, then we *must* also have signatures disabled.
// Or stated in reverse: if signature verification is enabled, then digest verification
// must also be.
g_assert (!composefs_config->is_signed);
g_print ("composefs: Mounting with no digest or signature check\n");
}

if (lcfs_mount_image (OSTREE_COMPOSEFS_NAME, TMP_SYSROOT, &cfs_options) == 0)
{
Expand All @@ -506,29 +513,14 @@ main (int argc, char *argv[])
else
{
int errsv = errno;
const char *errmsg;
switch (errsv)
{
case ENOVERITY:
errmsg = "fsverity not enabled on composefs image";
break;
case EWRONGVERITY:
errmsg = "Wrong fsverity digest in composefs image";
break;
case ENOSIGNATURE:
errmsg = "Missing signature for fsverity in composefs image";
break;
default:
errmsg = strerror (errno);
break;
}
if (composefs_config->enabled == OT_TRISTATE_MAYBE)
g_assert (composefs_config->enabled != OT_TRISTATE_NO);
if (composefs_config->enabled == OT_TRISTATE_MAYBE && errsv == ENOENT)
ericcurtin marked this conversation as resolved.
Show resolved Hide resolved
{
g_print ("composefs: optional support failed: %s\n", errmsg);
g_print ("composefs: No image present\n");
}
else
{
g_assert (composefs_config->enabled == OT_TRISTATE_YES);
const char *errmsg = composefs_error_message (errsv);
errx (EXIT_FAILURE, "composefs: failed to mount: %s", errmsg);
}
}
Expand Down
Loading