tpm: Make TPM buffer allocations more robust
Subsystems (4)
Jarkko Sakkinen
maintainerPATCH v9 1/1 tpm: Make TPM buffer allocations more robust
From: Jarkko Sakkinen <[email protected]>
Create more ergonomic primitives to work with TPM buffers, where 'tpm_buf_init*' initialize the memory and 'tpm_buf_reset*' (re)set a buffer for a particular use and purpose. The new primitives are ubiquitos when it comes to heap and stack usage.
Given that the kzalloc is decoupled, a managed allocation can be done trivially:
struct tpm_buf *buf __free(kfree) buf = kzalloc(TPM_BUF_MAX_SIZE, GFP_KERNEL);
This effectively zeros out the odds having any memory leaks with TPM buffers. The new structures can be later used to widen the use of stack over heap in the subsystem in the critical code paths..
---
v9:
- Rename pre-existing TPM_BUFSIZE as TPM_BUF_MAX_SIZE and redeclare it in include/linux/tpm.h, and use this constant instead of PAGE_SIZE in tpm_buf_init*. Define TPM_BUF_MIN_SIZE to be a sane placeholder value for stack allocations.
- Fix and restructure invariant for the sake of clarity.
- memset buffers to zero in tpm_buf_init* in order to guarantee a legit initial state. This does not cause any regressions but once tpm_buf is allocaed from stack at some site, this will zero out chance of corrupted state.
v8:
- Decouple memory init i.e. bring tpm_init* back but with new fresh form.
- Cap buf_size to page size and also make checks in tpm_buf_append safe:
https://lore.kernel.org/linux-integrity/hwsx2t2tkbos3g7k2syemxbvc6sfrsbviwm64ubcdl6ms7ljvo@toetomkhheht/
- Fix trusted_tpm_send() and simplify the flow.
v7:
- Additional function comments and invariant was unfortunately left to my staging area so here's the addition (does not affect functionality).
v6:
- Removed two empty lines as requested by Stefan:
https://lore.kernel.org/linux-integrity/[email protected]/
- Add 'capacity' field as this makes easy to stretch tpm_buf into stack allocation.
v5:
- I tested this version also with TPM 1.2 by booting up and checking that sysfs attributes work.
- Fixed the length check against capacity (James) with TPM_BUF_CAPACITY.
- Fixed declaration style: do it at the site (Jason).
- Improved commit message (Stefan).
- Removed "out" label from tpm2_pcr_read() (Stefan).
- Removed spurious "return rc;" from tpm2_get_pcr_allocation() (Stefan). v4:
- Wrote a more a descriptive short summary and improved description.
- Fixed the error in documentation: there is 4090 bytes of space left for the payload - not 4088 bytes.
- Turned tpm_buf_alloc() into inline function.
v3:
- Removed the cleanup class and moved on using __free(kfree) instead.
- Removed buf_size (James).
- I'm open for the idea of splitting still (Jason) but I'll hold at least this revision just to check that my core idea here is correct.
v2:
- Implement also memory allocation using the cleanup class.
- Rewrote the commit message.
- Implemented CLASS_TPM_BUF() helper macro.
--- drivers/char/tpm/tpm-buf.c | 137 +++++++---- drivers/char/tpm/tpm-dev-common.c | 4 +- drivers/char/tpm/tpm-dev.h | 2 +- drivers/char/tpm/tpm-interface.c | 4 +- drivers/char/tpm/tpm-sysfs.c | 20 +- drivers/char/tpm/tpm.h | 3 +- drivers/char/tpm/tpm1-cmd.c | 149 ++++++------ drivers/char/tpm/tpm2-cmd.c | 282 ++++++++++------------ drivers/char/tpm/tpm2-sessions.c | 121 +++++----- drivers/char/tpm/tpm2-space.c | 44 ++-- drivers/char/tpm/tpm_tis_i2c.c | 4 +- drivers/char/tpm/tpm_vtpm_proxy.c | 32 ++- include/linux/tpm.h | 28 ++- security/keys/trusted-keys/trusted_tpm1.c | 34 ++- security/keys/trusted-keys/trusted_tpm2.c | 156 ++++++------ 15 files changed, 493 insertions(+), 527 deletions(-)
drivers/char/tpm/tpm-buf.c +84 -53
@@ -7,82 +7,107 @@#include <linux/module.h> #include <linux/tpm.h> -/** -* tpm_buf_init() - Allocate and initialize a TPM command -* @buf: A &tpm_buf -* @tag: TPM_TAG_RQU_COMMAND, TPM2_ST_NO_SESSIONS or TPM2_ST_SESSIONS -* @ordinal: A command ordinal -* -* Return: 0 or -ENOMEM -*/ -int tpm_buf_init (struct tpm_buf *buf,u16 tag,u32 ordinal) +static void __tpm_buf_size_invariant (struct tpm_buf *buf,u16 buf_size) { - buf->data = (u8 *)__get_free_page (GFP_KERNEL ); -if (!buf->data) -return -ENOMEM ; - -tpm_buf_reset (buf, tag, ordinal); -return 0 ; +if (!buf->capacity) { +if (buf_size >TPM_BUF_MAX_SIZE ) { +WARN (1 ,"%s: size overflow: %u\n" , __func__, buf_size); + buf->flags |=TPM_BUF_ERROR ; + } + }else { +if (buf_size != buf->capacity +sizeof (*buf)) { +WARN (1 ,"%s: size mismatch: %u != %u\n" , __func__, buf_size, + buf->capacity +sizeof (*buf)); + buf->flags |=TPM_BUF_ERROR ; + } + } } -EXPORT_SYMBOL_GPL (tpm_buf_init); -/** -* tpm_buf_reset() - Initialize a TPM command -* @buf: A &tpm_buf -* @tag: TPM_TAG_RQU_COMMAND, TPM2_ST_NO_SESSIONS or TPM2_ST_SESSIONS -* @ordinal: A command ordinal -*/ -void tpm_buf_reset (struct tpm_buf *buf,u16 tag,u32 ordinal) +static void __tpm_buf_reset (struct tpm_buf *buf,u16 buf_size,u16 tag,u32 ordinal) {struct tpm_header *head = (struct tpm_header *)buf->data; +__tpm_buf_size_invariant (buf, buf_size); + +if (buf->flags &TPM_BUF_ERROR ) +return ; +WARN_ON (tag !=TPM_TAG_RQU_COMMAND && tag !=TPM2_ST_NO_SESSIONS && tag !=TPM2_ST_SESSIONS && tag !=0 ); buf->flags =0 ; buf->length =sizeof (*head); + buf->capacity = buf_size -sizeof (*buf); + buf->handles =0 ; head->tag =cpu_to_be16 (tag); head->length =cpu_to_be32 (sizeof (*head)); head->ordinal =cpu_to_be32 (ordinal); +} + +static void __tpm_buf_reset_sized (struct tpm_buf *buf,u16 buf_size) +{ +__tpm_buf_size_invariant (buf, buf_size); + +if (buf->flags &TPM_BUF_ERROR ) +return ; + + buf->flags =TPM_BUF_TPM2B ; + buf->length =2 ; + buf->capacity = buf_size -sizeof (*buf); buf->handles =0 ; + buf->data[0 ] =0 ; + buf->data[1 ] =0 ; } -EXPORT_SYMBOL_GPL (tpm_buf_reset);/** -* tpm_buf_init_sized() - Allocate and initialize a sized (TPM2B) buffer -* @buf: A @tpm_buf -* -* Return: 0 or -ENOMEM +* tpm_buf_init() - Initialize a TPM command +* @buf: A &tpm_buf +* @buf_size: Size of the buffer. */ -int tpm_buf_init_sized (struct tpm_buf *buf) +void tpm_buf_init (struct tpm_buf *buf,u16 buf_size) { - buf->data = (u8 *)__get_free_page (GFP_KERNEL ); -if (!buf->data) -return -ENOMEM ; +memset (buf,0 , buf_size); +__tpm_buf_reset (buf, buf_size,TPM_TAG_RQU_COMMAND ,0 ); +} +EXPORT_SYMBOL_GPL (tpm_buf_init); -tpm_buf_reset_sized (buf); -return 0 ; +/** +* tpm_buf_init_sized() - Initialize a sized buffer +* @buf: A &tpm_buf +* @buf_size: Size of the buffer. +*/ +void tpm_buf_init_sized (struct tpm_buf *buf,u16 buf_size) +{ +memset (buf,0 , buf_size); +__tpm_buf_reset_sized (buf, buf_size); }EXPORT_SYMBOL_GPL (tpm_buf_init_sized);/** -* tpm_buf_reset_sized() - Initialize a sized buffer +* tpm_buf_reset() - Re-initialize a TPM command * @buf: A &tpm_buf +* @tag: TPM_TAG_RQU_COMMAND, TPM2_ST_NO_SESSIONS or TPM2_ST_SESSIONS +* @ordinal: A command ordinal */ -void tpm_buf_reset_sized (struct tpm_buf *buf) +void tpm_buf_reset (struct tpm_buf *buf,u16 tag,u32 ordinal) { - buf->flags =TPM_BUF_TPM2B ; - buf->length =2 ; - buf->data[0 ] =0 ; - buf->data[1 ] =0 ; +u16 buf_size = buf->capacity +sizeof (*buf); + +__tpm_buf_reset (buf, buf_size, tag, ordinal); } -EXPORT_SYMBOL_GPL (tpm_buf_reset_sized); +EXPORT_SYMBOL_GPL (tpm_buf_reset); -void tpm_buf_destroy (struct tpm_buf *buf) +/** +* tpm_buf_reset_sized() - Re-initialize a sized buffer +* @buf: A &tpm_buf +*/ +void tpm_buf_reset_sized (struct tpm_buf *buf) { -free_page ((unsigned long )buf->data); +u16 buf_size = buf->capacity +sizeof (*buf); + +__tpm_buf_reset_sized (buf, buf_size); } -EXPORT_SYMBOL_GPL (tpm_buf_destroy); +EXPORT_SYMBOL_GPL (tpm_buf_reset_sized);/** * tpm_buf_length() - Return the number of bytes consumed by the data
@@ -92,6 +117,9 @@ EXPORT_SYMBOL_GPL(tpm_buf_destroy);*/ u32 tpm_buf_length (struct tpm_buf *buf) { +if (buf->flags &TPM_BUF_ERROR ) +return 0 ; +return buf->length; }EXPORT_SYMBOL_GPL (tpm_buf_length);
@@ -104,13 +132,14 @@ EXPORT_SYMBOL_GPL(tpm_buf_length);*/ void tpm_buf_append (struct tpm_buf *buf,const u8 *new_data,u16 new_length) { -/* Return silently if overflow has already happened. */ -if (buf->flags &TPM_BUF_OVERFLOW ) +u32 total_length = (u32 )buf->length + (u32 )new_length; + +if (buf->flags &TPM_BUF_ERROR )return ; -if ((buf->length + new_length) >PAGE_SIZE ) { +if (total_length > (u32 )buf->capacity) {WARN (1 ,"tpm_buf: write overflow\n" ); - buf->flags |=TPM_BUF_OVERFLOW ; + buf->flags |=TPM_BUF_ERROR ;return ; }
@@ -157,8 +186,12 @@ EXPORT_SYMBOL_GPL(tpm_buf_append_u32);*/ void tpm_buf_append_handle (struct tpm_chip *chip,struct tpm_buf *buf,u32 handle) { +if (buf->flags &TPM_BUF_ERROR ) +return ; +if (buf->flags &TPM_BUF_TPM2B ) { -dev_err (&chip->dev,"Invalid buffer type (TPM2B)\n" ); +dev_err (&chip->dev,"%s: invalid for buffer type: TPM2B\n" , __func__); + buf->flags |=TPM_BUF_ERROR ;return ; }
@@ -178,13 +211,13 @@ static void tpm_buf_read(struct tpm_buf *buf, off_t *offset, size_t count, voidoff_t next_offset;/* Return silently if overflow has already happened. */ -if (buf->flags &TPM_BUF_BOUNDARY_ERROR ) +if (buf->flags &TPM_BUF_ERROR )return ; next_offset = *offset + count;if (next_offset > buf->length) {WARN (1 ,"tpm_buf: read out of boundary\n" ); - buf->flags |=TPM_BUF_BOUNDARY_ERROR ; + buf->flags |=TPM_BUF_ERROR ;return ; }
@@ -242,5 +275,3 @@ u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset)return be32_to_cpu (value); }EXPORT_SYMBOL_GPL (tpm_buf_read_u32); - -
drivers/char/tpm/tpm-dev-common.c +2 -2
@@ -147,7 +147,7 @@ ssize_t tpm_common_read(struct file *file, char __user *buf, rc =copy_to_user (buf, priv->data_buffer + *off, ret_size);if (rc) { -memset (priv->data_buffer,0 ,TPM_BUFSIZE ); +memset (priv->data_buffer,0 ,TPM_BUF_MAX_SIZE ); priv->response_length =0 ; ret_size = -EFAULT ; }else {
@@ -173,7 +173,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,struct file_priv *priv = file->private_data;int ret =0 ; -if (size >TPM_BUFSIZE ) +if (size >TPM_BUF_MAX_SIZE )return -E2BIG ;mutex_lock (&priv->buffer_mutex);
drivers/char/tpm/tpm-dev.h +1 -1
@@ -18,7 +18,7 @@ struct file_priv {bool response_read;bool command_enqueued; -u8 data_buffer[TPM_BUFSIZE ]; +u8 data_buffer[TPM_BUF_MAX_SIZE ]; }; void tpm_common_open(struct file *file, struct tpm_chip *chip,
drivers/char/tpm/tpm-interface.c +2 -2
@@ -100,8 +100,8 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz)if (bufsiz <TPM_HEADER_SIZE )return -EINVAL ; -if (bufsiz >TPM_BUFSIZE ) - bufsiz =TPM_BUFSIZE ; +if (bufsiz >TPM_BUF_MAX_SIZE ) + bufsiz =TPM_BUF_MAX_SIZE ; count =be32_to_cpu (header->length); ordinal =be32_to_cpu (header->ordinal);
drivers/char/tpm/tpm-sysfs.c +10 -10
@@ -32,28 +32,30 @@ struct tpm_readpubek_out {static ssize_t pubek_show (struct device *dev,struct device_attribute *attr,char *buf) { -struct tpm_buf tpm_buf;struct tpm_readpubek_out *out;int i;char *str = buf;struct tpm_chip *chip =to_tpm_chip (dev);char anti_replay[20 ]; + struct tpm_buf *tpm_buf __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL); +if (!tpm_buf) +return -ENOMEM ; +memset (&anti_replay,0 ,sizeof (anti_replay));if (tpm_try_get_ops (chip))return 0 ; -if (tpm_buf_init (&tpm_buf,TPM_TAG_RQU_COMMAND ,TPM_ORD_READPUBEK )) - goto out_ops; - -tpm_buf_append (&tpm_buf, anti_replay,sizeof (anti_replay)); +tpm_buf_init (tpm_buf,TPM_BUF_MAX_SIZE ); +tpm_buf_reset (tpm_buf,TPM_TAG_RQU_COMMAND ,TPM_ORD_READPUBEK ); +tpm_buf_append (tpm_buf, anti_replay,sizeof (anti_replay)); -if (tpm_transmit_cmd (chip, &tpm_buf,READ_PUBEK_RESULT_MIN_BODY_SIZE , +if (tpm_transmit_cmd (chip, tpm_buf,READ_PUBEK_RESULT_MIN_BODY_SIZE ,"attempting to read the PUBEK" )) - goto out_buf; + goto out_ops; - out = (struct tpm_readpubek_out *)&tpm_buf.data[10 ]; + out = (struct tpm_readpubek_out *)&tpm_buf->data[10 ]; str +=sprintf (str, "Algorithm: %4ph\n"
@@ -71,8 +73,6 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,for (i =0 ; i <256 ; i +=16 ) str +=sprintf (str,"%16ph\n" , &out->modulus[i]); -out_buf: -tpm_buf_destroy (&tpm_buf); out_ops:tpm_put_ops (chip);return str - buf;
drivers/char/tpm/tpm.h +1 -2
@@ -32,7 +32,6 @@#endif #define TPM_MINOR 224/* officially assigned */ -#define TPM_BUFSIZE 4096#define TPM_NUM_DEVICES 65536#define TPM_RETRY 50
@@ -224,7 +223,7 @@ enum tpm2_pt_props { TPM2_PT_AUDIT_COUNTER_1 = TPM2_PT_VAR + 20, }; -/* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 +/* 128 bytes is an arbitrary cap. This could be as large as TPM_BUF_MAX_SIZE - 18 * bytes, but 128 is still a relatively large number of random bytes and * anything much bigger causes users of struct tpm_cmd_t to start getting * compiler warnings about stack frame size. */
drivers/char/tpm/tpm1-cmd.c +70 -79
271 lines not on this page · raw message
drivers/char/tpm/tpm2-cmd.c +130 -152
522 lines not on this page · raw message
drivers/char/tpm/tpm2-sessions.c +58 -63
224 lines not on this page · raw message
drivers/char/tpm/tpm2-space.c +18 -26
106 lines not on this page · raw message
drivers/char/tpm/tpm_tis_i2c.c +2 -2
@@ -232,7 +232,7 @@ static int tpm_tis_i2c_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len,int ret;u16 wrote =0 ; -if (len >TPM_BUFSIZE -1 ) +if (len >TPM_BUF_MAX_SIZE -1 )return -EIO ; phy->io_buf[0 ] = reg;
@@ -339,7 +339,7 @@ static int tpm_tis_i2c_probe(struct i2c_client *dev)if (!phy)return -ENOMEM ; - phy->io_buf =devm_kzalloc (&dev->dev,TPM_BUFSIZE ,GFP_KERNEL ); + phy->io_buf =devm_kzalloc (&dev->dev,TPM_BUF_MAX_SIZE ,GFP_KERNEL );if (!phy->io_buf)return -ENOMEM ;
drivers/char/tpm/tpm_vtpm_proxy.c +14 -18
@@ -42,7 +42,7 @@ struct proxy_dev {size_t req_len;/* length of queued TPM request */ size_t resp_len;/* length of queued TPM response */ -u8 buffer[TPM_BUFSIZE ];/* request/response buffer */ +u8 buffer[TPM_BUF_MAX_SIZE ];/* request/response buffer */ struct work_struct work;/* task that retrieves TPM timeouts */ };
@@ -395,40 +395,36 @@ static bool vtpm_proxy_tpm_req_canceled(struct tpm_chip *chip, u8 status)static int vtpm_proxy_request_locality (struct tpm_chip *chip,int locality) { -struct tpm_buf buf;int rc;const struct tpm_header *header;struct proxy_dev *proxy_dev =dev_get_drvdata (&chip->dev); + struct tpm_buf *buf __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL); +if (!buf) +return -ENOMEM ; + +tpm_buf_init (buf,TPM_BUF_MAX_SIZE );if (chip->flags &TPM_CHIP_FLAG_TPM2 ) - rc =tpm_buf_init (&buf,TPM2_ST_SESSIONS , -TPM2_CC_SET_LOCALITY ); +tpm_buf_reset (buf,TPM2_ST_SESSIONS ,TPM2_CC_SET_LOCALITY );else - rc =tpm_buf_init (&buf,TPM_TAG_RQU_COMMAND , -TPM_ORD_SET_LOCALITY ); -if (rc) -return rc; -tpm_buf_append_u8 (&buf, locality); +tpm_buf_reset (buf,TPM_TAG_RQU_COMMAND ,TPM_ORD_SET_LOCALITY ); + +tpm_buf_append_u8 (buf, locality); proxy_dev->state |=STATE_DRIVER_COMMAND ; - rc =tpm_transmit_cmd (chip, &buf,0 ,"attempting to set locality" ); + rc =tpm_transmit_cmd (chip, buf,0 ,"attempting to set locality" ); proxy_dev->state &= ~STATE_DRIVER_COMMAND ; -if (rc <0 ) { - locality = rc; - goto out; - } +if (rc <0 ) +return rc; - header = (const struct tpm_header *)buf.data; + header = (const struct tpm_header *)buf->data; rc =be32_to_cpu (header->return_code);if (rc) locality =-1 ; -out: -tpm_buf_destroy (&buf); -return locality; }
include/linux/tpm.h +15 -13
@@ -367,22 +367,25 @@ struct tpm_header { } __packed;enum tpm_buf_flags { -/* the capacity exceeded: */ -TPM_BUF_OVERFLOW =BIT (0 ), -/* TPM2B format: */ -TPM_BUF_TPM2B =BIT (1 ), -/* read out of boundary: */ -TPM_BUF_BOUNDARY_ERROR =BIT (2 ), +/* TPM2B format */ +TPM_BUF_TPM2B =BIT (1 ), +/* overflow or underrun error */ +TPM_BUF_ERROR =BIT (2 ), }; +#define TPM_BUF_MIN_SIZE 256/* size for stack allocations */ +#define TPM_BUF_MAX_SIZE 4096/* size for heap allocations */ +/* -* 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;u8 handles; +u16 length; +u16 capacity; +u8 data[]; };enum tpm2_object_attributes {
@@ -413,11 +416,10 @@ 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);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);
security/keys/trusted-keys/trusted_tpm1.c +15 -19
@@ -310,9 +310,8 @@ static int TSS_checkhmac2(unsigned char *buffer,* For key specific tpm requests, we will generate and send our * own TPM command packets using the drivers send function. */ -static int trusted_tpm_send (unsigned char *cmd,size_t buflen) +static int trusted_tpm_send (void *cmd,size_t buflen) { -struct tpm_buf buf;int rc;if (!chip)
@@ -322,15 +321,12 @@ static int trusted_tpm_send(unsigned char *cmd, size_t buflen)if (rc)return rc; - buf.flags =0 ; - buf.length = buflen; - buf.data = cmd;dump_tpm_buf (cmd); - rc =tpm_transmit_cmd (chip, &buf,4 ,"sending data" ); + rc =tpm_transmit_cmd (chip, cmd,4 ,"sending data" );dump_tpm_buf (cmd); +/* Convert TPM error to -EPERM. */ if (rc >0 ) -/* TPM error */ rc = -EPERM ;tpm_put_ops (chip);
@@ -624,23 +620,23 @@ static int tpm_unseal(struct tpm_buf *tb,static int key_seal (struct trusted_key_payload *p,struct trusted_key_options *o) { -struct tpm_buf tb;int ret; - ret =tpm_buf_init (&tb,0 ,0 ); -if (ret) -return ret; + struct tpm_buf *tb __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL); +if (!tb) +return -ENOMEM ; + +tpm_buf_init (tb,TPM_BUF_MAX_SIZE );/* include migratable flag at end of sealed key */ p->key[p->key_len] = p->migratable; - ret =tpm_seal (&tb, o->keytype, o->keyhandle, o->keyauth, + ret =tpm_seal (tb, o->keytype, o->keyhandle, o->keyauth, p->key, p->key_len +1 , p->blob, &p->blob_len, o->blobauth, o->pcrinfo, o->pcrinfo_len);if (ret <0 )pr_info ("srkseal failed (%d)\n" , ret); -tpm_buf_destroy (&tb);return ret; }
@@ -650,14 +646,15 @@ static int key_seal(struct trusted_key_payload *p,static int key_unseal (struct trusted_key_payload *p,struct trusted_key_options *o) { -struct tpm_buf tb;int ret; - ret =tpm_buf_init (&tb,0 ,0 ); -if (ret) -return ret; + struct tpm_buf *tb __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL); +if (!tb) +return -ENOMEM ; + +tpm_buf_init (tb,TPM_BUF_MAX_SIZE ); - ret =tpm_unseal (&tb, o->keyhandle, o->keyauth, p->blob, p->blob_len, + ret =tpm_unseal (tb, o->keyhandle, o->keyauth, p->blob, p->blob_len, o->blobauth, p->key, &p->key_len);if (ret <0 )pr_info ("srkunseal failed (%d)\n" , ret);
@@ -665,7 +662,6 @@ static int key_unseal(struct trusted_key_payload *p,/* pull migratable flag out of sealed key */ p->migratable = p->key[--p->key_len]; -tpm_buf_destroy (&tb);return ret; }
security/keys/trusted-keys/trusted_tpm2.c +71 -85
286 lines not on this page · raw message
Signature · 1 line
2.39.5