'\" t .TH "SYSTEMD\-PCRLOCK" "8" "" "systemd 255" "systemd-pcrlock" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" systemd-pcrlock, systemd-pcrlock-file-system.service, systemd-pcrlock-firmware-code.service, systemd-pcrlock-firmware-config.service, systemd-pcrlock-machine-id.service, systemd-pcrlock-make-policy.service, systemd-pcrlock-secureboot-authority.service, systemd-pcrlock-secureboot-policy.service \- Analyze and predict TPM2 PCR states and generate an access policy from the prediction .SH "SYNOPSIS" .HP \w'\fB/usr/lib/systemd/systemd\-pcrlock\ \fR\fB[OPTIONS...]\fR\ 'u \fB/usr/lib/systemd/systemd\-pcrlock \fR\fB[OPTIONS...]\fR .SH "DESCRIPTION" .PP Note: this command is experimental for now\&. While it is likely to become a regular component of systemd, it might still change in behaviour and interface\&. .PP \fBsystemd\-pcrlock\fR is a tool that may be used to analyze and predict TPM2 PCR measurements, and generate TPM2 access policies from the prediction which it stores in a TPM2 NV index (i\&.e\&. in the TPM2 non\-volatile memory)\&. This may then be used to restrict access to TPM2 objects (such as disk encryption keys) to system boot\-ups in which only specific, trusted components are used\&. .PP \fBsystemd\-pcrlock\fR uses as input for its analysis and prediction: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} The UEFI firmware TPM2 event log (i\&.e\&. /sys/kernel/security/tpm0/binary_bios_measurements) of the current boot\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} The userspace TPM2 event log (i\&.e\&. /run/log/systemd/tpm2\-measure\&.log) of the current boot\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} The current PCR state of the TPM2 chip\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} Boot component definition files (*\&.pcrlock and *\&.pcrlock\&.d/*\&.pcrlock, see \fBsystemd.pcrlock\fR(5)) that each define expected measurements for one component of the boot process, permitting alternative variants for each\&. (Variants may be used used to bless multiple kernel versions or boot loader versions at the same time\&.) .RE .PP It uses these inputs to generate a combined event log, validating it against the PCR states\&. It then attempts to recognize event log records and matches them against the defined components\&. For each PCR where this can be done comprehensively (i\&.e\&. where all listed records and all defined components have been matched) this may then be used to predict future PCR measurements, taking the alternative variants defined for each component into account\&. This prediction may then be converted into a TPM2 access policy (consisting of TPM2 \fBPolicyPCR\fR and \fBPolicyOR\fR items), which is then stored in an NV index in the TPM2\&. This may be used to then lock secrets (such as disk encryption keys) to these policies (via a TPM2 \fBPolicyAuthorizeNV\fR policy)\&. .PP Use tools such as \fBsystemd-cryptenroll\fR(1) or \fBsystemd-repart\fR(8) to bind disk encryption to such a \fBsystemd\-pcrlock\fR TPM2 policy\&. Specifically, see the \fB\-\-tpm2\-pcrlock=\fR switches of these tools\&. .PP The access policy logic requires a TPM2 device that implements the "PolicyAuthorizeNV" command, i\&.e\&. implements TPM 2\&.0 version 1\&.38 or newer\&. .SH "COMMANDS" .PP The following commands are understood: .PP \fBlog\fR .RS 4 This reads the combined TPM2 event log, validates it, matches it against the current PCR values, and outputs both in tabular form\&. Combine with \fB\-\-json=\fR to generate output in JSON format\&. .sp Added in version 255\&. .RE .PP \fBcel\fR .RS 4 This reads the combined TPM2 event log and writes it to STDOUT in \m[blue]\fBTCG Common Event Log Format (CEL\-JSON)\fR\m[]\&\s-2\u[1]\d\s+2 format\&. .sp Added in version 255\&. .RE .PP \fBlist\-components\fR .RS 4 Shows a list of component definitions and their variants, i\&.e\&. the *\&.pcrlock files discovered in /var/lib/pcrlock\&.d/, /usr/lib/pcrlock\&.d/, and the other supported directories\&. See \fBsystemd.pcrlock\fR(5) for details on these files and the full list of directories searched\&. .sp Added in version 255\&. .RE .PP \fBpredict\fR .RS 4 Predicts the PCR state on future boots\&. This will analyze the TPM2 event log as described above, recognize components, and then generate all possible resulting PCR values for all combinations of component variants\&. Note that no prediction is made for PCRs whose value does not match the event log records, for which unrecognized measurements are discovered or for which components are defined that cannot be found in the event log\&. This is a safety measure to ensure that any generated access policy can be fulfilled correctly on current and future boots\&. .sp Added in version 255\&. .RE .PP \fBmake\-policy\fR .RS 4 This predicts the PCR state for future boots, much like the \fBpredict\fR command above\&. It then uses this data to generate a TPM2 access policy which it stores in a TPM2 NV index\&. The prediction and information about the used TPM2 and its NV index are written to /var/lib/systemd/pcrlock\&.json\&. .sp The NV index is allocated on first invocation, and updated on subsequent invocations\&. .sp The NV index contents may be changed (and thus the policy stored in it updated) by providing an access PIN\&. This PIN is normally generated automatically and stored in encrypted form (with an access policy binding it to the NV index itself) in the aforementioned JSON policy file\&. This PIN may be chosen by the user, via the \fB\-\-recovery\-pin=\fR switch\&. If specified it may be used as alternative path of access to update the policy\&. .sp If the new prediction matches the old this command terminates quickly and executes no further operation\&. (Unless \fB\-\-force\fR is specified, see below\&.) .sp Added in version 255\&. .RE .PP \fBremove\-policy\fR .RS 4 Removes a previously generated policy\&. Deletes the /var/lib/systemd/pcrlock\&.json file, and deallocates the NV index\&. .sp Added in version 255\&. .RE .PP \fBlock\-firmware\-code\fR, \fBunlock\-firmware\-code\fR .RS 4 Generates/removes \&.pcrlock files based on the TPM2 event log of the current boot covering all records for PCRs 0 ("platform\-code") and 2 ("external\-code")\&. .sp This operation allows locking the boot process to the current version of the firmware of the system and its extension cards\&. This operation should only be used if the system vendor does not provide suitable pcrlock data ahead of time\&. .sp Note that this data only matches the current version of the firmware\&. If a firmware update is applied this data will be out\-of\-date and any access policy generated from it will no longer pass\&. It is thus recommended to invoke \fBunlock\-firmware\-code\fR before doing a firmware update, followed by \fBmake\-policy\fR to refresh the policy\&. .sp \fBsystemd\-pcrlock lock\-firmware\-code\fR is invoked automatically at boot via the systemd\-pcrlock\-firmware\-code\&.service unit, if enabled\&. This ensures that an access policy managed by \fBsystemd\-pcrlock\fR is automatically locked to the new firmware version whenever the policy has been relaxed temporarily, in order to cover for firmware updates, as described above\&. .sp The files are only generated from the event log if the event log matches the current TPM2 PCR state\&. .sp This writes/removes the files /var/lib/pcrlock\&.d/250\-firmware\-code\-early\&.pcrlock\&.d/generated\&.pcrlock and /var/lib/pcrlock\&.d/550\-firmware\-code\-late\&.pcrlock\&.d/generated\&.pcrlock\&. .sp Added in version 255\&. .RE .PP \fBlock\-firmware\-config\fR, \fBunlock\-firmware\-config\fR .RS 4 This is similar to \fBlock\-firmware\-code\fR/\fBunlock\-firmware\-code\fR but locks down the firmware configuration, i\&.e\&. PCRs 1 ("platform\-config") and 3 ("external\-config")\&. .sp This functionality should be used with care as in most scenarios a minor firmware configuration change should not invalidate access policies to TPM2 objects\&. Also note that some systems measure unstable and unpredictable information (e\&.g\&. current CPU voltages, temperatures, as part of SMBIOS data) to these PCRs, which means this form of lockdown cannot be used reliably on such systems\&. Use this functionality only if the system and hardware is well known and does not suffer by these limitations, for example in virtualized environments\&. .sp Use \fBunlock\-firmware\-config\fR before making firmware configuration changes\&. If the systemd\-pcrlock\-firmware\-config\&.service unit is enabled it will automatically generate a pcrlock file from the new measurements\&. .sp This writes/removes the files /var/lib/pcrlock\&.d/250\-firmware\-config\-early\&.pcrlock\&.d/generated\&.pcrlock and /var/lib/pcrlock\&.d/550\-firmware\-config\-late\&.pcrlock\&.d/generated\&.pcrlock\&. .sp Added in version 255\&. .RE .PP \fBlock\-secureboot\-policy\fR, \fBunlock\-secureboot\-policy\fR .RS 4 Generates/removes a \&.pcrlock file based on the SecureBoot policy currently enforced\&. This looks at the SecureBoot, PK, KEK, db, dbx, dbt, dbr EFI variables and predicts their measurements to PCR 7 ("secure\-boot\-policy") on the next boot\&. .sp Use \fBunlock\-firmware\-config\fR before applying SecureBoot policy updates\&. If the systemd\-pcrlock\-secureboot\-policy\&.service unit is enabled it will automatically generate a pcrlock file from the policy discovered\&. .sp This writes/removes the file /var/lib/pcrlock\&.d/230\-secureboot\-policy\&.pcrlock\&.d/generated\&.pcrlock\&. .sp Added in version 255\&. .RE .PP \fBlock\-secureboot\-authority\fR, \fBunlock\-secureboot\-authority\fR .RS 4 Generates/removes a \&.pcrlock file based on the SecureBoot authorities used to validate the boot path\&. SecureBoot authorities are the specific SecureBoot database entries that where used to validate the UEFI PE binaries executed at boot\&. This looks at the event log of the current boot, and uses relevant measurements on PCR 7 ("secure\-boot\-policy")\&. .sp This writes/removes the file /var/lib/pcrlock\&.d/620\-secureboot\-authority\&.pcrlock\&.d/generated\&.pcrlock\&. .sp Added in version 255\&. .RE .PP \fBlock\-gpt\fR [\fIDEVICE\fR], \fBunlock\-gpt\fR .RS 4 Generates/removes a \&.pcrlock file based on the GPT partition table of the specified disk\&. If no disk is specified automatically determines the block device backing the root file system\&. This locks the state of the disk partitioning of the booted medium, which firmware measures to PCR 5 ("boot\-loader\-config")\&. .sp This writes/removes the file /var/lib/pcrlock\&.d/600\-gpt\&.pcrlock\&.d/generated\&.pcrlock\&. .sp Added in version 255\&. .RE .PP \fBlock\-pe\fR [\fIBINARY\fR], \fBunlock\-pe\fR .RS 4 Generates/removes a \&.pcrlock file based on the specified PE binary\&. This is useful for predicting measurements the firmware makes to PCR 4 ("boot\-loader\-code") if the specified binary is part of the UEFI boot process\&. Use this on boot loader binaries and suchlike\&. Use \fBlock\-uki\fR (see below) for PE binaries that are unified kernel images (UKIs)\&. .sp Expects a path to the PE binary as argument\&. If not specified, reads the binary from STDIN instead\&. .sp The pcrlock file to write must be specified via the \fB\-\-pcrlock=\fR switch\&. .sp Added in version 255\&. .RE .PP \fBlock\-uki\fR [\fIUKI\fR], \fBunlock\-uki\fR .RS 4 Generates/removes a \&.pcrlock file based on the specified UKI PE binary\&. This is useful for predicting measurements the firmware makes to PCR 4 ("boot\-loader\-code"), and \fBsystemd-stub\fR(7) makes to PCR 11 ("kernel\-boot"), if the specified UKI is booted\&. This is a superset of \fBlock\-pe\fR\&. .sp Expects a path to the UKI PE binary as argument\&. If not specified, reads the binary from STDIN instead\&. .sp The pcrlock file to write must be specified via the \fB\-\-pcrlock=\fR switch\&. .sp Added in version 255\&. .RE .PP \fBlock\-machine\-id\fR, \fBunlock\-machine\-id\fR .RS 4 Generates/removes a \&.pcrlock file based on /etc/machine\-id\&. This is useful for predicting measurements \fBsystemd-pcrmachine.service\fR(8) makes to PCR 15 ("system\-identity")\&. .sp This writes/removes the file /var/lib/pcrlock\&.d/820\-machine\-id\&.pcrlock\&. .sp Added in version 255\&. .RE .PP \fBlock\-file\-system\fR [\fIPATH\fR], \fBunlock\-file\-system\fR [\fIPATH\fR] .RS 4 Generates/removes a \&.pcrlock file based on file system identity\&. This is useful for predicting measurements \fBsystemd-pcrfs@.service\fR(8) makes to PCR 15 ("system\-identity") for the root and /var/ file systems\&. .sp This writes/removes the files /var/lib/pcrlock\&.d/830\-root\-file\-system\&.pcrlock and /var/lib/pcrlock\&.d/840\-file\-system\-\fIpath\fR\&.pcrlock\&. .sp Added in version 255\&. .RE .PP \fBlock\-kernel\-cmdline\fR [\fIFILE\fR], \fBunlock\-kernel\-cmdline\fR .RS 4 Generates/removes a \&.pcrlock file based on /proc/cmdline (or the specified file if given)\&. This is useful for predicting measurements the Linux kernel makes to PCR 9 ("kernel\-initrd")\&. .sp This writes/removes the file /var/lib/pcrlock\&.d/710\-kernel\-cmdline\&.pcrlock/generated\&.pcrlock\&. .sp Added in version 255\&. .RE .PP \fBlock\-kernel\-initrd\fR \fIFILE\fR, \fBunlock\-kernel\-initrd\fR .RS 4 Generates/removes a \&.pcrlock file based on a kernel initrd cpio archive\&. This is useful for predicting measurements the Linux kernel makes to PCR 9 ("kernel\-initrd")\&. Do not use for \fBsystemd\-stub\fR UKIs, as the initrd is combined dynamically from various sources and hence does not take a single input, like this command\&. .sp This writes/removes the file /var/lib/pcrlock\&.d/720\-kernel\-initrd\&.pcrlock/generated\&.pcrlock\&. .sp Added in version 255\&. .RE .PP \fBlock\-raw\fR [\fIFILE\fR], \fBunlock\-raw\fR .RS 4 Generates/removes a \&.pcrlock file based on raw binary data\&. The data is either read from the specified file or from STDIN (if none is specified)\&. This requires that \fB\-\-pcrs=\fR is specified\&. The generated pcrlock file is written to the file specified via \fB\-\-pcrlock=\fR or to STDOUT (if none is specified)\&. .sp Added in version 255\&. .RE .SH "OPTIONS" .PP The following options are understood: .PP \fB\-\-raw\-description\fR .RS 4 When displaying the TPM2 event log do not attempt to decode the records to provide a friendly event log description string\&. Instead, show the binary payload data in escaped form\&. .sp Added in version 255\&. .RE .PP \fB\-\-pcr=\fR .RS 4 Specifies the PCR number to use\&. May be specified more than once to select multiple PCRs\&. .sp This is used by \fBlock\-raw\fR and \fBlock\-pe\fR to select the PCR to lock against\&. .sp If used with \fBpredict\fR and \fBmake\-policy\fR this will override which PCRs to include in the prediction and policy\&. If unspecified this defaults to PCRs 0\-5, 7, 11\-15\&. Note that these commands will not include any PCRs in the prediction/policy (even if specified explicitly) if there are measurements in the event log that do not match the current PCR value, or there are unrecognized measurements in the event log, or components define measurements not seen in the event log\&. .sp Added in version 255\&. .RE .PP \fB\-\-nv\-index=\fR .RS 4 Specifies to NV index to store the policy in\&. Honoured by \fBmake\-policy\fR\&. If not specified the command will automatically pick a free NV index\&. .sp Added in version 255\&. .RE .PP \fB\-\-components=\fR .RS 4 Takes a path to read *\&.pcrlock and *\&.pcrlock\&.d/*\&.pcrlock files from\&. May be used more than once to specify multiple such directories\&. If not specified defaults to /etc/pcrlock\&.d/, /run/pcrlock\&.d/, /var/lib/pcrlock\&.d/, /usr/local/pcrlock\&.d/, /usr/lib/pcrlock\&.d/\&. .sp Added in version 255\&. .RE .PP \fB\-\-location=\fR .RS 4 Takes either a string or a colon\-separated pair of strings\&. Configures up to which point in the sorted list of defined components to analyze/predict PCRs to\&. Typically, the \fBsystemd\-pcrlock\fR tool is invoked from a fully booted system after boot\-up and before shutdown\&. This means various components that are defined for shutdown have not been measured yet, and should not be searched for\&. This option allows one to restrict which components are considered for analysis (taking only components before some point into account, ignoring components after them)\&. The expected string is ordered against the filenames of the components defined\&. Any components with a lexicographically later name are ignored\&. This logic applies to the \fBlog\fR, \fBpredict\fR, and \fBmake\-policy\fR verbs\&. If a colon\-separated pair of strings are specified then they select which phases of the boot to include in the prediction/policy\&. The first string defines where the first prediction shall be made, and the second string defines where the last prediction shall be made\&. All such predictions are then combined into one set\&. .sp If used with \fBlist\-components\fR the selected location range will be highlighted in the component list\&. .sp Defaults to "760\-:940\-", which means the policies generated by default will basically cover the whole runtime of the OS userspace, from the initrd (as "760\-" closely follows 750\-enter\-initrd\&.pcrlock) until (and including) the main runtime of the system (as "940\-" is closely followed by 950\-shutdown\&.pcrlock)\&. See \fBsystemd.pcrlock\fR(5) for a full list of well\-known components, that illustrate where this range is placed by default\&. .sp Added in version 255\&. .RE .PP \fB\-\-recovery\-pin=\fR .RS 4 Takes a boolean\&. Defaults to false\&. Honoured by \fBmake\-policy\fR\&. If true, will query the user for a PIN to unlock the TPM2 NV index with\&. If no policy was created before this PIN is used to protect the newly allocated NV index\&. If a policy has been created before the PIN is used to unlock write access to the NV index\&. If this option is not used a PIN is automatically generated\&. Regardless if user supplied or automatically generated, it is stored in encrypted form in the policy metadata file\&. The recovery PIN may be used to regain write access to an NV index in case the access policy became out of date\&. .sp Added in version 255\&. .RE .PP \fB\-\-pcrlock=\fR .RS 4 Takes a file system path as argument\&. If specified overrides where to write the generated pcrlock data to\&. Honoured by the various \fBlock\-*\fR commands\&. If not specified, a default path is generally used, as documented above\&. .sp Added in version 255\&. .RE .PP \fB\-\-policy=\fR .RS 4 Takes a file system path as argument\&. If specified overrides where to write pcrlock policy metadata to\&. If not specified defaults to /var/lib/systemd/pcrlock\&.json\&. .sp Added in version 255\&. .RE .PP \fB\-\-force\fR .RS 4 If specified with \fBmake\-policy\fR, the predicted policy will be written to the NV index even if it is detected to be the same as the previously stored one\&. .sp Added in version 255\&. .RE .PP \fB\-\-json=\fR\fIMODE\fR .RS 4 Shows output formatted as JSON\&. Expects one of "short" (for the shortest possible output without any redundant whitespace or line breaks), "pretty" (for a pretty version of the same, with indentation and line breaks) or "off" (to turn off JSON output, the default)\&. .RE .PP \fB\-\-no\-pager\fR .RS 4 Do not pipe output into a pager\&. .RE .PP \fB\-h\fR, \fB\-\-help\fR .RS 4 Print a short help text and exit\&. .RE .PP \fB\-\-version\fR .RS 4 Print a short version string and exit\&. .RE .SH "EXIT STATUS" .PP On success, 0 is returned, a non\-zero failure code otherwise\&. .SH "SEE ALSO" .PP \fBsystemd\fR(1), \fBsystemd.pcrlock\fR(5), \fBsystemd-cryptenroll\fR(1), \fBsystemd-cryptsetup@.service\fR(8), \fBsystemd-repart\fR(8), \fBsystemd-pcrmachine.service\fR(8) .SH "NOTES" .IP " 1." 4 TCG Common Event Log Format (CEL-JSON) .RS 4 \%https://trustedcomputinggroup.org/resource/canonical-event-log-format/ .RE