diff options
| author | Jarkko Sakkinen <jarkko.sakkinen@opinsys.com> | 2026-07-11 09:01:09 -0700 |
|---|---|---|
| committer | Jarkko Sakkinen <jarkko@kernel.org> | 2026-08-21 04:44:57 +0300 |
| commit | 24483231da259974d1a4cb041bb4adafc22d152d (patch) | |
| tree | 6afcf981f75c78fc7794f83a9c17f0390fb089da /include | |
| parent | 9d63c22a68b539869f4e43b9dcd76d5d1969bfe6 (diff) | |
| download | linux-next-24483231da259974d1a4cb041bb4adafc22d152d.tar.gz linux-next-24483231da259974d1a4cb041bb4adafc22d152d.zip | |
tpm-buf: Memory-safe allocations
Decouple kzalloc from buffer creation, so that a managed allocation can be
used:
struct tpm_buf *buf __free(kfree) buf = kzalloc(TPM_BUFSIZE,
GFP_KERNEL);
if (!buf)
return -ENOMEM;
tpm_buf_init(buf, TPM_BUFSIZE);
Alternatively, other allocations are also possible (static data, stack,
etc) for example:
u8 buf_data[512];
struct tpm_buf *buf = (struct tpm_buf *)buf_data;
tpm_buf_init(buf, sizeof(buf_data));
This is achieved by embedding buffer's header inside the allocated blob,
instead of having an outer wrapper.
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@opinsys.com>
Tested-by: Srish Srinivasan <ssrish@linux.ibm.com>
Message-ID: <20260522013555.1063716-1-jarkko@kernel.org>
Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/tpm.h | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/include/linux/tpm.h b/include/linux/tpm.h index b357f8971d03..598dd53a10d8 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -208,13 +208,15 @@ enum tpm_buf_flags { }; /* - * A string buffer type for constructing TPM commands. + * A buffer for constructing and parsing TPM commands, responses and sized + * (TPM2B) buffers. */ struct tpm_buf { - u32 flags; - u32 length; - u8 *data; + u8 flags; + u16 length; + u16 capacity; u8 handles; + u8 data[]; }; struct tpm2_hash { @@ -222,12 +224,11 @@ struct tpm2_hash { unsigned int tpm_id; }; -int tpm_buf_init(struct tpm_buf *buf, u16 tag, u32 ordinal); +void tpm_buf_init(struct tpm_buf *buf, u16 buf_size); +void tpm_buf_init_sized(struct tpm_buf *buf, u16 buf_size); void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal); -int tpm_buf_init_sized(struct tpm_buf *buf); void tpm_buf_reset_sized(struct tpm_buf *buf); -void tpm_buf_destroy(struct tpm_buf *buf); -u32 tpm_buf_length(struct tpm_buf *buf); +u16 tpm_buf_length(struct tpm_buf *buf); void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_length); void tpm_buf_append_u8(struct tpm_buf *buf, const u8 value); void tpm_buf_append_u16(struct tpm_buf *buf, const u16 value); |
