for more information.</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--cvm</option></term>
+
+ <listitem><para>Detect whether invoked in a confidential virtual machine.
+ The result of this detection may be used to disable features that should
+ not be used in confidential VMs. It must not be used to release security
+ sensitive information. The latter must only be released after attestation
+ of the confidential environment.</para></listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-q</option></term>
<term><option>--quiet</option></term>
#include "alloc-util.h"
#include "build.h"
+#include "confidential-virt.h"
#include "main-func.h"
#include "pretty-print.h"
#include "string-table.h"
ONLY_CONTAINER,
ONLY_CHROOT,
ONLY_PRIVATE_USERS,
+ ONLY_CVM,
} arg_mode = ANY_VIRTUALIZATION;
static int help(void) {
" -v --vm Only detect whether we are run in a VM\n"
" -r --chroot Detect whether we are run in a chroot() environment\n"
" --private-users Only detect whether we are running in a user namespace\n"
+ " --cvm Only detect whether we are run in a confidential VM\n"
" -q --quiet Don't output anything, just set return value\n"
" --list List all known and detectable types of virtualization\n"
"\nSee the %s for details.\n",
ARG_VERSION = 0x100,
ARG_PRIVATE_USERS,
ARG_LIST,
+ ARG_CVM,
};
static const struct option options[] = {
{ "chroot", no_argument, NULL, 'r' },
{ "private-users", no_argument, NULL, ARG_PRIVATE_USERS },
{ "quiet", no_argument, NULL, 'q' },
+ { "cvm", no_argument, NULL, ARG_CVM },
{ "list", no_argument, NULL, ARG_LIST },
{}
};
DUMP_STRING_TABLE(virtualization, Virtualization, _VIRTUALIZATION_MAX);
return 0;
+ case ARG_CVM:
+ arg_mode = ONLY_CVM;
+ return 1;
+
case '?':
return -EINVAL;
static int run(int argc, char *argv[]) {
Virtualization v;
+ ConfidentialVirtualization c;
int r;
/* This is mostly intended to be used for scripts which want
return log_error_errno(r, "Failed to check for user namespace: %m");
return !r;
+ case ONLY_CVM:
+ c = detect_confidential_virtualization();
+ if (c < 0)
+ return log_error_errno(c, "Failed to check for confidential virtualization: %m");
+ if (!arg_quiet)
+ puts(confidential_virtualization_to_string(c));
+ return c == CONFIDENTIAL_VIRTUALIZATION_NONE;
+
case ANY_VIRTUALIZATION:
default:
v = detect_virtualization();