tpm_buf_check_hmac_response(9)
π tpm_buf_check_hmac_response(9)
okay so bestie, we're in the Kernel API Manual today and this one is lowkey iconic β it's tpm_buf_check_hmac_response, and it does exactly what the name screams: it checks the TPM return HMAC for correctness. no cap. π¦
β¨ NAME β¨
tpm_buf_check_hmac_response β check the TPM return HMAC for correctness
πΈ SYNOPSIS πΈ
int tpm_buf_check_hmac_response (struct tpm_chip *chip , struct tpm_buf
*buf , int rc );
π ARGUMENTS π
chipβ the TPM chip structure. that's your whole TPM vibe right there πbufβ the original command buffer, which now contains the response. it's giving "same buffer, new era" β¨rcβ the return code fromtpm_transmit_cmd. yes, the lowercasetpm_transmit_cmd, not the function above it, don't get it twisted π
π§ DESCRIPTION π§
okay so first case, bestie: if rc is non zero, buf may not contain an actual return. so rc is passed through as the return, and the session gets cleaned up and de-allocated if required. and when is it required? literally when TPM2_SA_CONTINUE_SESSION was not specified as a session flag. noted. π
second case, and this is the main character moment: if rc is zero, the response HMAC is computed against the returned buf and matched to the TPM one in the session area. if there's a mismatch, an error is logged and -EINVAL is returned. boom, roasted. π₯
and the reason for all this? the command issue and HMAC check sequence should look like this:
rc = tpm_transmit_cmd(...); rc = tpm_buf_check_hmac_response(buf, auth,
rc); if (rc) ...
which is easily layered into the current contrl flow. π«Ά
ngl that code block is the whole point β it's the "check your HMAC before you do anything else" pattern, and it slots right into the flow you already have.
π RETURN π
0 on success or an error. that's it. that's the tea. β
π SEE ALSO π
- Kernel file
./drivers/char/tpm/tpm2-sessions.c tpm_buf_append_name(9)tpm_buf_append_hmac_session(9)tpm_buf_fill_hmac_session(9)tpm2_end_auth_session(9)tpm2_start_auth_session(9)tpm2_parse_create_primary(9)tpm2_create_primary(9)tpm2_sessions_init(9)
and that's the whole page, bestie π©· this little icon lives in ./drivers/char/tpm, straight from the October 2026 drops β go read the source, it's right there, iykyk ππ§
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms