diff --git a/common/acs_test_framework_manifests/verify-tpm-measurements.yaml b/common/acs_test_framework_manifests/verify-tpm-measurements.yaml index d30bd8d7..0a519673 100644 --- a/common/acs_test_framework_manifests/verify-tpm-measurements.yaml +++ b/common/acs_test_framework_manifests/verify-tpm-measurements.yaml @@ -12,6 +12,9 @@ x_verify_tpm_cli: &verify_tpm_cli set -eu python3 "$1" "$PWD/pcr.yaml" "$PWD/event.yaml" +x_verify_tpm_pcrs: &verify_tpm_pcrs + sha256: ["p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7"] + x_valid_tpm_events: &valid_tpm_events - EventNum: 1 PCRIndex: 0 @@ -415,6 +418,53 @@ suites: - "Verify presence of “Exit Boot Services Invocation” event with EV_EFI_ACTION type" - "PASS" + # EDK2 CPU-location record must not trigger a naming warning. + - name: edk2_cpu_location_record_does_not_warn + <<: *verify_tpm_cli + scenario: + kind: verify_tpm + pcrs: *verify_tpm_pcrs + table_of_devices: + - "010000000000000005a6dd3f6ea7464fad2912f4531b3d081834877d30020000" + expect_stdout_or_stderr_regex: + - 'Verify EV_TABLE_OF_DEVICES.*recommended strings\s+: PASS' + expect_stdout_or_stderr_contains: + - "CPU-location record; naming check not applicable" + + # Other invalid names must still generate a warning. + - name: unrelated_bad_device_table_name_still_warns + <<: *verify_tpm_cli + scenario: + kind: verify_tpm + pcrs: *verify_tpm_pcrs + table_of_devices: + - "010000000000000005a6dd3f6ea7464fad2912f4531b3d081834877d30020000" + - "UNRECOGNIZED_CONFIG" + expect_stdout_or_stderr_regex: + - 'Verify EV_TABLE_OF_DEVICES.*recommended strings\s+: WARN' + + # A different GUID must not receive the exemption. + - name: wrong_guid_device_table_still_warns + <<: *verify_tpm_cli + scenario: + kind: verify_tpm + pcrs: *verify_tpm_pcrs + table_of_devices: + - "010000000000000005a6dd3f6ea7464fad2912f4531b3d091834877d30020000" + expect_stdout_or_stderr_regex: + - 'Verify EV_TABLE_OF_DEVICES.*recommended strings\s+: WARN' + + # An incomplete structure must not be exempted. + - name: truncated_cpu_location_record_still_warns + <<: *verify_tpm_cli + scenario: + kind: verify_tpm + pcrs: *verify_tpm_pcrs + table_of_devices: + - "010000000000000005a6dd3f6ea7464fad2912f4531b3d081834877d300200" + expect_stdout_or_stderr_regex: + - 'Verify EV_TABLE_OF_DEVICES.*recommended strings\s+: WARN' + # PCR mismatch while event classes are otherwise present. - name: cli_pcr_mismatch_reports_fail_but_runs <<: *verify_tpm_cli diff --git a/common/linux_scripts/verify_tpm_measurements.py b/common/linux_scripts/verify_tpm_measurements.py index dd48d59f..46482960 100644 --- a/common/linux_scripts/verify_tpm_measurements.py +++ b/common/linux_scripts/verify_tpm_measurements.py @@ -120,6 +120,32 @@ def parse_eventlog_data(event_log_path): print(f"ERROR: {e}") exit(1) + + +def is_edk2_cpu_location_event(event): + """Identify the 64-bit EDK2 MP Services CPU-location measurement. + Tcg2Dxe.MeasureHandoffTables() logs one EFI_HANDOFF_TABLE_POINTERS + entry: UINT64 table count, EFI_MP_SERVICES_PROTOCOL GUID, UINT64 pointer. + The event digest covers CPU-location data, not this pointer structure. + """ + if event['event_type'] != "EV_TABLE_OF_DEVICES" or event['pcr_index'] != 1: + return False + + event_data = event.get('event_data') + if not isinstance(event_data, str): + return False + + try: + payload = bytes.fromhex(event_data) + except ValueError: + return False + + return (len(payload) == 32 + and int.from_bytes(payload[:8], 'little') == 1 + and payload[8:24] == bytes.fromhex('05a6dd3f6ea7464fad2912f4531b3d08') + and int.from_bytes(payload[24:32], 'little') != 0) + + def check_events(event_list): try: # Verify the EV_NO_ACTION event for Specification ID version. @@ -311,25 +337,29 @@ def check_events(event_list): status = "FAIL" else: count = count + 1 + # This structured EDK2 record is not a Secure-world/controller + # configuration name; it must not undergo the ASCII naming check. + if is_edk2_cpu_location_event(event): + print_buffer.append(f"Event {event['event_num']:2} is an EDK2 " + "CPU-location record; naming check not applicable") + continue # check if event data matches recommended string for pattern in sec_wd_aux_patterns: - if re.match(pattern, event['event_data']): + if isinstance(event.get('event_data'), str) and \ + re.match(pattern, event['event_data']): match_found = True break - if not match_found : + if not match_found: print_buffer.append(f"Event {event['event_num']:2} data doesn't " + \ "comply with recommended string") - status = "WARN" + if status == "PASS": + status = "WARN" # reset flag for next iteration match_found = False if count == 0: print_buffer.append("Event of type EV_TABLE_OF_DEVICES measured into PCR[1] not found") - TestResult(10, "FAIL") - elif status == "WARN": - # all events of type EV_TABLE_OF_DEVICES has event string as recommended. - TestResult(10, "WARN") - else: - TestResult(10, "PASS") + status = "FAIL" + TestResult(10, status) # If ExitBootServices() is invoked, then an EV_EFI_ACTION event # “Exit Boot Services Invocation” must be measured.