Message ID | 1452707524-7695-1-git-send-email-festevam@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Herbert Xu |
Headers | show |
On Wed, Jan 13, 2016 at 03:52:02PM -0200, Fabio Estevam wrote: > From: Fabio Estevam <fabio.estevam@nxp.com> > > Based on commit 434b421241f2d0 ("crypto: caam - avoid needlessly saving and > restoring caam_hash_ctx") from Russell King. > > When exporting and importing the hash state, we will only export and > import into hashes which share the same struct crypto_ahash pointer. > (See hash_accept->af_alg_accept->hash_accept_parent.) > > This means that saving the sahara_ctx structure on export, and > restoring it on import is a waste of resources. So, remove this code. > > Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com> Very good. Not only is it a waste, it's a gaping security hole because modifying the tfm from import will corrupt it. But this is not enough, you're still copying things like the mutex which should not be copied but instead should be reinitialised in import. Thanks,
Hi Herbert, On Mon, Jan 25, 2016 at 12:07 PM, Herbert Xu <herbert@gondor.apana.org.au> wrote: > Very good. Not only is it a waste, it's a gaping security hole > because modifying the tfm from import will corrupt it. > > But this is not enough, you're still copying things like the mutex > which should not be copied but instead should be reinitialised in > import. So import() will look like this? static int sahara_sha_import(struct ahash_request *req, const void *in) { struct sahara_sha_reqctx *rctx = ahash_request_ctx(req); mutex_init(&rctx->mutex); memcpy(rctx, in, sizeof(struct sahara_sha_reqctx)); return 0; } Thanks -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Feb 02, 2016 at 11:41:56AM -0200, Fabio Estevam wrote: > > static int sahara_sha_import(struct ahash_request *req, const void *in) > { > struct sahara_sha_reqctx *rctx = ahash_request_ctx(req); > > mutex_init(&rctx->mutex); > memcpy(rctx, in, sizeof(struct sahara_sha_reqctx)); Preferably you shouldn't include the mutex in the exported state at all. Cheers,
diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c index f68c24a..53c7a9a 100644 --- a/drivers/crypto/sahara.c +++ b/drivers/crypto/sahara.c @@ -1155,26 +1155,18 @@ static int sahara_sha_digest(struct ahash_request *req) static int sahara_sha_export(struct ahash_request *req, void *out) { - struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); - struct sahara_ctx *ctx = crypto_ahash_ctx(ahash); struct sahara_sha_reqctx *rctx = ahash_request_ctx(req); - memcpy(out, ctx, sizeof(struct sahara_ctx)); - memcpy(out + sizeof(struct sahara_sha_reqctx), rctx, - sizeof(struct sahara_sha_reqctx)); + memcpy(out, rctx, sizeof(struct sahara_sha_reqctx)); return 0; } static int sahara_sha_import(struct ahash_request *req, const void *in) { - struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); - struct sahara_ctx *ctx = crypto_ahash_ctx(ahash); struct sahara_sha_reqctx *rctx = ahash_request_ctx(req); - memcpy(ctx, in, sizeof(struct sahara_ctx)); - memcpy(rctx, in + sizeof(struct sahara_sha_reqctx), - sizeof(struct sahara_sha_reqctx)); + memcpy(rctx, in, sizeof(struct sahara_sha_reqctx)); return 0; }