Received: by 10.223.176.5 with SMTP id f5csp2780191wra; Mon, 5 Feb 2018 09:42:46 -0800 (PST) X-Google-Smtp-Source: AH8x227oWiJq3z8GihgZcpfTZyk8JTAR3EgtZMrAvq8ArU14/T/61kEXhN+YE5f8OY4rHZhscy7o X-Received: by 2002:a17:902:1665:: with SMTP id g92-v6mr44608025plg.245.1517852566392; Mon, 05 Feb 2018 09:42:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517852566; cv=none; d=google.com; s=arc-20160816; b=pA88ArLZGMcGirR6Nzl5xGt1OkFMVxG7e2sHafBgK9Oe0EiABtiEOmCUCk0S2frXsc 9wYzo4nI0dMTocReRDtzk8W7jWcCYTHnuPqQB4FQgroYXqYA0qBMVkmhOa29+bkNtATR x06V/5JVJLYXBxtR33pVz9an0RWB2vPcWq49LE8acRVgxvPfa3Yim1lG66dwRoI9EmMi PW/ietV0xIrIDJnkMgYEU+Q0uYPxtcJgkMCZx1jxVyWZU5uBkSUC4c1KgexyZddlekng gVZEY648ll7uFOWVc6GE1PUCr+Z+Hpx2/2vL668hyfUDBStpcvHOqgEuSMmzTUoj1Qyp r8bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type :content-transfer-encoding:content-language:mime-version:user-agent :date:message-id:cc:to:subject:from:dkim-signature:dkim-filter :arc-authentication-results; bh=Mvgsd/Hk3z+P/fvqwyacafu2T6EJAT9jn544rFsy8ro=; b=u1DxS0xVjboWE41H7fglCOO4GKDlShqVDWYuXwGZktvfRtW6ZogmlZzVd7Uu2c7cb4 QLHdbneDeffVOzE2ixYpoiJ3E4udVWBRBXRrzKpzs6keVoIXlQ4n77g1YgaEoEKnUdg0 T4CQBZqRIkfMEVznSjOuAjky0lNjR8t+uR2BqRt205PeqkJo80l98BO6XnIy6Pq85aUT eQIcVM2PvcP3Kjce2flIwkvq3ESCEFc0VVTUt4DZTHEx9JsC6WUpRlKnwuYmXvXd2cKQ 4NLC2pgpn4vaJFnZmej5t7iLU6klwt5sbXPj+uYFe+rT3g5oKDSH/g14LpA78YN1VJtI DZnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=TtPKiV7O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u87si6699051pfj.41.2018.02.05.09.42.30; Mon, 05 Feb 2018 09:42:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=TtPKiV7O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753392AbeBERkg (ORCPT + 99 others); Mon, 5 Feb 2018 12:40:36 -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/oTVIUYBDkYlHt4dqRVRQqyJZcWVuYcYJTiYlUR4na6XRwnxpiRWVqUW5ccXleakFh9i lOZgURLntY1qixQSSE8sSc1OTS1ILYLJMnFwSjUwsl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-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180205174022eucas1p101e8339284c1f0ac8f40f70c24de1c1f X-RootMTR: 20180205174022eucas1p101e8339284c1f0ac8f40f70c24de1c1f References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- 2.16.0