Skip to content

Commit 33a8b3e

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: - vmalloc stack regression in CCM - Build problem in CRC32 on ARM - Memory leak in cavium - Missing Kconfig dependencies in atmel and mediatek - XTS Regression on some platforms (s390 and ppc) - Memory overrun in CCM test vector * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: vmx - Use skcipher for xts fallback crypto: vmx - Use skcipher for cbc fallback crypto: testmgr - Pad aes_ccm_enc_tv_template vector crypto: arm/crc32 - add build time test for CRC instruction support crypto: arm/crc32 - fix build error with outdated binutils crypto: ccm - move cbcmac input off the stack crypto: xts - Propagate NEED_FALLBACK bit crypto: api - Add crypto_requires_off helper crypto: atmel - CRYPTO_DEV_MEDIATEK should depend on HAS_DMA crypto: atmel - CRYPTO_DEV_ATMEL_TDES and CRYPTO_DEV_ATMEL_SHA should depend on HAS_DMA crypto: cavium - fix leak on curr if curr->head fails to be allocated crypto: cavium - Fix couple of static checker errors
2 parents 0710f3f + 5839f55 commit 33a8b3e

File tree

11 files changed

+79
-54
lines changed

11 files changed

+79
-54
lines changed

arch/arm/crypto/Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ ce-obj-$(CONFIG_CRYPTO_SHA1_ARM_CE) += sha1-arm-ce.o
1515
ce-obj-$(CONFIG_CRYPTO_SHA2_ARM_CE) += sha2-arm-ce.o
1616
ce-obj-$(CONFIG_CRYPTO_GHASH_ARM_CE) += ghash-arm-ce.o
1717
ce-obj-$(CONFIG_CRYPTO_CRCT10DIF_ARM_CE) += crct10dif-arm-ce.o
18-
ce-obj-$(CONFIG_CRYPTO_CRC32_ARM_CE) += crc32-arm-ce.o
18+
crc-obj-$(CONFIG_CRYPTO_CRC32_ARM_CE) += crc32-arm-ce.o
19+
20+
ifneq ($(crc-obj-y)$(crc-obj-m),)
21+
ifeq ($(call as-instr,.arch armv8-a\n.arch_extension crc,y,n),y)
22+
ce-obj-y += $(crc-obj-y)
23+
ce-obj-m += $(crc-obj-m)
24+
else
25+
$(warning These CRC Extensions modules need binutils 2.23 or higher)
26+
$(warning $(crc-obj-y) $(crc-obj-m))
27+
endif
28+
endif
1929

2030
ifneq ($(ce-obj-y)$(ce-obj-m),)
2131
ifeq ($(call as-instr,.fpu crypto-neon-fp-armv8,y,n),y)

arch/arm/crypto/crc32-ce-core.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ ENTRY(crc32c_pmull_le)
135135
vld1.8 {q3-q4}, [BUF, :128]!
136136
vmov.i8 qzr, #0
137137
vmov.i8 qCONSTANT, #0
138-
vmov dCONSTANTl[0], CRC
138+
vmov.32 dCONSTANTl[0], CRC
139139
veor.8 d2, d2, dCONSTANTl
140140
sub LEN, LEN, #0x40
141141
cmp LEN, #0x40

