Skip to content

Commit 11189d6

Browse files
James Bottomleyjarkkojs
authored andcommitted
tpm: add buffer function to point to returned parameters
Replace all instances of &buf.data[TPM_HEADER_SIZE] with a new function tpm_buf_parameters() because encryption sessions change where the return parameters are located in the buffer since if a return session is present they're 4 bytes beyond the header with those 4 bytes giving the parameter length. If there is no return session, then they're in the usual place immediately after the header. Signed-off-by: James Bottomley <[email protected]> Reviewed-by: Stefan Berger <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent f135440 commit 11189d6

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

drivers/char/tpm/tpm-buf.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,31 @@ u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset)
221221
return be32_to_cpu(value);
222222
}
223223
EXPORT_SYMBOL_GPL(tpm_buf_read_u32);
224+
225+
static u16 tpm_buf_tag(struct tpm_buf *buf)
226+
{
227+
struct tpm_header *head = (struct tpm_header *)buf->data;
228+
229+
return be16_to_cpu(head->tag);
230+
}
231+
232+
/**
233+
* tpm_buf_parameters - return the TPM response parameters area of the tpm_buf
234+
* @buf: tpm_buf to use
235+
*
236+
* Where the parameters are located depends on the tag of a TPM
237+
* command (it's immediately after the header for TPM_ST_NO_SESSIONS
238+
* or 4 bytes after for TPM_ST_SESSIONS). Evaluate this and return a
239+
* pointer to the first byte of the parameters area.
240+
*
241+
* @return: pointer to parameters area
242+
*/
243+
u8 *tpm_buf_parameters(struct tpm_buf *buf)
244+
{
245+
int offset = TPM_HEADER_SIZE;
246+
247+
if (tpm_buf_tag(buf) == TPM2_ST_SESSIONS)
248+
offset += 4;
249+
250+
return &buf->data[offset];
251+
}

include/linux/tpm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset);
344344
u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset);
345345
u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset);
346346

347+
u8 *tpm_buf_parameters(struct tpm_buf *buf);
348+
347349
/*
348350
* Check if TPM device is in the firmware upgrade mode.
349351
*/

0 commit comments

Comments
 (0)