From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A80132DEA94 for ; Tue, 2 Sep 2025 01:26:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756776386; cv=none; b=OJK2zKmq4RQ3Vz6Z1TxkJE+lDTa47hJrQtsaw2djyxpghuPavb0ia9n5clBP1BGz2wG+xZ0qgpbXdHJsOW1SdMhG7GSmwL5r6peibxT1nGaTU0F8WnYoBXo/ddMBnqu8sJF3RC3P0+rZvbpeeZla+5YSY15Y1sbPxwiFqQsPbcg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756776386; c=relaxed/simple; bh=2sMAXb7RANboZM9xwO0IQeIi+DvVXgYukpv67FWubSs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DqykovEitdqgKQESyl5XGKlTaNIbyHrvvcXh9VoyOHqv9xuAe1wyE+IVYmZ3QNihM5H/DarTlkygH5GsBcLHXd3s7BrQ0NNbxCSDmaDr3dmR2w0cJ0UByfr+ewY6irRbewHztBZ0ARgTKLN/JGVaV+ybGqd2VwMWORJoOjekX78= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qqo6f8Ki; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qqo6f8Ki" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A613CC4CEF0; Tue, 2 Sep 2025 01:26:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756776386; bh=2sMAXb7RANboZM9xwO0IQeIi+DvVXgYukpv67FWubSs=; h=From:To:Cc:Subject:Date:From; b=Qqo6f8KiPJwAK1TRKjJ/RMPiRsja01vr3XDaUO8DiT7RBhL/js+nwP8HK2/zlUo9A xreHFAEaDngxp+eEqdaZ/P5QLpHNqvizud16vixa4WsHrImhaVVCaa/krC5RMZ7U1h REdmn1bPrMdvMT9D0bZnEIF3oxIWMpotAFs31xjhur+kyzOZkVjPIjxzSDwCvQBArv HmDGytcHJqa9fmmTW/IoQ7iN1IC9wc48mIm88hrF/u2okycxisxoZoMN+UEVo0p81j /sxoatu5mWn+EYgap0b+itw93w5PCGyKEZ8cYff8eJHQJgRjSpCaybyI4Q2CJgoHhY QloGO3mrgRlGA== From: Jarkko Sakkinen To: tpm-protocol@lists.linux.dev Cc: Jarkko Sakkinen Subject: [PATCH] tests: add test_response_start_auth_session_no_sessions_2 Date: Tue, 2 Sep 2025 04:26:20 +0300 Message-Id: <20250902012620.2790121-1-jarkko@kernel.org> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: tpm-protocol@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a test taken from tpm2sh trace output, which reveals a bug in the response parser not catched by previous tests. Signed-off-by: Jarkko Sakkinen --- This is a embarrassing critical bug and damage from refactorization where `tpm_response!` macro was removed which was a compilicated task. The bright side is that the quality of test suite also leveled up as consequence and missing something as critical as this will become factors more difficult. Luckily response parsing it not too complicated, and this can be fixed quite easily. Dispatcher must be internally updated to pass the runtime parsed tag forward (just like it does for cc). I.e. a few macro updates should do. I should have a fix for this very soon! tests/runner.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/runner.rs b/tests/runner.rs index b63c801..3d2a1dc 100644 --- a/tests/runner.rs +++ b/tests/runner.rs @@ -26,7 +26,7 @@ use tpm2_protocol::{ TpmCreatePrimaryCommand, TpmEvictControlCommand, TpmFlushContextCommand, TpmFlushContextResponse, TpmGetCapabilityCommand, TpmHashCommand, TpmNvWriteCommand, TpmPcrEventResponse, TpmPcrReadCommand, TpmPcrReadResponse, TpmPolicyGetDigestResponse, - TpmStartAuthSessionCommand, TpmStartAuthSessionResponse, + TpmResponseBody, TpmStartAuthSessionCommand, TpmStartAuthSessionResponse, }, TpmBuffer, TpmBuild, TpmErrorKind, TpmParse, TpmPersistent, TpmSession, TpmSized, TpmWriter, TPM_MAX_COMMAND_SIZE, @@ -947,6 +947,26 @@ fn test_response_start_auth_session_no_sessions() { assert_eq!(resp, original_resp); } +fn test_response_start_auth_session_no_sessions_2() { + let response_hex = "8001000000300000000002000000002000647915de6106c955b26456b8b8a3b10546fa446405d4eb2e1fb0247fb52080"; + let response_bytes = hex_to_bytes(response_hex).unwrap(); + let (rc, body, sessions) = tpm_parse_response(TpmCc::StartAuthSession, &response_bytes) + .unwrap() + .unwrap(); + let mut built_bytes = [0; TPM_MAX_COMMAND_SIZE]; + let len = { + let mut writer = TpmWriter::new(&mut built_bytes); + match body { + TpmResponseBody::StartAuthSession(ref resp_struct) => { + tpm_build_response(resp_struct, &sessions, rc, &mut writer).unwrap(); + } + _ => panic!("Parsed the wrong response type!"), + } + writer.len() + }; + assert_eq!(&built_bytes[..len], &response_bytes); +} + fn test_tpm2b_build_length_too_large() { let large_slice: &[u8] = unsafe { std::slice::from_raw_parts( @@ -1156,6 +1176,7 @@ test_suite!( test_response_parse_policy_get_digest, test_response_start_auth_session, test_response_start_auth_session_no_sessions, + test_response_start_auth_session_no_sessions_2, test_tpm2b_build_length_too_large, test_tpmbuffer_try_from_slice_too_large, test_tpm_rc_base_from_raw, -- 2.39.5