Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751486AbeAPO0U (ORCPT + 1 other); Tue, 16 Jan 2018 09:26:20 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:60807 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751107AbeAPO0S (ORCPT ); Tue, 16 Jan 2018 09:26:18 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180116142615euoutp02d2d224ee11e14e224a0646e11719ce5d~KUIlsvKdC3232232322euoutp02t X-AuditID: cbfec7f2-f793b6d000003243-8f-5a5e0b8696b8 From: Kamil Konieczny Subject: [PATCH] crypto: testmgr.c: test misuse of result in ahash To: Herbert Xu Cc: "David S. Miller" , Bartlomiej Zolnierkiewicz , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Message-id: <9d678a28-8cb3-1ab8-cefe-1bafff2a18d9@partner.samsung.com> Date: Tue, 16 Jan 2018 15:26:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-version: 1.0 Content-type: text/plain; charset="utf-8" Content-language: en-US Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkleLIzCtJLcpLzFFi42LZduzned027rgog3/7jCw2zljPajHnfAuL RfcrGYv7934yWVzeNYfNgdVjy8qbTB7bDqh69G1ZxejxeZNcAEsUl01Kak5mWWqRvl0CV8be LXvYCzZLV0w694etgXGWaBcjJ4eEgIlE56297BC2mMSFe+vZuhi5OIQEljJK9C3azAySEBL4 zCjxao8ETEPXs39MEEXLGCVWXlkM5TxjlHjZdY4FpIpNwFzi0fYzTCC2sICTxN+Di1lBbBEB HYmVL0FsLg5mgYWMEj/6z4Pt5hVwkzhyfCbYOhYBVYkFjVfBGkQFIoDW7WKFqBGU+DH5HtgC ZgFNiRdfJkHZ4hLNrTehbHmJzWveMoMskBBYwCbRfmM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L+EzsarSUV/+de75bILkqY5n7wZuL by/rUM7SX8lUmqZ1r/qDRqtCqo+ShQ533/rPaolJDd+Zfu53mStRIRMVo/vlXu/mU57b2pXX ltp4sYstfPx2R49n2HHnxY4P9+5ptXglE/al/soNrUO8c9Tqs8v3nZNaueLtobDuUg4raQMl luKMREMt5qLiRABnTgLeXAIAAA== X-CMS-MailID: 20180116142614eucas1p1c171b69192a4b8f7871075ff712bb7ba X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180116142614eucas1p1c171b69192a4b8f7871075ff712bb7ba X-RootMTR: 20180116142614eucas1p1c171b69192a4b8f7871075ff712bb7ba References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Async hash operations can use result pointer in final/finup/digest, but not in init/update/export/import, so test it for misuse. Signed-off-by: Kamil Konieczny --- Tested with crypto run-time self test on Odroid-U3 with Exynos 4412 CPU with insmod s5p-sss.ko crypto/testmgr.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 44a85d4b3561..d5e23a142a04 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -177,6 +177,18 @@ static void testmgr_free_buf(char *buf[XBUFSIZE]) free_page((unsigned long)buf[i]); } +static int ahash_guard_result(char *result, char c, int size) +{ + int i; + + for (i = 0; i < size; i++) { + if (result[i] != c) + return -EINVAL; + } + + return 0; +} + static int ahash_partial_update(struct ahash_request **preq, struct crypto_ahash *tfm, const struct hash_testvec *template, void *hash_buff, int k, int temp, struct scatterlist *sg, @@ -186,6 +198,7 @@ static int ahash_partial_update(struct ahash_request **preq, struct ahash_request *req; int statesize, ret = -EINVAL; static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 }; + int digestsize = crypto_ahash_digestsize(tfm); req = *preq; statesize = crypto_ahash_statesize( @@ -196,12 +209,19 @@ static int ahash_partial_update(struct ahash_request **preq, goto out_nostate; } memcpy(state + statesize, guard, sizeof(guard)); + memset(result, 1, digestsize); ret = crypto_ahash_export(req, state); WARN_ON(memcmp(state + statesize, guard, sizeof(guard))); if (ret) { pr_err("alg: hash: Failed to export() for %s\n", algo); goto out; } + ret = ahash_guard_result(result, 1, digestsize); + if (ret) { + pr_err("alg: hash: Failed, export used req->result for %s\n", + algo); + goto out; + } ahash_request_free(req); req = ahash_request_alloc(tfm, GFP_KERNEL); if (!req) { @@ -221,6 +241,12 @@ static int ahash_partial_update(struct ahash_request **preq, pr_err("alg: hash: Failed to import() for %s\n", algo); goto out; } + ret = ahash_guard_result(result, 1, digestsize); + if (ret) { + pr_err("alg: hash: Failed, import used req->result for %s\n", + algo); + goto out; + } ret = crypto_wait_req(crypto_ahash_update(req), wait); if (ret) goto out; @@ -316,18 +342,31 @@ static int __test_hash(struct crypto_ahash *tfm, goto out; } } else { + memset(result, 1, digest_size); ret = crypto_wait_req(crypto_ahash_init(req), &wait); if (ret) { pr_err("alg: hash: init failed on test %d " "for %s: ret=%d\n", j, algo, -ret); goto out; } + ret = ahash_guard_result(result, 1, digest_size); + if (ret) { + pr_err("alg: hash: init failed on test %d " + "for %s: used req->result\n", j, algo); + goto out; + } ret = crypto_wait_req(crypto_ahash_update(req), &wait); if (ret) { pr_err("alg: hash: update failed on test %d " "for %s: ret=%d\n", j, algo, -ret); goto out; } + ret = ahash_guard_result(result, 1, digest_size); + if (ret) { + pr_err("alg: hash: update failed on test %d " + "for %s: used req->result\n", j, algo); + goto out; + } ret = crypto_wait_req(crypto_ahash_final(req), &wait); if (ret) { pr_err("alg: hash: final failed on test %d " -- 2.15.0