samba: fix some security problems
[openwrt.git] / target / linux / generic / patches-4.4 / 150-crypto-ccp-add-hash-state-import-and-export-support.patch
1 From: Tom Lendacky <thomas.lendacky@amd.com>
2 Subject: [PATCH v1] crypto: ccp - Add hash state import and export support
3 Date: Tue, 12 Jan 2016 11:17:38 -0600
4 Message-ID: <20160112171738.23496.44254.stgit@tlendack-t1.amdoffice.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset="utf-8"
7 Content-Transfer-Encoding: 7bit
8 Cc: Herbert Xu <herbert@gondor.apana.org.au>, <stable@vger.kernel.org>,
9         "David Miller" <davem@davemloft.net>
10 To: <linux-crypto@vger.kernel.org>
11
12 Commit 8996eafdcbad ("crypto: ahash - ensure statesize is non-zero")
13 added a check to prevent ahash algorithms from successfully registering
14 if the import and export functions were not implemented. This prevents
15 an oops in the hash_accept function of algif_hash. This commit causes
16 the ccp-crypto module SHA support and AES CMAC support from successfully
17 registering and causing the ccp-crypto module load to fail because the
18 ahash import and export functions are not implemented.
19
20 Update the CCP Crypto API support to provide import and export support
21 for ahash algorithms.
22
23 Cc: <stable@vger.kernel.org> # 3.14.x-
24 Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
25 ---
26  drivers/crypto/ccp/ccp-crypto-aes-cmac.c |   23 +++++++++++++++++++++++
27  drivers/crypto/ccp/ccp-crypto-sha.c      |   23 +++++++++++++++++++++++
28  2 files changed, 46 insertions(+)
29
30 --- a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
31 +++ b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
32 @@ -220,6 +220,26 @@ static int ccp_aes_cmac_digest(struct ah
33         return ccp_aes_cmac_finup(req);
34  }
35  
36 +static int ccp_aes_cmac_export(struct ahash_request *req, void *out)
37 +{
38 +       struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
39 +       struct ccp_aes_cmac_req_ctx *state = out;
40 +
41 +       *state = *rctx;
42 +
43 +       return 0;
44 +}
45 +
46 +static int ccp_aes_cmac_import(struct ahash_request *req, const void *in)
47 +{
48 +       struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
49 +       const struct ccp_aes_cmac_req_ctx *state = in;
50 +
51 +       *rctx = *state;
52 +
53 +       return 0;
54 +}
55 +
56  static int ccp_aes_cmac_setkey(struct crypto_ahash *tfm, const u8 *key,
57                                unsigned int key_len)
58  {
59 @@ -352,10 +372,13 @@ int ccp_register_aes_cmac_algs(struct li
60         alg->final = ccp_aes_cmac_final;
61         alg->finup = ccp_aes_cmac_finup;
62         alg->digest = ccp_aes_cmac_digest;
63 +       alg->export = ccp_aes_cmac_export;
64 +       alg->import = ccp_aes_cmac_import;
65         alg->setkey = ccp_aes_cmac_setkey;
66  
67         halg = &alg->halg;
68         halg->digestsize = AES_BLOCK_SIZE;
69 +       halg->statesize = sizeof(struct ccp_aes_cmac_req_ctx);
70  
71         base = &halg->base;
72         snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "cmac(aes)");
73 --- a/drivers/crypto/ccp/ccp-crypto-sha.c
74 +++ b/drivers/crypto/ccp/ccp-crypto-sha.c
75 @@ -207,6 +207,26 @@ static int ccp_sha_digest(struct ahash_r
76         return ccp_sha_finup(req);
77  }
78  
79 +static int ccp_sha_export(struct ahash_request *req, void *out)
80 +{
81 +       struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
82 +       struct ccp_sha_req_ctx *state = out;
83 +
84 +       *state = *rctx;
85 +
86 +       return 0;
87 +}
88 +
89 +static int ccp_sha_import(struct ahash_request *req, const void *in)
90 +{
91 +       struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
92 +       const struct ccp_sha_req_ctx *state = in;
93 +
94 +       *rctx = *state;
95 +
96 +       return 0;
97 +}
98 +
99  static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
100                           unsigned int key_len)
101  {
102 @@ -403,9 +423,12 @@ static int ccp_register_sha_alg(struct l
103         alg->final = ccp_sha_final;
104         alg->finup = ccp_sha_finup;
105         alg->digest = ccp_sha_digest;
106 +       alg->export = ccp_sha_export;
107 +       alg->import = ccp_sha_import;
108  
109         halg = &alg->halg;
110         halg->digestsize = def->digest_size;
111 +       halg->statesize = sizeof(struct ccp_sha_req_ctx);
112  
113         base = &halg->base;
114         snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name);