From patchwork Wed Feb 7 15:52:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 10205441 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 6D280602D8 for ; Wed, 7 Feb 2018 15:52:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AFA72901B for ; Wed, 7 Feb 2018 15:52:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DA442902C; Wed, 7 Feb 2018 15:52:19 +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=ham 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 B9BA52901B for ; Wed, 7 Feb 2018 15:52:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754231AbeBGPwR (ORCPT ); Wed, 7 Feb 2018 10:52:17 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:36793 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754138AbeBGPwP (ORCPT ); Wed, 7 Feb 2018 10:52:15 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180207155212euoutp0269b87e9f8659189aee6cc50976ee817c~RFf6dRLro1448914489euoutp02u; Wed, 7 Feb 2018 15:52:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180207155212euoutp0269b87e9f8659189aee6cc50976ee817c~RFf6dRLro1448914489euoutp02u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1518018732; bh=JvU+d4l5cNUz+jk71T/tEjiKrTKMwCqs6iR4C0ShtzQ=; h=From:Subject:To:Cc:Date:References:From; b=ssMCcRtrISW3waMsGH1d882WAmFT7lB2PpXf+pq/Yl/U9Sg/3OOzrtjTTZSKkbMvj 7MdnKZsigm+YTQaBiO0A9DhgRiQvROAUHmi6C8KoGKPyG1Cq5qtSaoR9fjsEODL0gp Dl/MqrIvth0hBgdHmtWMkmFp/HwtHzakq/W6SB4o= Received: from eusmges5.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180207155211eucas1p2f26c5e792625a7dab9f4496d4bca8436~RFf5rcb8D3245832458eucas1p2t; Wed, 7 Feb 2018 15:52:11 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges5.samsung.com (EUCPMTA) with SMTP id B8.2D.12743.BA02B7A5; Wed, 7 Feb 2018 15:52:11 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180207155211eucas1p2d8d04871aaeb49efc30909d46e47e028~RFf49IDjM0177201772eucas1p2v; Wed, 7 Feb 2018 15:52:11 +0000 (GMT) X-AuditID: cbfec7f5-f79d06d0000031c7-2a-5a7b20ab854c Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 45.B3.18832.BA02B7A5; Wed, 7 Feb 2018 15:52:11 +0000 (GMT) Received: from [106.120.51.18] by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P3S00072EQY0R10@eusync4.samsung.com>; Wed, 07 Feb 2018 15:52:11 +0000 (GMT) From: Kamil Konieczny Subject: [PATCH v3] crypto: s5p-sss.c: Fix kernel Oops in AES-ECB mode To: Herbert Xu Cc: Krzysztof Kozlowski , Vladimir Zapolskiy , "David S. Miller" , Anand Moon , Bartlomiej Zolnierkiewicz , Marek Szyprowski , linux-crypto@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Message-id: <77384548-9870-40b8-46fc-4bd62747efd6@partner.samsung.com> Date: Wed, 07 Feb 2018 16:52:09 +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+NgFlrNKsWRmVeSWpSXmKPExsWy7djP87qrFaqjDO6+UrHYOGM9q8Wc8y0s Ft2vZCzOn9/AbnH/3k8mi8u75rBZzDi/j8li3cZb7BZrj9xlt/j/q5nZgctjy8qbTB47Z91l 99h2QNVj06pONo9/C6ewePRtWcXo8XmTXAB7FJdNSmpOZllqkb5dAldG449ZTAXzJCreTnzI 2sDYJ9LFyMkhIWAice3vFEYIW0ziwr31bF2MXBxCAksZJV73bWaHcD4zStxt/s0K03Fy4jdG iMQyRolV/88zQTjPGCX273jHBlLFJmAu8Wj7GSYQW1jATWLpnYdgO0QEdCRWvlzMCtLALPCU SeL9gYtgCV6gojdLXjGD2CwCqhLre9vZQWxRgQiJhVOfQtUISvyYfI8FxGYW0JR48WUSlC0u 0dx6E8qWl9i85i0zyAIJgftsEhOvXGOGuNtF4uS0zSwQtrDEq+Nb2CFsGYnOjoNMEA39jBLL b5xih3CmMEocn3aVCaLKWuLw8YusECv4JCZtmw40lQMozivR0SYEUeIh8eHEd6hljhKfLkNc JyQQK9G1/hPTBEa5WUiemIXkiVlInpiF5IkFjCyrGEVSS4tz01OLTfWKE3OLS/PS9ZLzczcx ApPQ6X/Hv+5gXHrM6hCj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5gvFbl1Kv/vtYCr/c1aeuv2mykxFKckWioxVxU nAgANehB8YQCAAA= X-CMS-MailID: 20180207155211eucas1p2d8d04871aaeb49efc30909d46e47e028 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180207155211eucas1p2d8d04871aaeb49efc30909d46e47e028 X-RootMTR: 20180207155211eucas1p2d8d04871aaeb49efc30909d46e47e028 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. Use 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 Cc: stable@vger.kernel.org # can be applied after commit 8f9702aad138 --- version 3: Change commit message: drop 'Fixes: 8f9702aad138' as the error was introduced earlier. version 2: Change commit message. 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);