Skip to content

Commit 73a752c

Browse files
committed
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu: - fix crashes in skcipher/shash from zero-length input. - fix softirq GFP_KERNEL allocation in shash_setkey_unaligned. - error path bug fix in xts create function. - fix compiler warning regressions in axis and stm32 * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: shash - Fix zero-length shash ahash digest crash crypto: skcipher - Fix crash on zero-length input crypto: shash - Fix a sleep-in-atomic bug in shash_setkey_unaligned crypto: xts - Fix an error handling path in 'create()' crypto: stm32 - Try to fix hash padding crypto: axis - hide an unused variable
2 parents 0de50ea + b61907b commit 73a752c

5 files changed

Lines changed: 32 additions & 20 deletions

File tree

‎crypto/shash.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int shash_setkey_unaligned(struct crypto_shash *tfm, const u8 *key,
4141
int err;
4242

4343
absize = keylen + (alignmask & ~(crypto_tfm_ctx_alignment() - 1));
44-
buffer = kmalloc(absize, GFP_KERNEL);
44+
buffer = kmalloc(absize, GFP_ATOMIC);
4545
if (!buffer)
4646
return -ENOMEM;
4747

@@ -275,12 +275,14 @@ static int shash_async_finup(struct ahash_request *req)
275275

276276
int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc)
277277
{
278-
struct scatterlist *sg = req->src;
279-
unsigned int offset = sg->offset;
280278
unsigned int nbytes = req->nbytes;
279+
struct scatterlist *sg;
280+
unsigned int offset;
281281
int err;
282282

283-
if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) {
283+
if (nbytes &&
284+
(sg = req->src, offset = sg->offset,
285+
nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset))) {
284286
void *data;
285287

286288
data = kmap_atomic(sg_page(sg));

‎crypto/skcipher.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,9 @@ static int skcipher_copy_iv(struct skcipher_walk *walk)
426426

427427
static int skcipher_walk_first(struct skcipher_walk *walk)
428428
{
429-
walk->nbytes = 0;
430-
431429
if (WARN_ON_ONCE(in_irq()))
432430
return -EDEADLK;
433431

434-
if (unlikely(!walk->total))
435-
return 0;
436-
437432
walk->buffer = NULL;
438433
if (unlikely(((unsigned long)walk->iv & walk->alignmask))) {
439434
int err = skcipher_copy_iv(walk);
@@ -452,10 +447,15 @@ static int skcipher_walk_skcipher(struct skcipher_walk *walk,
452447
{
453448
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
454449

450+
walk->total = req->cryptlen;
451+
walk->nbytes = 0;
452+
453+
if (unlikely(!walk->total))
454+
return 0;
455+
455456
scatterwalk_start(&walk->in, req->src);
456457
scatterwalk_start(&walk->out, req->dst);
457458

458-
walk->total = req->cryptlen;
459459
walk->iv = req->iv;
460460
walk->oiv = req->iv;
461461

@@ -509,6 +509,11 @@ static int skcipher_walk_aead_common(struct skcipher_walk *walk,
509509
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
510510
int err;
511511

512+
walk->nbytes = 0;
513+
514+
if (unlikely(!walk->total))
515+
return 0;
516+
512517
walk->flags &= ~SKCIPHER_WALK_PHYS;
513518

514519
scatterwalk_start(&walk->in, req->src);

‎crypto/xts.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,10 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
554554
ctx->name[len - 1] = 0;
555555

556556
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
557-
"xts(%s)", ctx->name) >= CRYPTO_MAX_ALG_NAME)
558-
return -ENAMETOOLONG;
557+
"xts(%s)", ctx->name) >= CRYPTO_MAX_ALG_NAME) {
558+
err = -ENAMETOOLONG;
559+
goto err_drop_spawn;
560+
}
559561
} else
560562
goto err_drop_spawn;
561563

‎drivers/crypto/axis/artpec6_crypto.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,6 @@ struct artpec6_crypto_aead_req_ctx {
349349
/* The crypto framework makes it hard to avoid this global. */
350350
static struct device *artpec6_crypto_dev;
351351

352-
static struct dentry *dbgfs_root;
353-
354352
#ifdef CONFIG_FAULT_INJECTION
355353
static DECLARE_FAULT_ATTR(artpec6_crypto_fail_status_read);
356354
static DECLARE_FAULT_ATTR(artpec6_crypto_fail_dma_array_full);
@@ -2984,6 +2982,8 @@ struct dbgfs_u32 {
29842982
char *desc;
29852983
};
29862984

2985+
static struct dentry *dbgfs_root;
2986+
29872987
static void artpec6_crypto_init_debugfs(void)
29882988
{
29892989
dbgfs_root = debugfs_create_dir("artpec6_crypto", NULL);

‎drivers/crypto/stm32/stm32-hash.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ static int stm32_hash_dma_send(struct stm32_hash_dev *hdev)
553553
{
554554
struct stm32_hash_request_ctx *rctx = ahash_request_ctx(hdev->req);
555555
struct scatterlist sg[1], *tsg;
556-
int err = 0, len = 0, reg, ncp;
556+
int err = 0, len = 0, reg, ncp = 0;
557557
unsigned int i;
558-
const u32 *buffer = (const u32 *)rctx->buffer;
558+
u32 *buffer = (void *)rctx->buffer;
559559

560560
rctx->sg = hdev->req->src;
561561
rctx->total = hdev->req->nbytes;
@@ -620,10 +620,13 @@ static int stm32_hash_dma_send(struct stm32_hash_dev *hdev)
620620
reg |= HASH_CR_DMAA;
621621
stm32_hash_write(hdev, HASH_CR, reg);
622622

623-
for (i = 0; i < DIV_ROUND_UP(ncp, sizeof(u32)); i++)
624-
stm32_hash_write(hdev, HASH_DIN, buffer[i]);
625-
626-
stm32_hash_set_nblw(hdev, ncp);
623+
if (ncp) {
624+
memset(buffer + ncp, 0,
625+
DIV_ROUND_UP(ncp, sizeof(u32)) - ncp);
626+
writesl(hdev->io_base + HASH_DIN, buffer,
627+
DIV_ROUND_UP(ncp, sizeof(u32)));
628+
}
629+
stm32_hash_set_nblw(hdev, DIV_ROUND_UP(ncp, sizeof(u32)));
627630
reg = stm32_hash_read(hdev, HASH_STR);
628631
reg |= HASH_STR_DCAL;
629632
stm32_hash_write(hdev, HASH_STR, reg);

0 commit comments

Comments
 (0)