Skip to content

Commit 658c9d2

Browse files
chunkeeyherbertx
authored andcommitted
crypto: crypto4xx - put temporary dst sg into request ctx
This patch fixes a crash that happens when testing rfc4543(gcm(aes)) Unable to handle kernel paging request for data at address 0xf59b3420 Faulting instruction address: 0xc0012994 Oops: Kernel access of bad area, sig: 11 [#1] BE PowerPC 44x Platform Modules linked in: tcrypt(+) crypto4xx [...] CPU: 0 PID: 0 Comm: swapper Tainted: G O 4.17.0-rc1+ #23 NIP: c0012994 LR: d3077934 CTR: 06026d49 REGS: cfff7e30 TRAP: 0300 Tainted: G O (4.17.0-rc1+) MSR: 00029000 <CE,EE,ME> CR: 44744822 XER: 00000000 DEAR: f59b3420 ESR: 00000000 NIP [c0012994] __dma_sync+0x58/0x10c LR [d3077934] crypto4xx_bh_tasklet_cb+0x188/0x3c8 [crypto4xx] __dma_sync was fed the temporary _dst that crypto4xx_build_pd() had in it's function stack. This clearly never worked. This patch therefore overhauls the code from the original driver and puts the temporary dst sg list into aead's request context. Fixes: a0aae82 ("crypto: crypto4xx - prepare for AEAD support") Signed-off-by: Christian Lamparter <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 584201f commit 658c9d2

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

drivers/crypto/amcc/crypto4xx_alg.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static inline int crypto4xx_crypt(struct skcipher_request *req,
8787

8888
return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
8989
req->cryptlen, iv, ivlen, decrypt ? ctx->sa_in : ctx->sa_out,
90-
ctx->sa_len, 0);
90+
ctx->sa_len, 0, NULL);
9191
}
9292

9393
int crypto4xx_encrypt_noiv(struct skcipher_request *req)
@@ -223,7 +223,7 @@ int crypto4xx_rfc3686_encrypt(struct skcipher_request *req)
223223

224224
return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
225225
req->cryptlen, iv, AES_IV_SIZE,
226-
ctx->sa_out, ctx->sa_len, 0);
226+
ctx->sa_out, ctx->sa_len, 0, NULL);
227227
}
228228

229229
int crypto4xx_rfc3686_decrypt(struct skcipher_request *req)
@@ -238,7 +238,7 @@ int crypto4xx_rfc3686_decrypt(struct skcipher_request *req)
238238

239239
return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
240240
req->cryptlen, iv, AES_IV_SIZE,
241-
ctx->sa_out, ctx->sa_len, 0);
241+
ctx->sa_out, ctx->sa_len, 0, NULL);
242242
}
243243

244244
static int
@@ -449,6 +449,7 @@ int crypto4xx_setkey_aes_ccm(struct crypto_aead *cipher, const u8 *key,
449449
static int crypto4xx_crypt_aes_ccm(struct aead_request *req, bool decrypt)
450450
{
451451
struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
452+
struct crypto4xx_aead_reqctx *rctx = aead_request_ctx(req);
452453
struct crypto_aead *aead = crypto_aead_reqtfm(req);
453454
__le32 iv[16];
454455
u32 tmp_sa[SA_AES128_CCM_LEN + 4];
@@ -474,7 +475,7 @@ static int crypto4xx_crypt_aes_ccm(struct aead_request *req, bool decrypt)
474475

475476
return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
476477
len, iv, sizeof(iv),
477-
sa, ctx->sa_len, req->assoclen);
478+
sa, ctx->sa_len, req->assoclen, rctx->dst);
478479
}
479480

480481
int crypto4xx_encrypt_aes_ccm(struct aead_request *req)
@@ -622,7 +623,7 @@ static inline int crypto4xx_crypt_aes_gcm(struct aead_request *req,
622623
return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
623624
len, iv, sizeof(iv),
624625
decrypt ? ctx->sa_in : ctx->sa_out,
625-
ctx->sa_len, req->assoclen);
626+
ctx->sa_len, req->assoclen, rctx->dst);
626627
}
627628

628629
int crypto4xx_encrypt_aes_gcm(struct aead_request *req)
@@ -707,7 +708,7 @@ int crypto4xx_hash_update(struct ahash_request *req)
707708

708709
return crypto4xx_build_pd(&req->base, ctx, req->src, &dst,
709710
req->nbytes, NULL, 0, ctx->sa_in,
710-
ctx->sa_len, 0);
711+
ctx->sa_len, 0, NULL);
711712
}
712713

713714
int crypto4xx_hash_final(struct ahash_request *req)
@@ -726,7 +727,7 @@ int crypto4xx_hash_digest(struct ahash_request *req)
726727

727728
return crypto4xx_build_pd(&req->base, ctx, req->src, &dst,
728729
req->nbytes, NULL, 0, ctx->sa_in,
729-
ctx->sa_len, 0);
730+
ctx->sa_len, 0, NULL);
730731
}
731732

732733
/**

drivers/crypto/amcc/crypto4xx_core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,9 @@ int crypto4xx_build_pd(struct crypto_async_request *req,
695695
const __le32 *iv, const u32 iv_len,
696696
const struct dynamic_sa_ctl *req_sa,
697697
const unsigned int sa_len,
698-
const unsigned int assoclen)
698+
const unsigned int assoclen,
699+
struct scatterlist *_dst)
699700
{
700-
struct scatterlist _dst[2];
701701
struct crypto4xx_device *dev = ctx->dev;
702702
struct dynamic_sa_ctl *sa;
703703
struct ce_gd *gd;
@@ -996,9 +996,9 @@ static int crypto4xx_aead_init(struct crypto_aead *tfm)
996996

997997
amcc_alg = container_of(alg, struct crypto4xx_alg, alg.u.aead);
998998
crypto4xx_ctx_init(amcc_alg, ctx);
999-
crypto_aead_set_reqsize(tfm, sizeof(struct aead_request) +
1000-
max(sizeof(struct crypto4xx_ctx), 32 +
1001-
crypto_aead_reqsize(ctx->sw_cipher.aead)));
999+
crypto_aead_set_reqsize(tfm, max(sizeof(struct aead_request) + 32 +
1000+
crypto_aead_reqsize(ctx->sw_cipher.aead),
1001+
sizeof(struct crypto4xx_aead_reqctx)));
10021002
return 0;
10031003
}
10041004

drivers/crypto/amcc/crypto4xx_core.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ struct crypto4xx_ctx {
133133
} sw_cipher;
134134
};
135135

136+
struct crypto4xx_aead_reqctx {
137+
struct scatterlist dst[2];
138+
};
139+
136140
struct crypto4xx_alg_common {
137141
u32 type;
138142
union {
@@ -159,7 +163,8 @@ int crypto4xx_build_pd(struct crypto_async_request *req,
159163
const __le32 *iv, const u32 iv_len,
160164
const struct dynamic_sa_ctl *sa,
161165
const unsigned int sa_len,
162-
const unsigned int assoclen);
166+
const unsigned int assoclen,
167+
struct scatterlist *dst_tmp);
163168
int crypto4xx_setkey_aes_cbc(struct crypto_skcipher *cipher,
164169
const u8 *key, unsigned int keylen);
165170
int crypto4xx_setkey_aes_cfb(struct crypto_skcipher *cipher,

0 commit comments

Comments
 (0)