[tpmdd-devel,linux-next] tmp2: fix an off by one bug
diff mbox

Message ID 20170323154029.27816-1-vincent.stehle@laposte.net
State New
Headers show

Commit Message

Vincent Stehlé March 23, 2017, 3:40 p.m. UTC
In tpm2_map_to_phandle(), avoid the case where i equals
ARRAY_SIZE(space->context_tbl) and we then access space->context_tbl[i].

This fixes the following smatch error:

  drivers/char/tpm/tpm2-space.c:232 tpm2_map_to_phandle() error: buffer overflow 'space->context_tbl' 3 <= 3

Fixes: 5f6b4fbc12c8fc97 ("tpm: infrastructure for TPM spaces")
Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net>
Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>


I saw that in Linux next-20170323.

Best regards,


 drivers/char/tpm/tpm2-space.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff mbox

diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
index d36d81e07076..009934269514 100644
--- a/drivers/char/tpm/tpm2-space.c
+++ b/drivers/char/tpm/tpm2-space.c
@@ -229,7 +229,7 @@  static bool tpm2_map_to_phandle(struct tpm_space *space, void *handle)
 	int i;
 	i = 0xFFFFFF - (vhandle & 0xFFFFFF);
-	if (i > ARRAY_SIZE(space->context_tbl) || !space->context_tbl[i])
+	if (i >= ARRAY_SIZE(space->context_tbl) || !space->context_tbl[i])
 		return false;
 	phandle = space->context_tbl[i];