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

Submitted by Vincent on March 23, 2017, 3:40 p.m.

Details

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

Commit Message

Vincent March 23, 2017, 3:40 p.m.
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>
---


Hi,

I saw that in Linux next-20170323.

Best regards,

Vincent.


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

Patch hide | download patch | download 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];