crypto: api - fix reqsize handling for skciphers and aeads
PATCH 1/1 crypto: api - fix reqsize handling for skciphers and aeads
Commit afddce13ce81d ("crypto: api - Add reqsize to crypto_alg") introduced cra_reqsize field in crypto_alg struct to replace type specific reqsize fields. It looks like this was introduced specifically for ahash and acomp from the commit description as subsequent commits add necessary changes in these alg frameworks.
However, this is being recommended for use in all crypto algs [1] instead of setting reqsize using crypto_*_set_reqsize(). Using cra_reqsize in skcipher and aead algorithms, hence, causes memory corruptions and crashes as the underlying functions in the algorithm framework have not been updated to set the reqsize properly from cra_reqsize. [2]
Add proper set_reqsize calls in the skcipher and aead init functions to properly initialize reqsize for these algorithms in the framework.
[1]: https://lore.kernel.org/linux-crypto/[email protected]/
[2]: https://gist.github.com/Pratham-T/24247446f1faf4b7843e4014d5089f6b
---
Found this while developing TI DTHEv2 crypto driver. I narrowed that these crashes in [2] are due to some upstream change and not my code as the same driver is working fine in our internal 6.12 LTS version (with daily CI builds not showing any regression from crypto subsystem). The *only* change is replacing crypto_skcipher_set_reqsize() with cra_reqsize in algorithms as this patch was introduced after 6.12.
Now, these crashes were not caught earlier because [3] split the in-kernel self-tests into two configs (CRYPTO_SELFTESTS and CRYPTO_SELFTESTS_FULL) which went unnoticed in my local development flow and the CRYPTO_SELFTESTS_FULL config was not enabled till recently. [2] shows after applying this patch, the driver passes all selftests succssfully with CRYPTO_SELFTESTS_FULL=y.
[3]: https://lore.kernel.org/linux-crypto/[email protected]/
--- crypto/aead.c | 1 + crypto/skcipher.c | 2 ++ 2 files changed, 3 insertions(+)
crypto/aead.c +1 -0
@@ -120,6 +120,7 @@ static int crypto_aead_init_tfm(struct crypto_tfm *tfm)struct aead_alg *alg =crypto_aead_alg (aead);crypto_aead_set_flags (aead,CRYPTO_TFM_NEED_KEY ); +crypto_aead_set_reqsize (aead,crypto_tfm_alg_reqsize (tfm)); aead->authsize = alg->maxauthsize;
crypto/skcipher.c +2 -0
@@ -294,6 +294,8 @@ static int crypto_skcipher_init_tfm(struct crypto_tfm *tfm)return crypto_init_lskcipher_ops_sg (tfm); } +crypto_skcipher_set_reqsize (skcipher,crypto_tfm_alg_reqsize (tfm)); +if (alg->exit) skcipher->base.exit = crypto_skcipher_exit_tfm;
Signature · 1 line
2.43.0
Herbert Xu
maintainerQuoted 37 lines · T Pratham
Commit
afddce13ce81d("crypto: api - Add reqsize tocrypto_alg") introducedcra_reqsizefield incrypto_algstruct to replace type specific reqsize fields. It looks like this was introduced specifically for ahash and acomp from the commit description as subsequent commits add necessary changes in these alg frameworks.However, this is being recommended for use in all crypto algs [1] instead of setting reqsize using crypto_*_set_reqsize(). Using
cra_reqsizein skcipher and aead algorithms, hence, causes memory corruptions and crashes as the underlying functions in the algorithm framework have not been updated to set the reqsize properly fromcra_reqsize. [2]Add proper
set_reqsizecalls in the skcipher and aead init functions to properly initialize reqsize for these algorithms in the framework.[1]: https://lore.kernel.org/linux-crypto/[email protected]/
[2]: https://gist.github.com/Pratham-T/24247446f1faf4b7843e4014d5089f6bFixes afddce13ce81d ("crypto: api - Add reqsize to crypto_alg")Signed-off-by T Pratham <[email protected]>---
Found this while developing TI DTHEv2 crypto driver. I narrowed that these crashes in [2] are due to some upstream change and not my code as the same driver is working fine in our internal 6.12 LTS version (with daily CI builds not showing any regression from crypto subsystem). The *only* change is replacing
crypto_skcipher_set_reqsize()withcra_reqsizein algorithms as this patch was introduced after 6.12.Now, these crashes were not caught earlier because [3] split the in-kernel self-tests into two configs (
CRYPTO_SELFTESTSandCRYPTO_SELFTESTS_FULL) which went unnoticed in my local development flow and theCRYPTO_SELFTESTS_FULLconfig was not enabled till recently. [2] shows after applying this patch, the driver passes all selftests succssfully with CRYPTO_SELFTESTS_FULL=y.
Quoted 5 lines
[3]: https://lore.kernel.org/linux-crypto/[email protected]/
--- crypto/aead.c | 1 + crypto/skcipher.c | 2 ++ 2 files changed, 3 insertions(+)
Thanks. I've applied the skcipher part of your patch.
Please repost the AEAD part as a separate patch.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 44 lines · Herbert Xu
Quoted 37 lines · T Pratham
Commit
afddce13ce81d("crypto: api - Add reqsize tocrypto_alg") introducedcra_reqsizefield incrypto_algstruct to replace type specific reqsize fields. It looks like this was introduced specifically for ahash and acomp from the commit description as subsequent commits add necessary changes in these alg frameworks.However, this is being recommended for use in all crypto algs [1] instead of setting reqsize using crypto_*_set_reqsize(). Using
cra_reqsizein skcipher and aead algorithms, hence, causes memory corruptions and crashes as the underlying functions in the algorithm framework have not been updated to set the reqsize properly fromcra_reqsize. [2]Add proper
set_reqsizecalls in the skcipher and aead init functions to properly initialize reqsize for these algorithms in the framework.[1]: https://lore.kernel.org/linux-crypto/[email protected]/
[2]: https://gist.github.com/Pratham-T/24247446f1faf4b7843e4014d5089f6bFixes afddce13ce81d ("crypto: api - Add reqsize to crypto_alg")Signed-off-by T Pratham <[email protected]>---
Found this while developing TI DTHEv2 crypto driver. I narrowed that these crashes in [2] are due to some upstream change and not my code as the same driver is working fine in our internal 6.12 LTS version (with daily CI builds not showing any regression from crypto subsystem). The *only* change is replacing
crypto_skcipher_set_reqsize()withcra_reqsizein algorithms as this patch was introduced after 6.12.Now, these crashes were not caught earlier because [3] split the in-kernel self-tests into two configs (
CRYPTO_SELFTESTSandCRYPTO_SELFTESTS_FULL) which went unnoticed in my local development flow and theCRYPTO_SELFTESTS_FULLconfig was not enabled till recently. [2] shows after applying this patch, the driver passes all selftests succssfully with CRYPTO_SELFTESTS_FULL=y.Quoted 5 lines
[3]: https://lore.kernel.org/linux-crypto/[email protected]/
--- crypto/aead.c | 1 + crypto/skcipher.c | 2 ++ 2 files changed, 3 insertions(+)
Quoted 5 lines
Thanks. I've applied the skcipher part of your patch.
Please repost the AEAD part as a separate patch.
Cheers,
Sent.
https://lore.kernel.org/linux-crypto/[email protected]/T/#u
Signature · 2 lines
Regards T Pratham <[email protected]>