]> xenbits.xensource.com Git - seabios.git/commitdiff
tpm: Avoid scatter-gather copying in build_and_send_cmd()
authorKevin O'Connor <kevin@koconnor.net>
Sun, 22 Nov 2015 22:56:53 +0000 (17:56 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Tue, 24 Nov 2015 03:54:33 +0000 (22:54 -0500)
Setup the tpm hardware request in a linear area of memory.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/tcgbios.c

index 44d7d87b69d18021aa0dce4f4139396cb55b3147..6efa08b31a422cbfe6e484ef58cfa3adfa8705b1 100644 (file)
@@ -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;