]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tpm-util: fix TPM parameter handling
authorAnatol Pomozov <anatol.pomozov@gmail.com>
Fri, 10 Sep 2021 18:52:55 +0000 (11:52 -0700)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 11 Sep 2021 06:32:17 +0000 (15:32 +0900)
cryptenroll allows to specify a custom TPM driver separated from
parameters with colon e.g. `systemd-cryptenroll --tpm2-device=swtpm:`
tells to load swtpm tss driver and use it as a device.

Unfortunately it does not work, swtpm driver init() fails with

```
debug:tcti:src/tss2-tcti/tcti-swtpm.c:570:Tss2_Tcti_Swtpm_Init() Dup'd conf string to: 0x562f91cbc000
debug:tcti:src/util/key-value-parse.c:85:parse_key_value_string() parsing key/value: swtpm:
WARNING:tcti:src/util/key-value-parse.c:50:parse_key_value() key / value string is invalid
Failed to initialize TCTI context: tcti:A parameter has a bad value
```

It turns out that cryptenroll suppose to use the driver name internally
and strip it before passing the rest of parameters to init() function.
Without doing it swtpm receives incorrect key-value property and gets
confused.

Fix it by passing the correct parameter (without driver name) to the
init() function.

Fixes #20708

src/shared/tpm2-util.c

index 793a54a449d256f779f1d6b750429abbf4350505..f29686e9948b1cf524aafce36cf2b77844658793 100644 (file)
@@ -184,7 +184,7 @@ static int tpm2_init(const char *device, struct tpm2_context *ret) {
                 if (!tcti)
                         return log_oom();
 
-                rc = info->init(tcti, &sz, device);
+                rc = info->init(tcti, &sz, param);
                 if (rc != TPM2_RC_SUCCESS)
                         return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
                                                "Failed to initialize TCTI context: %s", sym_Tss2_RC_Decode(rc));