]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tpm: Check outgoing command size
authorSimon Glass <sjg@chromium.org>
Fri, 14 May 2021 01:39:29 +0000 (19:39 -0600)
committerTom Rini <trini@konsulko.com>
Thu, 15 Jul 2021 22:42:05 +0000 (18:42 -0400)
In tpm_sendrecv_command() the command buffer is passed in. If a mistake is
somehow made in setting this up, the size could be out of range. Add a
sanity check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 331152)
lib/tpm-common.c

index 4277846fdd06291e3bb226112ea32a4995d9f35c..82ffdc5341bce21aecbd088d1921b73f93f15f2c 100644 (file)
@@ -176,6 +176,11 @@ u32 tpm_sendrecv_command(struct udevice *dev, const void *command,
        }
 
        size = tpm_command_size(command);
+
+       /* sanity check, which also helps coverity */
+       if (size > COMMAND_BUFFER_SIZE)
+               return log_msg_ret("size", -E2BIG);
+
        log_debug("TPM request [size:%d]: ", size);
        for (i = 0; i < size; i++)
                log_debug("%02x ", ((u8 *)command)[i]);