From patchwork Tue Jan 16 14:26:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 10167199 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D2179601E7 for ; Tue, 16 Jan 2018 14:26:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C29F928464 for ; Tue, 16 Jan 2018 14:26:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B552D28477; Tue, 16 Jan 2018 14:26:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1526B28464 for ; Tue, 16 Jan 2018 14:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751229AbeAPO0U (ORCPT ); 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 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180116142615euoutp02d2d224ee11e14e224a0646e11719ce5d~KUIlsvKdC3232232322euoutp02t; Tue, 16 Jan 2018 14:26:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180116142615euoutp02d2d224ee11e14e224a0646e11719ce5d~KUIlsvKdC3232232322euoutp02t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1516112775; bh=LLL9KpsRwbcxc+Gmlrm0z/8IYsMdjP5Je0JBzcjJq2Q=; h=From:Subject:To:Cc:Date:References:From; b=phBBHoRtA92+DTtFCG7F5nkWF2Fdjq5BruT85brURg2v4jqLVLwSRtVEAi0iEhwZa wWf24Rv0VdPz9KuOBLBahd5Ne7tKmSZ1rKSsGw3LucNK9w5HgORagjagnWMu0RUDLr h8qAKOp40MsbkrsxEM2bxkY7Wx9Z36jf36cTLcFY= Received: from eusmges3.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180116142615eucas1p2964f73873d5cdb895e950e713b0e48d6~KUIlGqWrp1292612926eucas1p2f; Tue, 16 Jan 2018 14:26:15 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3.samsung.com (EUCPMTA) with SMTP id 0F.36.12867.68B0E5A5; Tue, 16 Jan 2018 14:26:14 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180116142614eucas1p1c171b69192a4b8f7871075ff712bb7ba~KUIkfZ1NX1791717917eucas1p1E; Tue, 16 Jan 2018 14:26:14 +0000 (GMT) X-AuditID: cbfec7f2-f793b6d000003243-8f-5a5e0b8696b8 Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 03.53.20118.68B0E5A5; Tue, 16 Jan 2018 14:26:14 +0000 (GMT) Received: from [106.120.51.18] by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P2N003V7K3PMK00@eusync1.samsung.com>; Tue, 16 Jan 2018 14:26:14 +0000 (GMT) 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 ZgFNiRdfJkHZ4hLNrTehbHmJzWveMoMskBBYwCbRfmMuG8TdLhJPz/5mhLCFJV4d3wL1tIzE 5cndLBAN/YwSy2+cYodwpjBKHJ92lQmiylri8PGLrBAr+CQmbZsOtIIDKM4r0dEmBFHiIXH6 yjsWiLCjxP9NOpCwi5X4f/gQ2wRGuVlIfpiF5IdZSH6YheSHBYwsqxhFUkuLc9NTi431ihNz i0vz0vWS83M3MQITxul/xz/tYPx6wuoQowAHoxIPL8Of2Cgh1sSy4srcQ4wSHMxKIryNwTFR QrwpiZVVqUX58UWlOanFhxilOViUxHlto9oihQTSE0tSs1NTC1KLYLJMHJxSDYzelW4yOe9W tdx7Zfci6cqa9qJdTXWhDYIX1O2rL7+u59p+fO/35Z+OiwbHLuXepHBy6bGu7Swbg4+dk7vt r27PnVoXsTY6vUji6SnV6W/UVxvMtq3y3ptRd3KhxJeizFNPtFkrvZ3qyrWliko/zWdIXFNy bkr+s+dVWsxTS/unCwhs/fDqwX0lluKMREMt5qLiRACm/cGFFAMAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJLMWRmVeSWpSXmKPExsVy+t/xy7pt3HFRBo0/JSw2zljPajHnfAuL RfcrGYv7934yWVzeNYfNgdVjy8qbTB7bDqh69G1ZxejxeZNcAEsUl01Kak5mWWqRvl0CV8be LXvYCzZLV0w694etgXGWaBcjJ4eEgIlE17N/TBC2mMSFe+vZuhi5OIQEljBKXOo5D+U8Y5RY fv8HWBWbgLnEo+1nwGxhASeJvwcXs4LYIgI6EitfgthcHMwCCxklJi0+BpbgFXCTOHJ8JjOI zSKgKrGg8SpYXFQgQqJp5lyoGkGJH5PvsXQxcgA1q0tMmZILEmYWEJdobr3JAmHLS2xe85Z5 AiP/LCQdsxA6ZiHpmIWkYwEjyypGkdTS4tz03GIjveLE3OLSvHS95PzcTYzAAN527OeWHYxd 74IPMQpwMCrx8DL8iY0SYk0sK67MPcQowcGsJMLbGBwTJcSbklhZlVqUH19UmpNafIhRmoNF SZy3d8/qSCGB9MSS1OzU1ILUIpgsEwenVANjfFHC9kPL+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-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 "