Skip to contentSkip to conversation

tpm: silence an array overflow warning

PATCH In review Dan Carpenter 2 participants 4 messages Feb 3, 2017 – Feb 6, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm: silence an array overflow warning

We should check that we're within bounds first before checking that "chip->active_banks[i] != TPM2_ALG_ERROR" so I've re-ordered the two checks.

drivers/char/tpm/tpm-interface.c +2 -2
index 423938e8570f..087748b8264f 100644
@@ -800,8 +800,8 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
 	if (chip->flags & TPM_CHIP_FLAG_TPM2) {
 		memset(digest_list, 0, sizeof(digest_list));
 
-		for (i = 0; chip->active_banks[i] != TPM2_ALG_ERROR &&
-		     i < ARRAY_SIZE(chip->active_banks); i++) {
+		for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
+			    chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
 			digest_list[i].alg_id = chip->active_banks[i];
 			memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
 			count++;
#1 lore raw
Quoted 5 lines · Dan Carpenter

We should check that we're within bounds first before checking that "chip->active_banks[i] != TPM2_ALG_ERROR" so I've re-ordered the two checks.

Thank you, good catch! Do you mind if I squash this.

/Jarkko

Quoted 16 lines
drivers/char/tpm/tpm-interface.c +2 -2
index 423938e8570f..087748b8264f 100644
@@ -800,8 +800,8 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
 	if (chip->flags & TPM_CHIP_FLAG_TPM2) {
 		memset(digest_list, 0, sizeof(digest_list));
 
-		for (i = 0; chip->active_banks[i] != TPM2_ALG_ERROR &&
-		     i < ARRAY_SIZE(chip->active_banks); i++) {
+		for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
+			    chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
 			digest_list[i].alg_id = chip->active_banks[i];
 			memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
 			count++;
#2 lore raw
Quoted 9 lines · Jarkko Sakkinen
Quoted 5 lines · Dan Carpenter

We should check that we're within bounds first before checking that "chip->active_banks[i] != TPM2_ALG_ERROR" so I've re-ordered the two checks.

Thank you, good catch! Do you mind if I squash this.

Not at all.

regards,
dan carpenter

#3 lore raw
Quoted 8 lines · Dan Carpenter
Quoted 7 lines · Jarkko Sakkinen
Quoted 5 lines · Dan Carpenter

We should check that we're within bounds first before checking that "chip->active_banks[i] != TPM2_ALG_ERROR" so I've re-ordered the two checks.

Quoted 7 lines
Quoted 2 lines

Thank you, good catch! Do you mind if I squash this.

Not at all.

regards,
dan carpenter

Already went as a separate commit in a pull request to James :-)

/Jarkko