From patchwork Mon Feb 5 17:40:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 10201023 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 B040F6056F for ; Mon, 5 Feb 2018 17:40:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F9D328782 for ; Mon, 5 Feb 2018 17:40:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 923E9287CB; Mon, 5 Feb 2018 17:40:32 +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 35C3428782 for ; Mon, 5 Feb 2018 17:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753329AbeBERk2 (ORCPT ); Mon, 5 Feb 2018 12:40:28 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:45430 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752738AbeBERk1 (ORCPT ); Mon, 5 Feb 2018 12:40:27 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180205174023euoutp01862b77554ec109b7b16956ce9da19705~QfrzKi-w52623226232euoutp01k; Mon, 5 Feb 2018 17:40:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180205174023euoutp01862b77554ec109b7b16956ce9da19705~QfrzKi-w52623226232euoutp01k DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1517852423; bh=Mvgsd/Hk3z+P/fvqwyacafu2T6EJAT9jn544rFsy8ro=; h=From:Subject:To:Cc:Date:References:From; b=TtPKiV7OC6IPAZVlB+JwoiAFCQIABDNPPGLZFv0Jxqi/az1HbuKqg1EbUfFyYeOd7 eFRctjh63hZ59MzcAFWjxR1SeNWkSDh48JDawLJA5h47QkdZG2sCAIh9r7QwV4WmkV tpw9GTbExzs+dffZyG8gZPHjJHNUMIZCU+u+C1Y8= Received: from eusmges2.samsung.com (unknown [203.254.199.241]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180205174022eucas1p1fa547f4ebcd706776c8baf6009e6ee9c~QfryTrinS0287602876eucas1p1N; Mon, 5 Feb 2018 17:40:22 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2.samsung.com (EUCPMTA) with SMTP id 37.CC.12907.607987A5; Mon, 5 Feb 2018 17:40:22 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180205174022eucas1p101e8339284c1f0ac8f40f70c24de1c1f~QfrxoYZ6D1963619636eucas1p13; Mon, 5 Feb 2018 17:40:22 +0000 (GMT) X-AuditID: cbfec7f1-f793a6d00000326b-83-5a789706d4f5 Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id EA.35.20118.607987A5; Mon, 5 Feb 2018 17:40:22 +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 <0P3O0012TUF9X980@eusync1.samsung.com>; Mon, 05 Feb 2018 17:40:22 +0000 (GMT) From: Kamil Konieczny Subject: [PATCH] crypto: s5p-sss.c: Fix kernel Oops in AES-ECB mode To: Herbert Xu Cc: Krzysztof Kozlowski , Vladimir Zapolskiy , "David S. Miller" , Bartlomiej Zolnierkiewicz , Marek Szyprowski , Anand Moon , linux-crypto@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-kernel Message-id: <224788c7-426b-d3a9-d0a6-412d2b8afb75@partner.samsung.com> Date: Mon, 05 Feb 2018 18:40:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-version: 1.0 Content-type: text/plain; charset="utf-8" Content-language: en-US Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJKsWRmVeSWpSXmKPExsWy7djP87ps0yuiDHY0K1lsnLGe1WLO+RYW i+5XMhbnz29gt7h/7yeTxeVdc9gsZpzfx2SxbuMtdou1R+6yW/z/1czswOWxZeVNJo+ds+6y e2w7oOqxaVUnm8e/hVNYPPq2rGL0+LxJLoA9issmJTUnsyy1SN8ugSvj0zTegl6xigP3f7M2 MK4Q6mLk5JAQMJH4O2k3C4QtJnHh3nq2LkYuDiGBpYwSJ87NhnI+AzmH37LDdBw6/hoqsYxR YtafX6wQzjNGiZXNm1hBqtgEzCUebT/DBGILCzhLtC2fxQxiiwjoSKx8uRisgVngC5PEw/4r YA28Am4SVzvusoHYLAKqEqe7/4E1iApESCyc+pQRokZQ4sfke2DHMgtoSrz4MgnKFpdobr0J ZctLbF7zlhlkgYTAfTaJGQcvQN3tIjF75lImCFtY4tXxLVBxGYnLk7tZIBr6GSWW3zjFDuFM YZQ4Pu0qVIe1xOHjF1khVvBJTNo2HWgFB1CcV6KjDRqUHhJtd3ZBlTtKXFw3hQ2kREggVmLr kqQJjHKzkPwwC8kPs5D8MAvJDwsYWVYxiqSWFuempxYb6RUn5haX5qXrJefnbmIEJqDT/45/ 3MH4/oTVIUYBDkYlHt4dqRVRQqyJZcWV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POKHEUpyRaKjFXFSc CACVQ/VCggIAAA== X-CMS-MailID: 20180205174022eucas1p101e8339284c1f0ac8f40f70c24de1c1f X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180205174022eucas1p101e8339284c1f0ac8f40f70c24de1c1f X-RootMTR: 20180205174022eucas1p101e8339284c1f0ac8f40f70c24de1c1f 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 In AES-ECB mode crypt is done with key only, so any use of IV can cause kernel Oops, as reported by Anand Moon. Fixed it by using IV only in AES-CBC and AES-CTR. Signed-off-by: Kamil Konieczny Reported-by: Anand Moon Reviewed-by: Krzysztof Kozlowski Tested-by: Anand Moon --- Tested on Odroid XU4/HC1, kernel 4.15 with following command: fallocate -l 128MiB /tmp/test.bin dd if=/dev/urandom of=/tmp/testkey.key bs=128 count=1 sync cryptsetup luksFormat --debug -q -d /tmp/testkey.key \ --cipher aes-cbc-essiv:sha256 -h sha256 -s 128 /tmp/test.bin The original report by Anand Moon: https://www.spinics.net/lists/linux-crypto/msg31180.html Oops reproduced with cryptsetup 2.0.0, kernel 4.15, in .config in crypto API ECB support was turned off, and s5p-sss AES driver on. cryptsetup is using aes-ecb and has req->info in aes_ctx set to 0x10, which caused Oops: [ 2078.683779] Internal error: Oops: 17 [#1] PREEMPT SMP ARM [ 2078.689148] Modules linked in: algif_skcipher af_alg sd_mod sg evdev uas usb_storage scsi_mod gpio_keys fbtft(C) spidev spi_s3c64xx ipv6 [ 2078.701377] CPU: 1 PID: 15 Comm: ksoftirqd/1 Tainted: G C 4.15.0-rc9-xu4krck #1 [ 2078.709861] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) [ 2078.715932] PC is at memcpy+0x80/0x330 [ 2078.719652] LR is at s5p_tasklet_cb+0x19c/0x328 drivers/crypto/s5p-sss.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c index 142c6020cec7..5c0496d1ed41 100644 --- a/drivers/crypto/s5p-sss.c +++ b/drivers/crypto/s5p-sss.c @@ -1926,15 +1926,21 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode) uint32_t aes_control; unsigned long flags; int err; + u8 *iv; aes_control = SSS_AES_KEY_CHANGE_MODE; if (mode & FLAGS_AES_DECRYPT) aes_control |= SSS_AES_MODE_DECRYPT; - if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CBC) + if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CBC) { aes_control |= SSS_AES_CHAIN_MODE_CBC; - else if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CTR) + iv = req->info; + } else if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CTR) { aes_control |= SSS_AES_CHAIN_MODE_CTR; + iv = req->info; + } else { + iv = NULL; /* AES_ECB */ + } if (dev->ctx->keylen == AES_KEYSIZE_192) aes_control |= SSS_AES_KEY_SIZE_192; @@ -1965,7 +1971,7 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode) goto outdata_error; SSS_AES_WRITE(dev, AES_CONTROL, aes_control); - s5p_set_aes(dev, dev->ctx->aes_key, req->info, dev->ctx->keylen); + s5p_set_aes(dev, dev->ctx->aes_key, iv, dev->ctx->keylen); s5p_set_dma_indata(dev, dev->sg_src); s5p_set_dma_outdata(dev, dev->sg_dst);