pcrlock: add --strict option
Add a --strict option that makes sure all PCRs for which components were found are indeed included in the set of predicted PCRs. Instead throw an error. Avoids creating a policy less secure than requested. Co-authored-by: Akarithos <277667353+Akarithos@users.noreply.github.com>
This commit is contained in:
committed by
Akarithos
co-authored by
Akarithos
parent
dcde7c750d
commit
d1cec47900
@@ -601,6 +601,15 @@
|
|||||||
<xi:include href="version-info.xml" xpointer="v258"/></listitem>
|
<xi:include href="version-info.xml" xpointer="v258"/></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--strict=</option></term>
|
||||||
|
|
||||||
|
<listitem><para>Takes a boolean. Defaults to false. Honoured by <command>make-policy</command> and <command>predict</command>. If
|
||||||
|
true all specified PCRs must be included in the policy otherwise the command returns failure.</para>
|
||||||
|
|
||||||
|
<xi:include href="version-info.xml" xpointer="v262"/></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<xi:include href="standard-options.xml" xpointer="json" />
|
<xi:include href="standard-options.xml" xpointer="json" />
|
||||||
<xi:include href="standard-options.xml" xpointer="no-pager" />
|
<xi:include href="standard-options.xml" xpointer="no-pager" />
|
||||||
<xi:include href="standard-options.xml" xpointer="help" />
|
<xi:include href="standard-options.xml" xpointer="help" />
|
||||||
|
|||||||
+14
-2
@@ -91,6 +91,7 @@ static RecoveryPinMode arg_recovery_pin = RECOVERY_PIN_HIDE;
|
|||||||
static char *arg_policy_path = NULL;
|
static char *arg_policy_path = NULL;
|
||||||
static bool arg_force = false;
|
static bool arg_force = false;
|
||||||
static BootEntryTokenType arg_entry_token_type = BOOT_ENTRY_TOKEN_AUTO;
|
static BootEntryTokenType arg_entry_token_type = BOOT_ENTRY_TOKEN_AUTO;
|
||||||
|
static bool arg_strict = false;
|
||||||
static char *arg_entry_token = NULL;
|
static char *arg_entry_token = NULL;
|
||||||
static bool arg_varlink = false;
|
static bool arg_varlink = false;
|
||||||
static bool arg_quiet = false;
|
static bool arg_quiet = false;
|
||||||
@@ -3068,6 +3069,7 @@ static int unlink_pcrlock(const char *default_pcrlock_path) {
|
|||||||
|
|
||||||
static int event_log_reduce_to_safe_pcrs(EventLog *el, uint32_t *pcrs) {
|
static int event_log_reduce_to_safe_pcrs(EventLog *el, uint32_t *pcrs) {
|
||||||
_cleanup_free_ char *dropped = NULL, *kept = NULL;
|
_cleanup_free_ char *dropped = NULL, *kept = NULL;
|
||||||
|
bool dropped_relevant_pcr = false;
|
||||||
|
|
||||||
assert(el);
|
assert(el);
|
||||||
assert(pcrs);
|
assert(pcrs);
|
||||||
@@ -3110,6 +3112,9 @@ static int event_log_reduce_to_safe_pcrs(EventLog *el, uint32_t *pcrs) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
drop:
|
drop:
|
||||||
|
if (arg_strict)
|
||||||
|
dropped_relevant_pcr = true;
|
||||||
|
|
||||||
*pcrs &= ~(UINT32_C(1) << pcr);
|
*pcrs &= ~(UINT32_C(1) << pcr);
|
||||||
|
|
||||||
if (strextendf_with_separator(&dropped, ", ", "%" PRIu32 " (%s)", pcr, tpm2_pcr_index_to_string(pcr)) < 0)
|
if (strextendf_with_separator(&dropped, ", ", "%" PRIu32 " (%s)", pcr, tpm2_pcr_index_to_string(pcr)) < 0)
|
||||||
@@ -3117,7 +3122,7 @@ static int event_log_reduce_to_safe_pcrs(EventLog *el, uint32_t *pcrs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dropped)
|
if (dropped)
|
||||||
log_notice("PCRs dropped from protection mask: %s", dropped);
|
log_full(dropped_relevant_pcr ? LOG_ERR : LOG_NOTICE, "PCRs dropped from protection mask: %s", dropped);
|
||||||
else
|
else
|
||||||
log_debug("No PCRs dropped from protection mask.");
|
log_debug("No PCRs dropped from protection mask.");
|
||||||
|
|
||||||
@@ -3126,7 +3131,7 @@ static int event_log_reduce_to_safe_pcrs(EventLog *el, uint32_t *pcrs) {
|
|||||||
else
|
else
|
||||||
log_notice("No PCRs kept in protection mask.");
|
log_notice("No PCRs kept in protection mask.");
|
||||||
|
|
||||||
return 0;
|
return dropped_relevant_pcr ? -ENOEXEC : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pcr_prediction_add_result(
|
static int pcr_prediction_add_result(
|
||||||
@@ -5503,6 +5508,13 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
|
|||||||
return r;
|
return r;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
OPTION_LONG("strict", "BOOL",
|
||||||
|
"Require all PCRs configured via --pcr= included in policy"):
|
||||||
|
r = parse_boolean_argument("--strict", opts.arg, &arg_strict);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
break;
|
||||||
|
|
||||||
OPTION('q', "quiet", NULL, "Suppress unnecessary output"):
|
OPTION('q', "quiet", NULL, "Suppress unnecessary output"):
|
||||||
arg_quiet = true;
|
arg_quiet = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user