Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: aead - pass instance to crypto_grab_aead()

Initializing a crypto_aead_spawn currently requires:

1. Set spawn->base.inst to point to the instance.
2. Call crypto_grab_aead().

But there's no reason for these steps to be separate, and in fact this
unneeded complication has caused at least one bug, the one fixed by
commit 6db43410179b ("crypto: adiantum - initialize crypto_spawn::inst")

So just make crypto_grab_aead() take the instance as an argument.

To keep the function calls from getting too unwieldy due to this extra
argument, also introduce a 'mask' variable into the affected places
which weren't already using one.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
cd900f0c b9f76ddd

+29 -28
+4 -2
crypto/aead.c
··· 207 207 .tfmsize = offsetof(struct crypto_aead, base), 208 208 }; 209 209 210 - int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name, 211 - u32 type, u32 mask) 210 + int crypto_grab_aead(struct crypto_aead_spawn *spawn, 211 + struct crypto_instance *inst, 212 + const char *name, u32 type, u32 mask) 212 213 { 214 + spawn->base.inst = inst; 213 215 spawn->base.frontend = &crypto_aead_type; 214 216 return crypto_grab_spawn(&spawn->base, name, type, mask); 215 217 }
+5 -3
crypto/ccm.c
··· 734 734 struct rtattr **tb) 735 735 { 736 736 struct crypto_attr_type *algt; 737 + u32 mask; 737 738 struct aead_instance *inst; 738 739 struct crypto_aead_spawn *spawn; 739 740 struct aead_alg *alg; ··· 748 747 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) 749 748 return -EINVAL; 750 749 750 + mask = crypto_requires_sync(algt->type, algt->mask); 751 + 751 752 ccm_name = crypto_attr_alg_name(tb[1]); 752 753 if (IS_ERR(ccm_name)) 753 754 return PTR_ERR(ccm_name); ··· 759 756 return -ENOMEM; 760 757 761 758 spawn = aead_instance_ctx(inst); 762 - crypto_set_aead_spawn(spawn, aead_crypto_instance(inst)); 763 - err = crypto_grab_aead(spawn, ccm_name, 0, 764 - crypto_requires_sync(algt->type, algt->mask)); 759 + err = crypto_grab_aead(spawn, aead_crypto_instance(inst), 760 + ccm_name, 0, mask); 765 761 if (err) 766 762 goto out_free_inst; 767 763
+2 -2
crypto/cryptd.c
··· 865 865 ctx = aead_instance_ctx(inst); 866 866 ctx->queue = queue; 867 867 868 - crypto_set_aead_spawn(&ctx->aead_spawn, aead_crypto_instance(inst)); 869 - err = crypto_grab_aead(&ctx->aead_spawn, name, type, mask); 868 + err = crypto_grab_aead(&ctx->aead_spawn, aead_crypto_instance(inst), 869 + name, type, mask); 870 870 if (err) 871 871 goto out_free_inst; 872 872
+1 -2
crypto/essiv.c
··· 500 500 ictx = crypto_instance_ctx(inst); 501 501 502 502 /* AEAD cipher, e.g., "authenc(hmac(sha256),cbc(aes))" */ 503 - crypto_set_aead_spawn(&ictx->u.aead_spawn, inst); 504 - err = crypto_grab_aead(&ictx->u.aead_spawn, 503 + err = crypto_grab_aead(&ictx->u.aead_spawn, inst, 505 504 inner_cipher_name, 0, mask); 506 505 if (err) 507 506 goto out_free_inst;
+10 -6
crypto/gcm.c
··· 856 856 struct rtattr **tb) 857 857 { 858 858 struct crypto_attr_type *algt; 859 + u32 mask; 859 860 struct aead_instance *inst; 860 861 struct crypto_aead_spawn *spawn; 861 862 struct aead_alg *alg; ··· 870 869 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) 871 870 return -EINVAL; 872 871 872 + mask = crypto_requires_sync(algt->type, algt->mask); 873 + 873 874 ccm_name = crypto_attr_alg_name(tb[1]); 874 875 if (IS_ERR(ccm_name)) 875 876 return PTR_ERR(ccm_name); ··· 881 878 return -ENOMEM; 882 879 883 880 spawn = aead_instance_ctx(inst); 884 - crypto_set_aead_spawn(spawn, aead_crypto_instance(inst)); 885 - err = crypto_grab_aead(spawn, ccm_name, 0, 886 - crypto_requires_sync(algt->type, algt->mask)); 881 + err = crypto_grab_aead(spawn, aead_crypto_instance(inst), 882 + ccm_name, 0, mask); 887 883 if (err) 888 884 goto out_free_inst; 889 885 ··· 1089 1087 struct rtattr **tb) 1090 1088 { 1091 1089 struct crypto_attr_type *algt; 1090 + u32 mask; 1092 1091 struct aead_instance *inst; 1093 1092 struct crypto_aead_spawn *spawn; 1094 1093 struct aead_alg *alg; ··· 1104 1101 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) 1105 1102 return -EINVAL; 1106 1103 1104 + mask = crypto_requires_sync(algt->type, algt->mask); 1105 + 1107 1106 ccm_name = crypto_attr_alg_name(tb[1]); 1108 1107 if (IS_ERR(ccm_name)) 1109 1108 return PTR_ERR(ccm_name); ··· 1116 1111 1117 1112 ctx = aead_instance_ctx(inst); 1118 1113 spawn = &ctx->aead; 1119 - crypto_set_aead_spawn(spawn, aead_crypto_instance(inst)); 1120 - err = crypto_grab_aead(spawn, ccm_name, 0, 1121 - crypto_requires_sync(algt->type, algt->mask)); 1114 + err = crypto_grab_aead(spawn, aead_crypto_instance(inst), 1115 + ccm_name, 0, mask); 1122 1116 if (err) 1123 1117 goto out_free_inst; 1124 1118
+2 -2
crypto/geniv.c
··· 64 64 /* Ignore async algorithms if necessary. */ 65 65 mask |= crypto_requires_sync(algt->type, algt->mask); 66 66 67 - crypto_set_aead_spawn(spawn, aead_crypto_instance(inst)); 68 - err = crypto_grab_aead(spawn, name, type, mask); 67 + err = crypto_grab_aead(spawn, aead_crypto_instance(inst), 68 + name, type, mask); 69 69 if (err) 70 70 goto err_free_inst; 71 71
+2 -3
crypto/pcrypt.c
··· 258 258 if (!ctx->psdec) 259 259 goto out_free_psenc; 260 260 261 - crypto_set_aead_spawn(&ctx->spawn, aead_crypto_instance(inst)); 262 - 263 - err = crypto_grab_aead(&ctx->spawn, name, 0, 0); 261 + err = crypto_grab_aead(&ctx->spawn, aead_crypto_instance(inst), 262 + name, 0, 0); 264 263 if (err) 265 264 goto out_free_psdec; 266 265
+3 -8
include/crypto/internal/aead.h
··· 81 81 return container_of(req, struct aead_request, base); 82 82 } 83 83 84 - static inline void crypto_set_aead_spawn( 85 - struct crypto_aead_spawn *spawn, struct crypto_instance *inst) 86 - { 87 - crypto_set_spawn(&spawn->base, inst); 88 - } 89 - 90 - int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name, 91 - u32 type, u32 mask); 84 + int crypto_grab_aead(struct crypto_aead_spawn *spawn, 85 + struct crypto_instance *inst, 86 + const char *name, u32 type, u32 mask); 92 87 93 88 static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn) 94 89 {