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

[CRYPTO] gcm: Fix request context alignment

This patch fixes the request context alignment so that it is actually
aligned to the value required by the algorithm.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+14 -7
+14 -7
crypto/gcm.c
··· 43 43 struct ablkcipher_request abreq; 44 44 }; 45 45 46 + static inline struct crypto_gcm_req_priv_ctx *crypto_gcm_reqctx( 47 + struct aead_request *req) 48 + { 49 + unsigned long align = crypto_aead_alignmask(crypto_aead_reqtfm(req)); 50 + 51 + return (void *)PTR_ALIGN((u8 *)aead_request_ctx(req), align + 1); 52 + } 53 + 46 54 static void crypto_gcm_ghash_init(struct crypto_gcm_ghash_ctx *ctx, u32 flags, 47 55 struct gf128mul_4k *gf128) 48 56 { ··· 232 224 { 233 225 struct crypto_aead *aead = crypto_aead_reqtfm(req); 234 226 struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead); 235 - struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req); 227 + struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); 236 228 u32 flags = req->base.tfm->crt_flags; 237 229 u8 *auth_tag = pctx->auth_tag; 238 230 u8 *counter = pctx->counter; ··· 264 256 static int crypto_gcm_hash(struct aead_request *req) 265 257 { 266 258 struct crypto_aead *aead = crypto_aead_reqtfm(req); 267 - struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req); 259 + struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); 268 260 u8 *auth_tag = pctx->auth_tag; 269 261 struct crypto_gcm_ghash_ctx *ghash = &pctx->ghash; 270 262 ··· 289 281 290 282 static int crypto_gcm_encrypt(struct aead_request *req) 291 283 { 292 - struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req); 284 + struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); 293 285 struct ablkcipher_request *abreq = &pctx->abreq; 294 286 int err = 0; 295 287 ··· 315 307 static int crypto_gcm_decrypt(struct aead_request *req) 316 308 { 317 309 struct crypto_aead *aead = crypto_aead_reqtfm(req); 318 - struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req); 310 + struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); 319 311 struct ablkcipher_request *abreq = &pctx->abreq; 320 312 u8 *auth_tag = pctx->auth_tag; 321 313 u8 *iauth_tag = pctx->iauth_tag; ··· 360 352 ctx->ctr = ctr; 361 353 ctx->gf128 = NULL; 362 354 363 - align = max_t(unsigned long, crypto_ablkcipher_alignmask(ctr), 364 - __alignof__(u32) - 1); 355 + align = crypto_tfm_alg_alignmask(tfm); 365 356 align &= ~(crypto_tfm_ctx_alignment() - 1); 366 357 tfm->crt_aead.reqsize = align + 367 358 sizeof(struct crypto_gcm_req_priv_ctx) + ··· 435 428 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; 436 429 inst->alg.cra_priority = ctr->cra_priority; 437 430 inst->alg.cra_blocksize = 16; 438 - inst->alg.cra_alignmask = __alignof__(u32) - 1; 431 + inst->alg.cra_alignmask = ctr->cra_alignmask | (__alignof__(u64) - 1); 439 432 inst->alg.cra_type = &crypto_aead_type; 440 433 inst->alg.cra_aead.ivsize = 12; 441 434 inst->alg.cra_aead.maxauthsize = 16;