2024-03-28 10:13:44

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH v6 3/5] crypto: tegra: Add Tegra Security Engine driver

On Tue, Mar 19, 2024 at 01:53:04PM +0530, Akhil R wrote:
>
> +struct tegra_sha_reqctx {
> + struct ahash_request fallback_req;

This doesn't work because ahash_request is dynamically sized.
So you'll end up clobbering the rest of the struct if a fallback
ends up being used.

You should place the fallback_req at the end of the reqctx and set
the reqsize based on the fallback reqsize.

Cheers,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


2024-04-02 12:38:33

by Akhil R

[permalink] [raw]
Subject: RE: [PATCH v6 3/5] crypto: tegra: Add Tegra Security Engine driver

> On Tue, Mar 19, 2024 at 01:53:04PM +0530, Akhil R wrote:
> >
> > +struct tegra_sha_reqctx {
> > + struct ahash_request fallback_req;
>
> This doesn't work because ahash_request is dynamically sized.
> So you'll end up clobbering the rest of the struct if a fallback ends up being used.
>
> You should place the fallback_req at the end of the reqctx and set the reqsize
> based on the fallback reqsize.
>
Should I set the reqsize as below in sha_cra_init()? Seeing this in other crypto drivers.

crypto_ahash_set_reqsize(ahash_tfm,
sizeof(struct tegra_sha_reqctx) +
crypto_ahash_reqsize(ctx->fallback_tfm));

Regards,
Akhil

2024-04-02 12:39:40

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH v6 3/5] crypto: tegra: Add Tegra Security Engine driver

On Tue, Apr 02, 2024 at 12:36:41PM +0000, Akhil R wrote:
>
> Should I set the reqsize as below in sha_cra_init()? Seeing this in other crypto drivers.
>
> crypto_ahash_set_reqsize(ahash_tfm,
> sizeof(struct tegra_sha_reqctx) +
> crypto_ahash_reqsize(ctx->fallback_tfm));

Yes if you places the fallback request at the end of reqctx then
this is the correct reqsize.

Cheers,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt