public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] tpm: silence an array overflow warning
@ 2017-02-03 10:30 Dan Carpenter
  2017-02-03 18:11 ` Jarkko Sakkinen
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2017-02-03 10:30 UTC (permalink / raw)
  To: Peter Huewe, Nayna Jain
  Cc: Marcel Selhorst, Jarkko Sakkinen, Jason Gunthorpe, tpmdd-devel,
	kernel-janitors

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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 423938e8570f..087748b8264f 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -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++;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [patch] tpm: silence an array overflow warning
  2017-02-03 10:30 [patch] tpm: silence an array overflow warning Dan Carpenter
@ 2017-02-03 18:11 ` Jarkko Sakkinen
  2017-02-06  9:20   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Jarkko Sakkinen @ 2017-02-03 18:11 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Peter Huewe, Nayna Jain, Marcel Selhorst, Jason Gunthorpe,
	tpmdd-devel, kernel-janitors

On Fri, Feb 03, 2017 at 01:30:40PM +0300, Dan Carpenter wrote:
> 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.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

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

/Jarkko

> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 423938e8570f..087748b8264f 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -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++;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] tpm: silence an array overflow warning
  2017-02-03 18:11 ` Jarkko Sakkinen
@ 2017-02-06  9:20   ` Dan Carpenter
  2017-02-06 14:15     ` Jarkko Sakkinen
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2017-02-06  9:20 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: Peter Huewe, Nayna Jain, Marcel Selhorst, Jason Gunthorpe,
	tpmdd-devel, kernel-janitors

On Fri, Feb 03, 2017 at 08:11:20PM +0200, Jarkko Sakkinen wrote:
> On Fri, Feb 03, 2017 at 01:30:40PM +0300, Dan Carpenter wrote:
> > 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.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Thank you, good catch! Do you mind if I squash this.
> 

Not at all.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] tpm: silence an array overflow warning
  2017-02-06  9:20   ` Dan Carpenter
@ 2017-02-06 14:15     ` Jarkko Sakkinen
  0 siblings, 0 replies; 4+ messages in thread
From: Jarkko Sakkinen @ 2017-02-06 14:15 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
	tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Mon, Feb 06, 2017 at 12:20:07PM +0300, Dan Carpenter wrote:
> On Fri, Feb 03, 2017 at 08:11:20PM +0200, Jarkko Sakkinen wrote:
> > On Fri, Feb 03, 2017 at 01:30:40PM +0300, Dan Carpenter wrote:
> > > 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.
> > > 
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-02-06 14:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-03 10:30 [patch] tpm: silence an array overflow warning Dan Carpenter
2017-02-03 18:11 ` Jarkko Sakkinen
2017-02-06  9:20   ` Dan Carpenter
2017-02-06 14:15     ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox