[PATCH 1/3] crypto: Fix the pointer voodoo in unaligned ahash

Marek Vasut marex at denx.de
Sun Feb 9 01:15:46 EST 2014


On Sunday, February 09, 2014 at 02:18:56 AM, Herbert Xu wrote:
> On Tue, Jan 14, 2014 at 01:35:50PM -0600, Tom Lendacky wrote:
> > On Tuesday, January 14, 2014 06:33:47 PM Marek Vasut wrote:
> > > Add documentation for the pointer voodoo that is happening in
> > > crypto/ahash.c in ahash_op_unaligned(). This code is quite confusing,
> > > so add a beefy chunk of documentation.
> > > 
> > > Moreover, make sure the mangled request is completely restored after
> > > finishing this unaligned operation. This means restoring all of
> > > .result, .priv, .base.data and .base.complete .
> > > 
> > > Also, remove the crypto_completion_t complete = ... line present in the
> > > ahash_op_unaligned_done() function. This type actually declares a
> > > function pointer, which is very confusing.
> > > 
> > > Finally, yet very important nonetheless, make sure the req->priv is
> > > free()'d only after the original request is restored in
> > > ahash_op_unaligned_done(). The req->priv data must not be free()'d
> > > before that in ahash_op_unaligned_finish(), since we would be
> > > accessing previously free()'d data in ahash_op_unaligned_done() and
> > > cause corruption.
> > > 
> > > Signed-off-by: Marek Vasut <marex at denx.de>
> > > Cc: David S. Miller <davem at davemloft.net>
> > > Cc: Fabio Estevam <fabio.estevam at freescale.com>
> > > Cc: Herbert Xu <herbert at gondor.apana.org.au>
> > > Cc: Shawn Guo <shawn.guo at linaro.org>
> > > Cc: Tom Lendacky <thomas.lendacky at amd.com>
> > > ---
> > > 
> > >  crypto/ahash.c | 65
> > >  ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file
> > >  changed, 54 insertions(+), 11 deletions(-)
> > > 
> > > diff --git a/crypto/ahash.c b/crypto/ahash.c
> > > index a92dc38..5ca8ede 100644
> > > --- a/crypto/ahash.c
> > > +++ b/crypto/ahash.c
> > > @@ -29,6 +29,7 @@
> > > 
> > >  struct ahash_request_priv {
> > >  
> > >  	crypto_completion_t complete;
> > >  	void *data;
> > > 
> > > +	void *priv;
> > > 
> > >  	u8 *result;
> > >  	void *ubuf[] CRYPTO_MINALIGN_ATTR;
> > >  
> > >  };
> > > 
> > > @@ -200,23 +201,38 @@ static void ahash_op_unaligned_finish(struct
> > > ahash_request *req, int err)
> > > 
> > >  	if (!err)
> > >  	
> > >  		memcpy(priv->result, req->result,
> > >  		
> > >  		       crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
> > > 
> > > -
> > > -	kzfree(priv);
> > 
> > You can't move/remove this kzfree since a synchronous operation will not
> > take the ahash_op_unaligned_done path.  A synchronous operation will
> > never return -EINPROGRESS and the effect will be to never free the priv
> > structure.
> 
> Marek, did you have a chance to address this?

Hi,

it's in the pipeline, I'm just overloaded. We missed a MW for this, right ? :-(



More information about the linux-arm-kernel mailing list