diff --git a/man/systemd-analyze.xml b/man/systemd-analyze.xml index 6a02291666..f3dfd7479f 100644 --- a/man/systemd-analyze.xml +++ b/man/systemd-analyze.xml @@ -1047,7 +1047,8 @@ default ignore - - Specification Date: Mon 2023-01-09 Manufacturer: STM Vendor String: ST33KTPM2XSPI - Firmware Version: 9.258 + Firmware Version: 9.258 + Modalias String: fi2.0:lv0:rv1.59:sy2023:sd9:mfSTM:vsST33KTPM2XSPI:ty0:fw9.258.0: diff --git a/src/analyze/analyze-has-tpm2.c b/src/analyze/analyze-has-tpm2.c index a63c44ebc6..2e7890cea1 100644 --- a/src/analyze/analyze-has-tpm2.c +++ b/src/analyze/analyze-has-tpm2.c @@ -120,6 +120,17 @@ int verb_identify_tpm2(int argc, char **argv, void *userdata) { if (r < 0) return table_log_add_error(r); + _cleanup_free_ char *m = NULL; + if (tpm2_vendor_info_to_modalias(&info, &m) < 0) + return log_oom(); + + r = table_add_many( + table, + TABLE_FIELD, "Modalias String", + TABLE_STRING, m); + if (r < 0) + return table_log_add_error(r); + r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, /* show_header= */ false); if (r < 0) return r; diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 64332fda32..2705f3b794 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -349,6 +349,43 @@ static int tpm2_get_capability( return more == TPM2_YES; } +int tpm2_vendor_info_to_modalias(const Tpm2VendorInfo *info, char **ret) { + _cleanup_free_ char *m = NULL; + + assert(info); + assert(ret); + + /* Closely inspired by kernel modalias strings, this distills information from the TPM vendor data + * into a string suitable for matching hwdb */ + + if (asprintf(&m, + "fi%s:" + "lv%" PRIu32 ":" + "rv%" PRIu32 ".%" PRIu32 ":" + "sy%" PRIu32 ":" + "sd%" PRIu32 ":" + "mf%s:" + "vs%s:" + "ty%" PRIx32 ":" + "fw%" PRIu16 ".%" PRIu16 ".%" PRIu32 ":", + info->family_indicator, + info->level, + info->revision_major, + info->revision_minor, + info->year, + info->day_of_year, + info->manufacturer, + info->vendor_string, + info->vendor_tpm_type, + info->firmware_version_major, + info->firmware_version_minor, + info->firmware_version2) < 0) + return -ENOMEM; + + *ret = TAKE_PTR(m); + return 0; +} + static char *mangle_vendor_chars(char *c, size_t n) { char *end = c; assert(c || n == 0); diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h index cbdad19719..9bccdd9712 100644 --- a/src/shared/tpm2-util.h +++ b/src/shared/tpm2-util.h @@ -210,6 +210,7 @@ typedef struct Tpm2VendorInfo { char vendor_string[4*4+1]; } Tpm2VendorInfo; +int tpm2_vendor_info_to_modalias(const Tpm2VendorInfo *info, char **ret); int tpm2_get_vendor_info(Tpm2Context *c, Tpm2VendorInfo *ret); void tpm2_log_debug_tpml_pcr_selection(const TPML_PCR_SELECTION *l, const char *msg);