diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2015-11-22 17:56:53 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2015-11-23 22:54:33 -0500 |
commit | b82bc5109e8366d5fb9cb9015e1c6d3e187de369 (patch) | |
tree | 751457068537756aea62776eefa50a8ebbcc8c6e | |
parent | 7bf7738b1ac09fe7714eb844aa41965ceca8885d (diff) | |
download | seabios-hppa-b82bc5109e8366d5fb9cb9015e1c6d3e187de369.zip seabios-hppa-b82bc5109e8366d5fb9cb9015e1c6d3e187de369.tar.gz seabios-hppa-b82bc5109e8366d5fb9cb9015e1c6d3e187de369.tar.bz2 |
tpm: Avoid scatter-gather copying in build_and_send_cmd()
Setup the tpm hardware request in a linear area of memory.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | src/tcgbios.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/tcgbios.c b/src/tcgbios.c index 44d7d87..6efa08b 100644 --- a/src/tcgbios.c +++ b/src/tcgbios.c @@ -332,33 +332,30 @@ build_and_send_cmd(u8 locty, u32 ordinal, const u8 *append, u32 append_size, u8 *resbuffer, u32 return_size, u32 *returnCode, enum tpmDurationType to_t) { - u32 rc; + struct { + struct tpm_req_header trqh; + u8 cmd[20]; + } PACKED req = { + .trqh.tag = cpu_to_be16(TPM_TAG_RQU_CMD), + .trqh.totlen = cpu_to_be32(TPM_REQ_HEADER_SIZE + append_size), + .trqh.ordinal = cpu_to_be32(ordinal), + }; u8 obuffer[64]; - struct tpm_req_header trqh; struct tpm_rsp_header *trsh = (struct tpm_rsp_header *)obuffer; - struct iovec iovec[3] = {{ 0 }}; u32 obuffer_len = sizeof(obuffer); + memset(obuffer, 0x0, sizeof(obuffer)); - if (return_size > sizeof(obuffer)) { - dprintf(DEBUG_tcg, "TCGBIOS: size of requested response too big."); + if (return_size > sizeof(obuffer) || append_size > sizeof(req.cmd)) { + warn_internalerror(); return TCG_FIRMWARE_ERROR; } + if (append_size) + memcpy(req.cmd, append, append_size); - trqh.tag = cpu_to_be16(TPM_TAG_RQU_CMD); - trqh.totlen = cpu_to_be32(TPM_REQ_HEADER_SIZE + append_size); - trqh.ordinal = cpu_to_be32(ordinal); - - iovec[0].data = &trqh; - iovec[0].length = TPM_REQ_HEADER_SIZE; - - if (append_size) { - iovec[1].data = append; - iovec[1].length = append_size; - } - - memset(obuffer, 0x0, sizeof(obuffer)); - - rc = transmit(locty, iovec, obuffer, &obuffer_len, to_t); + struct iovec iovec[2] = {{ 0 }}; + iovec[0].data = &req; + iovec[0].length = TPM_REQ_HEADER_SIZE + append_size; + u32 rc = transmit(locty, iovec, obuffer, &obuffer_len, to_t); if (rc) return rc; |