Skip to content

Commit e52432e

Browse files
committed
tpm: vtpm_proxy: Check length to avoid compiler warning
When building with -Warray-bounds under GCC 11.2, this warning was emitted: In function 'memset', inlined from 'vtpm_proxy_fops_read' at drivers/char/tpm/tpm_vtpm_proxy.c:102:2: ./include/linux/fortify-string.h:43:33: warning: '__builtin_memset' pointer overflow between offset 164 and size [2147483648, 4294967295] [-Warray-bounds] 43 | #define __underlying_memset __builtin_memset | ^ This warning appears to be triggered due to the "count < len" check in vtpm_proxy_fops_read() splitting the CFG[1], and the compiler attempting to reason about the possible value range in len compared to the buffer size. In order to silence this warning, and to keep this code robust if the use of proxy_dev->req_len ever changes in the future, explicitly check the size of len before reaching the memset(). [1] https://lore.kernel.org/lkml/CAG48ez1iTF9KegKJrW5a3WzXgCPZJ73nS2_e5esKJRppdzvv8g@mail.gmail.com Cc: Peter Huewe <peterhuewe@gmx.de> Cc: Jarkko Sakkinen <jarkko@kernel.org> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: linux-integrity@vger.kernel.org Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Link: https://lore.kernel.org/lkml/4b59d305-6858-1514-751a-37853ad777be@linux.ibm.com Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20220119184354.3367603-1-keescook@chromium.org
1 parent 545c272 commit e52432e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/char/tpm/tpm_vtpm_proxy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static ssize_t vtpm_proxy_fops_read(struct file *filp, char __user *buf,
9191

9292
len = proxy_dev->req_len;
9393

94-
if (count < len) {
94+
if (count < len || len > sizeof(proxy_dev->buffer)) {
9595
mutex_unlock(&proxy_dev->buf_lock);
9696
pr_debug("Invalid size in recv: count=%zd, req_len=%zd\n",
9797
count, len);

0 commit comments

Comments
 (0)