Skip to content

Commit d651800

Browse files
daandemeyeryuwata
authored andcommitted
tpm2-setup: Don't fail if we can't access the TPM due to authorization failure
The TPM might be password/pin protected for various reasons even if there is no SRK yet. Let's handle those cases gracefully instead of failing the unit as it is enabled by default.
1 parent 0ef63b1 commit d651800

6 files changed

Lines changed: 36 additions & 1 deletion

File tree

catalog/systemd.catalog.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,3 +780,16 @@ Documentation: https://systemd.io/PORTABLE_SERVICES/
780780
A Portable Service @PORTABLE_ROOT@ (with extensions: @PORTABLE_EXTENSION@) has been
781781
detached from the system and is no longer available for use. The list of attached
782782
Portable Services can be queried with 'portablectl list'.
783+
784+
-- ad7089f928ac4f7ea00c07457d47ba8a
785+
Subject: Authorization failure while attempting to enroll SRK into TPM
786+
Defined-By: systemd
787+
Support: %SUPPORT_URL%
788+
Documentation: man:systemd-tpm2-setup.service(8)
789+
790+
An authorization failure occured while attempting to enroll a Storage Root Key (SRK) on the Trusted Platform
791+
Module (TPM). Most likely this means that a PIN/Password (authValue) has been set on the Owner hierarchy of
792+
the TPM.
793+
794+
Automatic SRK enrollment on TPMs in such scenarios is not supported. In order to unset the PIN/password
795+
protection on the owner hierarchy issue a command like the following: 'tpm2_changeauth -c o -p <OLDPW> ""'.

src/shared/tpm2-util.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,8 @@ int tpm2_create_primary(
21192119
/* creationData= */ NULL,
21202120
/* creationHash= */ NULL,
21212121
/* creationTicket= */ NULL);
2122+
if (rc == TPM2_RC_BAD_AUTH)
2123+
return log_debug_errno(SYNTHETIC_ERRNO(EDEADLK), "Authorization failure while attempting to enroll SRK into TPM.");
21222124
if (rc != TSS2_RC_SUCCESS)
21232125
return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
21242126
"Failed to generate primary key in TPM: %s",

src/systemd/sd-messages.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ _SD_BEGIN_DECLARATIONS;
272272
#define SD_MESSAGE_PORTABLE_DETACHED SD_ID128_MAKE(76,c5,c7,54,d6,28,49,0d,8e,cb,a4,c9,d0,42,11,2b)
273273
#define SD_MESSAGE_PORTABLE_DETACHED_STR SD_ID128_MAKE_STR(76,c5,c7,54,d6,28,49,0d,8e,cb,a4,c9,d0,42,11,2b)
274274

275+
#define SD_MESSAGE_SRK_ENROLLMENT_NEEDS_AUTHORIZATION SD_ID128_MAKE(ad,70,89,f9,28,ac,4f,7e,a0,0c,07,45,7d,47,ba,8a)
276+
#define SD_MESSAGE_SRK_ENROLLMENT_NEEDS_AUTHORIZATION_STR SD_ID128_MAKE_STR(ad,70,89,f9,28,ac,4f,7e,a0,0c,07,45,7d,47,ba,8a)
277+
275278
_SD_END_DECLARATIONS;
276279

277280
#endif

src/tpm2-setup/tpm2-setup.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <getopt.h>
44
#include <unistd.h>
55

6+
#include "sd-messages.h"
7+
68
#include "build.h"
79
#include "fd-util.h"
810
#include "fileio.h"
@@ -223,6 +225,8 @@ static int load_public_key_tpm2(struct public_key_data *ret) {
223225
/* ret_name= */ NULL,
224226
/* ret_qname= */ NULL,
225227
NULL);
228+
if (r == -EDEADLK)
229+
return r;
226230
if (r < 0)
227231
return log_error_errno(r, "Failed to get or create SRK: %m");
228232
if (r > 0)
@@ -289,6 +293,13 @@ static int run(int argc, char *argv[]) {
289293
}
290294

291295
r = load_public_key_tpm2(&tpm2_key);
296+
if (r == -EDEADLK) {
297+
log_struct_errno(LOG_INFO, r,
298+
LOG_MESSAGE("Insufficient permissions to access TPM, not generating SRK."),
299+
"MESSAGE_ID=" SD_MESSAGE_SRK_ENROLLMENT_NEEDS_AUTHORIZATION_STR);
300+
return 76; /* Special return value which means "Insufficient permissions to access TPM,
301+
* cannot generate SRK". This isn't really an error when called at boot. */;
302+
}
292303
if (r < 0)
293304
return r;
294305

@@ -383,4 +394,4 @@ static int run(int argc, char *argv[]) {
383394
return 0;
384395
}
385396

386-
DEFINE_MAIN_FUNCTION(run);
397+
DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);

units/systemd-tpm2-setup-early.service.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ ConditionPathExists=!/run/systemd/tpm2-srk-public-key.pem
2121
Type=oneshot
2222
RemainAfterExit=yes
2323
ExecStart={{LIBEXECDIR}}/systemd-tpm2-setup --early=yes --graceful
24+
25+
# The tool returns 76 if the TPM cannot be accessed due to an authorization failure and we can't generate an SRK.
26+
SuccessExitStatus=76

units/systemd-tpm2-setup.service.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ ConditionPathExists=!/etc/initrd-release
2222
Type=oneshot
2323
RemainAfterExit=yes
2424
ExecStart={{LIBEXECDIR}}/systemd-tpm2-setup --graceful
25+
26+
# The tool returns 76 if the TPM cannot be accessed due to an authorization failure and we can't generate an SRK.
27+
SuccessExitStatus=76

0 commit comments

Comments
 (0)