crypto/ccm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct crypto_rfc4309_req_ctx {
4545

4646
struct crypto_ccm_req_priv_ctx {
4747
u8 odata[16];
48+
u8 idata[16];
4849
u8 auth_tag[16];
4950
u32 flags;
5051
struct scatterlist src[3];
@@ -183,8 +184,8 @@ static int crypto_ccm_auth(struct aead_request *req, struct scatterlist *plain,
183184
AHASH_REQUEST_ON_STACK(ahreq, ctx->mac);
184185
unsigned int assoclen = req->assoclen;
185186
struct scatterlist sg[3];
186-
u8 odata[16];
187-
u8 idata[16];
187+
u8 *odata = pctx->odata;
188+
u8 *idata = pctx->idata;
188189
int ilen, err;
189190

190191
/* format control data for input */

crypto/testmgr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22691,7 +22691,7 @@ static struct aead_testvec aes_ccm_enc_tv_template[] = {
2269122691
"\x09\x75\x9a\x9b\x3c\x9b\x27\x39",
2269222692
.klen = 32,
2269322693
.iv = "\x03\xf9\xd9\x4e\x63\xb5\x3d\x9d"
22694-
"\x43\xf6\x1e\x50",
22694+
"\x43\xf6\x1e\x50\0\0\0\0",
2269522695
.assoc = "\x57\xf5\x6b\x8b\x57\x5c\x3d\x3b"
2269622696
"\x13\x02\x01\x0c\x83\x4c\x96\x35"
2269722697
"\x8e\xd6\x39\xcf\x7d\x14\x9b\x94"

crypto/xts.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
463463
struct xts_instance_ctx *ctx;
464464
struct skcipher_alg *alg;
465465
const char *cipher_name;
466+
u32 mask;
466467
int err;
467468

468469
algt = crypto_get_attr_type(tb);
@@ -483,18 +484,19 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
483484
ctx = skcipher_instance_ctx(inst);
484485

485486
crypto_set_skcipher_spawn(&ctx->spawn, skcipher_crypto_instance(inst));
486-
err = crypto_grab_skcipher(&ctx->spawn, cipher_name, 0,
487-
crypto_requires_sync(algt->type,
488-
algt->mask));
487+
488+
mask = crypto_requires_off(algt->type, algt->mask,
489+
CRYPTO_ALG_NEED_FALLBACK |
490+
CRYPTO_ALG_ASYNC);
491+
492+
err = crypto_grab_skcipher(&ctx->spawn, cipher_name, 0, mask);
489493
if (err == -ENOENT) {
490494
err = -ENAMETOOLONG;
491495
if (snprintf(ctx->name, CRYPTO_MAX_ALG_NAME, "ecb(%s)",
492496
cipher_name) >= CRYPTO_MAX_ALG_NAME)
493497
goto err_free_inst;
494498

495-
err = crypto_grab_skcipher(&ctx->spawn, ctx->name, 0,
496-
crypto_requires_sync(algt->type,
497-
algt->mask));
499+
err = crypto_grab_skcipher(&ctx->spawn, ctx->name, 0, mask);
498500
}
499501

500502
if (err)

drivers/crypto/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ config CRYPTO_DEV_ATMEL_AES
459459

460460
config CRYPTO_DEV_ATMEL_TDES
461461
tristate "Support for Atmel DES/TDES hw accelerator"
462+
depends on HAS_DMA
462463
depends on ARCH_AT91 || COMPILE_TEST
463464
select CRYPTO_DES
464465
select CRYPTO_BLKCIPHER
@@ -472,6 +473,7 @@ config CRYPTO_DEV_ATMEL_TDES
472473

473474
config CRYPTO_DEV_ATMEL_SHA
474475
tristate "Support for Atmel SHA hw accelerator"
476+
depends on HAS_DMA
475477
depends on ARCH_AT91 || COMPILE_TEST
476478
select CRYPTO_HASH
477479
help
@@ -583,6 +585,7 @@ config CRYPTO_DEV_ROCKCHIP
583585

584586
config CRYPTO_DEV_MEDIATEK
585587
tristate "MediaTek's EIP97 Cryptographic Engine driver"
588+
depends on HAS_DMA
586589
depends on (ARM && ARCH_MEDIATEK) || COMPILE_TEST
587590
select CRYPTO_AES
588591
select CRYPTO_AEAD

drivers/crypto/cavium/cpt/cptvf_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ static int alloc_command_queues(struct cpt_vf *cptvf,
242242
if (!curr->head) {
243243
dev_err(&pdev->dev, "Command Q (%d) chunk (%d) allocation failed\n",
244244
i, queue->nchunks);
245+
kfree(curr);
245246
goto cmd_qfail;
246247
}
247248

@@ -815,8 +816,10 @@ static void cptvf_remove(struct pci_dev *pdev)
815816
{
816817
struct cpt_vf *cptvf = pci_get_drvdata(pdev);
817818

818-
if (!cptvf)
819+
if (!cptvf) {
819820
dev_err(&pdev->dev, "Invalid CPT-VF device\n");
821+
return;
822+
}
820823

821824
/* Convey DOWN to PF */
822825
if (cptvf_send_vf_down(cptvf)) {

drivers/crypto/cavium/cpt/cptvf_reqmanager.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ void do_post_process(struct cpt_vf *cptvf, struct cpt_info_buffer *info)
330330
{
331331
struct pci_dev *pdev = cptvf->pdev;
332332

333-
if (!info || !cptvf) {
334-
dev_err(&pdev->dev, "Input params are incorrect for post processing\n");
333+
if (!info) {
334+
dev_err(&pdev->dev, "incorrect cpt_info_buffer for post processing\n");
335335
return;
336336
}
337337

drivers/crypto/vmx/aes_cbc.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,43 @@
2727
#include <asm/switch_to.h>
2828
#include <crypto/aes.h>
2929
#include <crypto/scatterwalk.h>
30+
#include <crypto/skcipher.h>
3031

3132
#include "aesp8-ppc.h"
3233

3334
struct p8_aes_cbc_ctx {
34-
struct crypto_blkcipher *fallback;
35+
struct crypto_skcipher *fallback;
3536
struct aes_key enc_key;
3637
struct aes_key dec_key;
3738
};
3839

3940
static int p8_aes_cbc_init(struct crypto_tfm *tfm)
4041
{
4142
const char *alg;
42-
struct crypto_blkcipher *fallback;
43+
struct crypto_skcipher *fallback;
4344
struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
4445

4546
if (!(alg = crypto_tfm_alg_name(tfm))) {
4647
printk(KERN_ERR "Failed to get algorithm name.\n");
4748
return -ENOENT;
4849
}
4950

50-
fallback =
51-
crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
51+
fallback = crypto_alloc_skcipher(alg, 0,
52+
CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK);
53+
5254
if (IS_ERR(fallback)) {
5355
printk(KERN_ERR
5456
"Failed to allocate transformation for '%s': %ld\n",
5557
alg, PTR_ERR(fallback));
5658
return PTR_ERR(fallback);
5759
}
5860
printk(KERN_INFO "Using '%s' as fallback implementation.\n",
59-
crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback));
61+
crypto_skcipher_driver_name(fallback));
62+
6063

61-
crypto_blkcipher_set_flags(
64+
crypto_skcipher_set_flags(
6265
fallback,
63-
crypto_blkcipher_get_flags((struct crypto_blkcipher *)tfm));
66+
crypto_skcipher_get_flags((struct crypto_skcipher *)tfm));
6467
ctx->fallback = fallback;
6568

6669
return 0;
@@ -71,7 +74,7 @@ static void p8_aes_cbc_exit(struct crypto_tfm *tfm)
7174
struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
7275

7376
if (ctx->fallback) {
74-
crypto_free_blkcipher(ctx->fallback);
77+
crypto_free_skcipher(ctx->fallback);
7578
ctx->fallback = NULL;
7679
}
7780
}
@@ -91,7 +94,7 @@ static int p8_aes_cbc_setkey(struct crypto_tfm *tfm, const u8 *key,
9194
pagefault_enable();
9295
preempt_enable();
9396

94-
ret += crypto_blkcipher_setkey(ctx->fallback, key, keylen);
97+
ret += crypto_skcipher_setkey(ctx->fallback, key, keylen);
9598
return ret;
9699
}
97100

@@ -103,15 +106,14 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
103106
struct blkcipher_walk walk;
104107
struct p8_aes_cbc_ctx *ctx =
105108
crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
106-
struct blkcipher_desc fallback_desc = {
107-
.tfm = ctx->fallback,
108-
.info = desc->info,
109-
.flags = desc->flags
110-
};
111109

112110
if (in_interrupt()) {
113-
ret = crypto_blkcipher_encrypt(&fallback_desc, dst, src,
114-
nbytes);
111+
SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback);
112+
skcipher_request_set_tfm(req, ctx->fallback);
113+
skcipher_request_set_callback(req, desc->flags, NULL, NULL);
114+
skcipher_request_set_crypt(req, src, dst, nbytes, desc->info);
115+
ret = crypto_skcipher_encrypt(req);
116+
skcipher_request_zero(req);
115117
} else {
116118
preempt_disable();
117119
pagefault_disable();
@@ -144,15 +146,14 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
144146
struct blkcipher_walk walk;
145147
struct p8_aes_cbc_ctx *ctx =
146148
crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
147-
struct blkcipher_desc fallback_desc = {
148-
.tfm = ctx->fallback,
149-
.info = desc->info,
150-
.flags = desc->flags
151-
};
152149

153150
if (in_interrupt()) {
154-
ret = crypto_blkcipher_decrypt(&fallback_desc, dst, src,
155-
nbytes);
151+
SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback);
152+
skcipher_request_set_tfm(req, ctx->fallback);
153+
skcipher_request_set_callback(req, desc->flags, NULL, NULL);
154+
skcipher_request_set_crypt(req, src, dst, nbytes, desc->info);
155+
ret = crypto_skcipher_decrypt(req);
156+
skcipher_request_zero(req);
156157
} else {
157158
preempt_disable();
158159
pagefault_disable();

drivers/crypto/vmx/aes_xts.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
#include <crypto/aes.h>
2929
#include <crypto/scatterwalk.h>
3030
#include <crypto/xts.h>
31+
#include <crypto/skcipher.h>
3132

3233
#include "aesp8-ppc.h"
3334

3435
struct p8_aes_xts_ctx {
35-
struct crypto_blkcipher *fallback;
36+
struct crypto_skcipher *fallback;
3637
struct aes_key enc_key;
3738
struct aes_key dec_key;
3839
struct aes_key tweak_key;
@@ -41,28 +42,28 @@ struct p8_aes_xts_ctx {
4142
static int p8_aes_xts_init(struct crypto_tfm *tfm)
4243
{
4344
const char *alg;
44-
struct crypto_blkcipher *fallback;
45+
struct crypto_skcipher *fallback;
4546
struct p8_aes_xts_ctx *ctx = crypto_tfm_ctx(tfm);
4647

4748
if (!(alg = crypto_tfm_alg_name(tfm))) {
4849
printk(KERN_ERR "Failed to get algorithm name.\n");
4950
return -ENOENT;
5051
}
5152

52-
fallback =
53-
crypto_alloc_blkcipher(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
53+
fallback = crypto_alloc_skcipher(alg, 0,
54+
CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK);
5455
if (IS_ERR(fallback)) {
5556
printk(KERN_ERR
5657
"Failed to allocate transformation for '%s': %ld\n",
5758
alg, PTR_ERR(fallback));
5859
return PTR_ERR(fallback);
5960
}
6061
printk(KERN_INFO "Using '%s' as fallback implementation.\n",
61-
crypto_tfm_alg_driver_name((struct crypto_tfm *) fallback));
62+
crypto_skcipher_driver_name(fallback));
6263

63-
crypto_blkcipher_set_flags(
64+
crypto_skcipher_set_flags(
6465
fallback,
65-
crypto_blkcipher_get_flags((struct crypto_blkcipher *)tfm));
66+
crypto_skcipher_get_flags((struct crypto_skcipher *)tfm));
6667
ctx->fallback = fallback;
6768

6869
return 0;
@@ -73,7 +74,7 @@ static void p8_aes_xts_exit(struct crypto_tfm *tfm)
7374
struct p8_aes_xts_ctx *ctx = crypto_tfm_ctx(tfm);
7475

7576
if (ctx->fallback) {
76-
crypto_free_blkcipher(ctx->fallback);
77+
crypto_free_skcipher(ctx->fallback);
7778
ctx->fallback = NULL;
7879
}
7980
}
@@ -98,7 +99,7 @@ static int p8_aes_xts_setkey(struct crypto_tfm *tfm, const u8 *key,
9899
pagefault_enable();
99100
preempt_enable();
100101

101-
ret += crypto_blkcipher_setkey(ctx->fallback, key, keylen);
102+
ret += crypto_skcipher_setkey(ctx->fallback, key, keylen);
102103
return ret;
103104
}
104105

@@ -113,15 +114,14 @@ static int p8_aes_xts_crypt(struct blkcipher_desc *desc,
113114
struct blkcipher_walk walk;
114115
struct p8_aes_xts_ctx *ctx =
115116
crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
116-
struct blkcipher_desc fallback_desc = {
117-
.tfm = ctx->fallback,
118-
.info = desc->info,
119-
.flags = desc->flags
120-
};
121117

122118
if (in_interrupt()) {
123-
ret = enc ? crypto_blkcipher_encrypt(&fallback_desc, dst, src, nbytes) :
124-
crypto_blkcipher_decrypt(&fallback_desc, dst, src, nbytes);
119+
SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback);
120+
skcipher_request_set_tfm(req, ctx->fallback);
121+
skcipher_request_set_callback(req, desc->flags, NULL, NULL);
122+
skcipher_request_set_crypt(req, src, dst, nbytes, desc->info);
123+
ret = enc? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req);
124+
skcipher_request_zero(req);
125125
} else {
126126
preempt_disable();
127127
pagefault_disable();

include/crypto/algapi.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,18 @@ static inline struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb,
360360
return crypto_attr_alg(tb[1], type, mask);
361361
}
362362

363+
static inline int crypto_requires_off(u32 type, u32 mask, u32 off)
364+
{
365+
return (type ^ off) & mask & off;
366+
}
367+
363368
/*
364369
* Returns CRYPTO_ALG_ASYNC if type/mask requires the use of sync algorithms.
365370
* Otherwise returns zero.
366371
*/
367372
static inline int crypto_requires_sync(u32 type, u32 mask)
368373
{
369-
return (type ^ CRYPTO_ALG_ASYNC) & mask & CRYPTO_ALG_ASYNC;
374+
return crypto_requires_off(type, mask, CRYPTO_ALG_ASYNC);
370375
}
371376

372377
noinline unsigned long __crypto_memneq(const void *a, const void *b, size_t size);

0 commit comments

Comments
 (0)