Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1472082

Re: [PATCH] tpm: fix a race condition in tpm2_unseal_trusted()

From Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Newsgroups linux.kernel
Subject Re: [PATCH] tpm: fix a race condition in tpm2_unseal_trusted()
Date 2016-08-29 21:50 +0200
Message-ID <sbAJb-34a-3@gated-at.bofh.it> (permalink)
References <sb1V8-6BZ-21@gated-at.bofh.it> <sbdtg-5lr-3@gated-at.bofh.it> <sbwFz-yc-11@gated-at.bofh.it> <sbApQ-2WW-11@gated-at.bofh.it>
Organization Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo

Show all headers | View raw


On Mon, Aug 29, 2016 at 01:21:10PM -0600, Jason Gunthorpe wrote:
> On Mon, Aug 29, 2016 at 06:25:21PM +0300, Jarkko Sakkinen wrote:
> > On Sun, Aug 28, 2016 at 12:51:49PM -0600, Jason Gunthorpe wrote:
> > > On Sun, Aug 28, 2016 at 08:36:52AM +0200, Jarkko Sakkinen wrote:
> > > >  
> > > > @@ -576,7 +576,8 @@ static int tpm2_load(struct tpm_chip *chip,
> > > >  		goto out;
> > > >  	}
> > > >  
> > > > -	rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, "loading blob");
> > > > +	rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, TPM_TRANSMIT_UNLOCKED,
> > > > +			      "loading blob");
> > > 
> > > I still don't like this, required mutex's should not be split outside the
> > > function that needs them without more a more obvious indication:
> > > 
> > > > +	mutex_lock(&chip->tpm_mutex);
> > > >  	rc = tpm2_load(chip, payload, options, &blob_handle);
> > > >  	if (rc)
> > > > -		return rc;
> > > 
> > > I recommend you stick with the idiom and do this:
> > > 
> > >         mutex_lock(&chip->tpm_mutex);
> > >   	rc = tpm2_load(chip, payload, options, &blob_handle, TPM_TRANSMIT_UNLOCKED);
> > > 
> > > Which makes it easy to see we are doing it right everywhere.
> > 
> > Why consume stack for unnecessary stuff? This is a static function. For
> > me this sounds like cutting hairs really.
> 
> Well, tpm2_load looks like any other normal command that would grab
> the mutex, so something has to be done to indicate to the reader it is
> the unlocked version.
> 
> I wouldn't worry about the stack, the compiler will inline that away
> anyhow.
> 
> > One thing that would improve readability would be to rename internal
> > functions tpm2_load and tpm2_unseal to tpm2_load_cmd and tpm2_unseal_cmd
> > in order to underline that they are command wrappers and not to mix with
> > tpm2_unseal_trusted().
> 
> That seems reasonable as well, as long as all _cmd varients are unlocked.

I think this more reasonable argument for your proposal than previous
ones for the flags parameter. Or maybe you had this argument in earlier
responses but I just failed to decipher it.

I can buy this.

> Jason

/Jarkko

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] tpm: fix a race condition in tpm2_unseal_trusted() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2016-08-28 08:40 +0200
  Re: [PATCH] tpm: fix a race condition in tpm2_unseal_trusted() Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-08-28 21:00 +0200
    Re: [PATCH] tpm: fix a race condition in tpm2_unseal_trusted() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2016-08-29 17:30 +0200
      Re: [PATCH] tpm: fix a race condition in tpm2_unseal_trusted() Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-08-29 21:30 +0200
        Re: [PATCH] tpm: fix a race condition in tpm2_unseal_trusted() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2016-08-29 21:50 +0200
          Re: [PATCH] tpm: fix a race condition in tpm2_unseal_trusted() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2016-08-29 22:10 +0200
            Re: [PATCH] tpm: fix a race condition in tpm2_unseal_trusted() Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-08-29 22:10 +0200

csiph-web