| 1 |
<?xml version='1.0'?> <!--*-nxml-*--> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="systemd-pcrphase.service" conditional='ENABLE_BOOTLOADER HAVE_OPENSSL HAVE_TPM2' |
| 7 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 8 |
|
| 9 |
<refentryinfo> |
| 10 |
<title>systemd-pcrphase.service</title> |
| 11 |
<productname>systemd</productname> |
| 12 |
</refentryinfo> |
| 13 |
|
| 14 |
<refmeta> |
| 15 |
<refentrytitle>systemd-pcrphase.service</refentrytitle> |
| 16 |
<manvolnum>8</manvolnum> |
| 17 |
</refmeta> |
| 18 |
|
| 19 |
<refnamediv> |
| 20 |
<refname>systemd-pcrphase.service</refname> |
| 21 |
<refname>systemd-pcrphase-sysinit.service</refname> |
| 22 |
<refname>systemd-pcrphase-initrd.service</refname> |
| 23 |
<refname>systemd-pcrmachine.service</refname> |
| 24 |
<refname>systemd-pcrosseparator.service</refname> |
| 25 |
<refname>systemd-pcrproduct.service</refname> |
| 26 |
<refname>[email protected]</refname> |
| 27 |
<refname>systemd-pcrfs-root.service</refname> |
| 28 |
<refname>[email protected]</refname> |
| 29 |
<refname>systemd-pcrnvdone.service</refname> |
| 30 |
<refname>systemd-pcrphase-factory-reset.service</refname> |
| 31 |
<refname>systemd-pcrphase-storage-target-mode.service</refname> |
| 32 |
<refname>systemd-pcrextend</refname> |
| 33 |
<refpurpose>Measure boot phases, machine ID, product UUID, user records and file system identity into TPM PCRs and NvPCRs</refpurpose> |
| 34 |
</refnamediv> |
| 35 |
|
| 36 |
<refsynopsisdiv> |
| 37 |
<para><filename>systemd-pcrphase.service</filename></para> |
| 38 |
<para><filename>systemd-pcrphase-sysinit.service</filename></para> |
| 39 |
<para><filename>systemd-pcrphase-initrd.service</filename></para> |
| 40 |
<para><filename>systemd-pcrmachine.service</filename></para> |
| 41 |
<para><filename>systemd-pcrosseparator.service</filename></para> |
| 42 |
<para><filename>systemd-pcrproduct.service</filename></para> |
| 43 |
<para><filename>[email protected]</filename></para> |
| 44 |
<para><filename>systemd-pcrfs-root.service</filename></para> |
| 45 |
<para><filename>[email protected]</filename></para> |
| 46 |
<para><filename>systemd-pcrnvdone.service</filename></para> |
| 47 |
<para><filename>systemd-pcrphase-factory-reset.service</filename></para> |
| 48 |
<para><filename>systemd-pcrphase-storage-target-mode.service</filename></para> |
| 49 |
<para><filename>/usr/lib/systemd/systemd-pcrextend</filename> <optional><replaceable>STRING</replaceable></optional></para> |
| 50 |
</refsynopsisdiv> |
| 51 |
|
| 52 |
<refsect1> |
| 53 |
<title>Description</title> |
| 54 |
|
| 55 |
<para><filename>systemd-pcrphase.service</filename>, |
| 56 |
<filename>systemd-pcrphase-sysinit.service</filename>, and |
| 57 |
<filename>systemd-pcrphase-initrd.service</filename> are system services that measure specific strings |
| 58 |
into TPM2 PCR 11 during boot at various milestones of the boot process.</para> |
| 59 |
|
| 60 |
<para><filename>systemd-pcrmachine.service</filename> is a system service that measures the machine ID |
| 61 |
(see <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>) into |
| 62 |
PCR 15.</para> |
| 63 |
|
| 64 |
<para><filename>systemd-pcrosseparator.service</filename> is a system service that measures the word |
| 65 |
<literal>os-separator</literal> into PCRs 0-7, 9, 12-14. This acts as additional separator measurement |
| 66 |
separating pre-boot (i.e. firmware + bootloader) measurements from OS measurements, and in particular |
| 67 |
"seals" off the firmware PCRs.</para> |
| 68 |
|
| 69 |
<para><filename>systemd-pcrproduct.service</filename> is a system service that measures the firmware |
| 70 |
product UUID (as provided by one of SMBIOS, Devicetree, …) into a NvPCR named |
| 71 |
<literal>hardware</literal>.</para> |
| 72 |
|
| 73 |
<para><filename>[email protected]</filename> is a template service that measures the (reduced, |
| 74 |
canonical JSON) user record of the user indicated by its instance identifier (a UID) into a NvPCR named |
| 75 |
<literal>login</literal>. It is started by |
| 76 |
<citerefentry><refentrytitle>systemd-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 77 |
on the user's first login of the current boot, much like |
| 78 |
<citerefentry><refentrytitle>[email protected]</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 79 |
Unlike the latter it is intentionally never stopped again: it is a <varname>Type=oneshot</varname> service |
| 80 |
with <varname>RemainAfterExit=yes</varname> in <filename>system.slice</filename>, so each user is measured |
| 81 |
exactly once per boot regardless of how often they log in and out (NvPCR extensions form a hash chain, so |
| 82 |
measuring the same record twice would otherwise make the NvPCR value unpredictable). The resulting |
| 83 |
<literal>login</literal> NvPCR (together with the |
| 84 |
<filename>/run/log/systemd/tpm2-measure.log</filename> event log) thus provides a TPM-backed, |
| 85 |
append-only record of which user identities were activated during the current boot.</para> |
| 86 |
|
| 87 |
<para><filename>systemd-pcrnvdone.service</filename> is a system service that measures a separator event |
| 88 |
into PCR 9 once all NvPCRs have completed initialization.</para> |
| 89 |
|
| 90 |
<para><filename>systemd-pcrfs-root.service</filename> and <filename>[email protected]</filename> are |
| 91 |
services that measure file system identity information (i.e. mount point, file system type, label and |
| 92 |
UUID, partition label and UUID) into PCR 15. <filename>systemd-pcrfs-root.service</filename> does so for |
| 93 |
the root file system, <filename>[email protected]</filename> is a template unit that measures the |
| 94 |
file system indicated by its instance identifier instead.</para> |
| 95 |
|
| 96 |
<para>These services require |
| 97 |
<citerefentry><refentrytitle>systemd-stub</refentrytitle><manvolnum>7</manvolnum></citerefentry> to be |
| 98 |
used in a unified kernel image (UKI). They execute no operation when the stub has not been used to invoke |
| 99 |
the kernel. The stub will measure the invoked kernel and associated vendor resources into PCR 11 before |
| 100 |
handing control to it; once userspace is invoked these services then will extend TPM2 PCR 11 with certain |
| 101 |
literal strings indicating phases of the boot process. During a regular boot process PCR 11 is extended |
| 102 |
with the following strings:</para> |
| 103 |
|
| 104 |
<orderedlist> |
| 105 |
<listitem><para><literal>enter-initrd</literal> — early when the initrd initializes, before activating |
| 106 |
system extension images for the initrd. It acts as a barrier between the time where the kernel |
| 107 |
initializes and where the initrd starts operating and enables system extension images, i.e. code |
| 108 |
shipped outside of the UKI. (This extension happens when the |
| 109 |
<citerefentry><refentrytitle>systemd-pcrphase-initrd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 110 |
service is started.)</para></listitem> |
| 111 |
|
| 112 |
<listitem><para><literal>leave-initrd</literal> — when the initrd is about to transition into the host |
| 113 |
file system. It acts as barrier between initrd code and host OS code. (This extension happens when the |
| 114 |
<citerefentry><refentrytitle>systemd-pcrphase-sysinit.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 115 |
service is stopped.)</para></listitem> |
| 116 |
|
| 117 |
<listitem><para><literal>sysinit</literal> — when basic system initialization is complete (which |
| 118 |
includes local file systems having been mounted), and the system begins starting regular system |
| 119 |
services. (This extension happens when the |
| 120 |
<citerefentry><refentrytitle>systemd-pcrphase-sysinit.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 121 |
service is started.)</para></listitem> |
| 122 |
|
| 123 |
<listitem><para><literal>ready</literal> — during later boot-up, after remote file systems have been |
| 124 |
activated (i.e. after <filename>remote-fs.target</filename>), but before users are permitted to log in |
| 125 |
(i.e. before <filename>systemd-user-sessions.service</filename>). It acts as barrier between the time |
| 126 |
where unprivileged regular users are still prohibited to log in and where they are allowed to log in. |
| 127 |
(This extension happens when the |
| 128 |
<citerefentry><refentrytitle>systemd-pcrphase-sysinit.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 129 |
service is started.) |
| 130 |
</para></listitem> |
| 131 |
|
| 132 |
<listitem><para><literal>shutdown</literal> — when the system shutdown begins. It acts as barrier |
| 133 |
between the time the system is fully up and running and where it is about to shut down. (This extension |
| 134 |
happens when the <filename>systemd-pcrphase.service</filename> service is stopped.)</para></listitem> |
| 135 |
|
| 136 |
<listitem><para><literal>final</literal> — at the end of system shutdown. It acts as barrier between |
| 137 |
the time the service manager still runs and when it transitions into the final shutdown phase where |
| 138 |
service management is not available anymore. (This extension happens when the |
| 139 |
<citerefentry><refentrytitle>systemd-pcrphase-sysinit.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 140 |
service is stopped.)</para></listitem> |
| 141 |
</orderedlist> |
| 142 |
|
| 143 |
<para>During a regular system lifecycle, PCR 11 is extended with the strings |
| 144 |
<literal>enter-initrd</literal>, <literal>leave-initrd</literal>, <literal>sysinit</literal>, |
| 145 |
<literal>ready</literal>, <literal>shutdown</literal>, and <literal>final</literal>.</para> |
| 146 |
|
| 147 |
<para>Specific phases of the boot process may be referenced via the series of strings measured, separated |
| 148 |
by colons (the "phase path"). For example, the phase path for the regular system runtime is |
| 149 |
<literal>enter-initrd:leave-initrd:sysinit:ready</literal>, while the one for the initrd is just |
| 150 |
<literal>enter-initrd</literal>. The phase path for the boot phase before the initrd is an empty string; |
| 151 |
because that's hard to pass around a single colon (<literal>:</literal>) may be used instead. Note that |
| 152 |
the aforementioned six strings are just the default strings and individual systems might measure other |
| 153 |
strings at other times, and thus implement different and more fine-grained boot phases to bind policy |
| 154 |
to.</para> |
| 155 |
|
| 156 |
<para>By binding policy of TPM2 objects to a specific phase path it is possible to restrict access to |
| 157 |
them to specific phases of the boot process, for example making it impossible to access the root file |
| 158 |
system's encryption key after the system transitioned from the initrd into the host root file system. |
| 159 |
</para> |
| 160 |
|
| 161 |
<para>Use |
| 162 |
<citerefentry><refentrytitle>systemd-measure</refentrytitle><manvolnum>1</manvolnum></citerefentry> to |
| 163 |
pre-calculate expected PCR 11 values for specific boot phases (via the <option>--phase=</option> switch). |
| 164 |
</para> |
| 165 |
|
| 166 |
<para><filename>systemd-pcrfs-root.service</filename> and <filename>[email protected]</filename> are |
| 167 |
automatically pulled into the initial transaction by |
| 168 |
<citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 169 |
for the root and <filename>/var/</filename> file |
| 170 |
systems. <citerefentry><refentrytitle>systemd-fstab-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 171 |
will do this for all mounts with the <option>x-systemd.pcrfs</option> mount option in |
| 172 |
<filename>/etc/fstab</filename>.</para> |
| 173 |
</refsect1> |
| 174 |
|
| 175 |
<refsect1> |
| 176 |
<title>Options</title> |
| 177 |
|
| 178 |
<para>The <filename>/usr/lib/systemd/systemd-pcrextend</filename> executable may also be invoked from the |
| 179 |
command line, where it expects the word to extend into a PCR or NvPCR, as well as the following |
| 180 |
switches:</para> |
| 181 |
|
| 182 |
<variablelist> |
| 183 |
<varlistentry> |
| 184 |
<term><option>--bank=</option></term> |
| 185 |
|
| 186 |
<listitem><para>Takes the PCR banks to extend the specified word into. If not specified, the tool |
| 187 |
automatically determines all enabled PCR banks and measures the word into all of |
| 188 |
them.</para> |
| 189 |
|
| 190 |
<xi:include href="version-info.xml" xpointer="v252"/></listitem> |
| 191 |
</varlistentry> |
| 192 |
|
| 193 |
<varlistentry> |
| 194 |
<term><option>--pcr=</option></term> |
| 195 |
|
| 196 |
<listitem><para>Takes the index of the PCR to extend. If <option>--machine-id</option> or |
| 197 |
<option>--file-system=</option> are specified defaults to 15, otherwise (and unless |
| 198 |
<option>--product-id</option> is specified) defaults to 11. May be specified multiple times, in order |
| 199 |
to measure to multiple PCRs at the same time. May not be combined with |
| 200 |
<option>--nvpcr=</option>.</para> |
| 201 |
|
| 202 |
<xi:include href="version-info.xml" xpointer="v255"/></listitem> |
| 203 |
</varlistentry> |
| 204 |
|
| 205 |
<varlistentry> |
| 206 |
<term><option>--nvpcr=</option></term> |
| 207 |
|
| 208 |
<listitem><para>Takes a name of an NvPCR to extend. NvPCRs are additional PCRs implemented via TPM NV |
| 209 |
indexes. The name should be a short string such as <literal>hardware</literal> or |
| 210 |
<literal>disk-encryption</literal>. If <option>--product-id</option> is specified defaults |
| 211 |
<literal>hardware</literal>. May not be combined with <option>--pcr=</option>.</para> |
| 212 |
|
| 213 |
<xi:include href="version-info.xml" xpointer="v259"/></listitem> |
| 214 |
</varlistentry> |
| 215 |
|
| 216 |
<varlistentry> |
| 217 |
<term><option>--tpm2-device=<replaceable>PATH</replaceable></option></term> |
| 218 |
|
| 219 |
<listitem><para>Controls which TPM2 device to use. Expects a device node path referring to the TPM2 |
| 220 |
chip (e.g. <filename>/dev/tpmrm0</filename>). Alternatively the special value <literal>auto</literal> |
| 221 |
may be specified, in order to automatically determine the device node of a suitable TPM2 device (of |
| 222 |
which there must be exactly one). The special value <literal>list</literal> may be used to enumerate |
| 223 |
all suitable TPM2 devices currently discovered.</para> |
| 224 |
|
| 225 |
<xi:include href="version-info.xml" xpointer="v252"/></listitem> |
| 226 |
</varlistentry> |
| 227 |
|
| 228 |
<varlistentry> |
| 229 |
<term><option>--graceful</option></term> |
| 230 |
|
| 231 |
<listitem><para>If no TPM2 firmware, kernel subsystem, kernel driver or device support is found, exit |
| 232 |
with exit status 0 (i.e. indicate success). If this is not specified, any attempt to measure without a |
| 233 |
TPM2 device will cause the invocation to fail.</para> |
| 234 |
|
| 235 |
<xi:include href="version-info.xml" xpointer="v253"/></listitem> |
| 236 |
</varlistentry> |
| 237 |
|
| 238 |
<varlistentry> |
| 239 |
<term><option>--early</option></term> |
| 240 |
|
| 241 |
<listitem><para>Selects early-boot mode. Specifically this means that the NvPCR anchor secret is not |
| 242 |
attempted to be written into <filename>/var/lib/</filename> and the boot loader partition in addition |
| 243 |
to <filename>/run/</filename>. (Unlike the latter the former are generally not mounted and writable |
| 244 |
during early boot or in the initrd.)</para> |
| 245 |
|
| 246 |
<xi:include href="version-info.xml" xpointer="v259"/></listitem> |
| 247 |
</varlistentry> |
| 248 |
|
| 249 |
<varlistentry> |
| 250 |
<term><option>--machine-id</option></term> |
| 251 |
|
| 252 |
<listitem><para>Instead of measuring a word specified on the command line into PCR 11, measure the |
| 253 |
host's machine ID into PCR 15.</para> |
| 254 |
|
| 255 |
<xi:include href="version-info.xml" xpointer="v253"/></listitem> |
| 256 |
</varlistentry> |
| 257 |
|
| 258 |
<varlistentry> |
| 259 |
<term><option>--product-id</option></term> |
| 260 |
|
| 261 |
<listitem><para>Instead of measuring a word specified on the command line into PCR 11, measure the |
| 262 |
firmware's product UUID into an NvPCR named <literal>hardware</literal>.</para> |
| 263 |
|
| 264 |
<xi:include href="version-info.xml" xpointer="v259"/></listitem> |
| 265 |
</varlistentry> |
| 266 |
|
| 267 |
<varlistentry> |
| 268 |
<term><option>--login=</option></term> |
| 269 |
|
| 270 |
<listitem><para>Instead of measuring a word specified on the command line into PCR 11, measure the |
| 271 |
user record of the specified user into an NvPCR named <literal>login</literal>. The parameter must be a |
| 272 |
user name or numeric UID. The record is reduced to its <literal>regular</literal>, |
| 273 |
<literal>perMachine</literal> and <literal>binding</literal> sections (i.e. the privileged, secret, |
| 274 |
status and signature sections are stripped, so that for example password hash changes do not perturb |
| 275 |
the NvPCR), normalized and serialized to canonical JSON before measurement. This is primarily used by |
| 276 |
<filename>[email protected]</filename>.</para> |
| 277 |
|
| 278 |
<xi:include href="version-info.xml" xpointer="v261"/></listitem> |
| 279 |
</varlistentry> |
| 280 |
|
| 281 |
<varlistentry> |
| 282 |
<term><option>--file-system=</option></term> |
| 283 |
|
| 284 |
<listitem><para>Instead of measuring a word specified on the command line into PCR 11, measure |
| 285 |
identity information of the specified file system into PCR 15. The parameter must be the path to the |
| 286 |
established mount point of the file system to measure.</para> |
| 287 |
|
| 288 |
<xi:include href="version-info.xml" xpointer="v253"/></listitem> |
| 289 |
</varlistentry> |
| 290 |
|
| 291 |
<varlistentry> |
| 292 |
<term><option>--event-type=</option></term> |
| 293 |
|
| 294 |
<listitem><para>Set the event log event type for this measurement. Pass <literal>help</literal> for a |
| 295 |
list of currently defined identifiers. Defaults to an appropriate value for |
| 296 |
<option>--machine-id</option>, <option>--product-id</option>, <option>--file-system=</option>, |
| 297 |
<option>--login=</option>, and otherwise to <literal>phase</literal>.</para> |
| 298 |
|
| 299 |
<xi:include href="version-info.xml" xpointer="v259"/></listitem> |
| 300 |
</varlistentry> |
| 301 |
|
| 302 |
<xi:include href="standard-options.xml" xpointer="help" /> |
| 303 |
<xi:include href="standard-options.xml" xpointer="version" /> |
| 304 |
|
| 305 |
</variablelist> |
| 306 |
</refsect1> |
| 307 |
|
| 308 |
<refsect1> |
| 309 |
<title>Files</title> |
| 310 |
|
| 311 |
<variablelist> |
| 312 |
<varlistentry> |
| 313 |
<term><filename>/run/log/systemd/tpm2-measure.log</filename></term> |
| 314 |
|
| 315 |
<listitem><para>Measurements are logged into an event log file maintained in |
| 316 |
<filename>/run/log/systemd/tpm2-measure.log</filename>, which contains a <ulink |
| 317 |
url="https://www.rfc-editor.org/rfc/rfc7464.html">JSON-SEQ</ulink> series of objects that follow the |
| 318 |
general structure of the <ulink |
| 319 |
url="https://trustedcomputinggroup.org/resource/canonical-event-log-format/">TCG Canonical Event Log |
| 320 |
Format (CEL-JSON)</ulink> event objects (but lack the <literal>recnum</literal> |
| 321 |
field).</para> |
| 322 |
|
| 323 |
<para>A <constant>LOCK_EX</constant> BSD file lock (<citerefentry |
| 324 |
project='man-pages'><refentrytitle>flock</refentrytitle><manvolnum>2</manvolnum></citerefentry>) on |
| 325 |
the log file is acquired while the measurement is made and the file is updated. Thus, applications |
| 326 |
that intend to acquire a consistent quote from the TPM with the associated snapshot of the event log |
| 327 |
should acquire a <constant>LOCK_SH</constant> lock while doing so.</para> |
| 328 |
|
| 329 |
<xi:include href="version-info.xml" xpointer="v252"/></listitem> |
| 330 |
</varlistentry> |
| 331 |
|
| 332 |
<varlistentry> |
| 333 |
<term><filename>/usr/lib/nvpcr/*.nvpcr</filename></term> |
| 334 |
|
| 335 |
<listitem><para>Definition files for NvPCRs.</para> |
| 336 |
<xi:include href="version-info.xml" xpointer="v259"/></listitem> |
| 337 |
</varlistentry> |
| 338 |
</variablelist> |
| 339 |
</refsect1> |
| 340 |
|
| 341 |
<refsect1> |
| 342 |
<title>See Also</title> |
| 343 |
<para><simplelist type="inline"> |
| 344 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 345 |
<member><citerefentry><refentrytitle>systemd-stub</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> |
| 346 |
<member><citerefentry><refentrytitle>systemd-measure</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 347 |
<member><citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 348 |
<member><citerefentry><refentrytitle>systemd-fstab-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 349 |
<member><ulink url="https://systemd.io/TPM2_PCR_MEASUREMENTS">TPM2 PCR Measurements Made by systemd</ulink></member> |
| 350 |
</simplelist></para> |
| 351 |
</refsect1> |
| 352 |
|
| 353 |
</refentry> |