From patchwork Mon Aug 19 14:22:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11101173 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C03FC14DE for ; Mon, 19 Aug 2019 14:24:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFA282877E for ; Mon, 19 Aug 2019 14:24:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3A6428896; Mon, 19 Aug 2019 14:24:10 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 13EE62877E for ; Mon, 19 Aug 2019 14:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726784AbfHSOYJ (ORCPT ); Mon, 19 Aug 2019 10:24:09 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:54463 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726842AbfHSOYJ (ORCPT ); Mon, 19 Aug 2019 10:24:09 -0400 Received: by mail-wm1-f66.google.com with SMTP id p74so1801240wme.4 for ; Mon, 19 Aug 2019 07:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=okCdUHYHWt8s+0k5Gl5UgSWbhxR2JAmRuhLJNchPGYI=; b=CIAwk/2xz5Fk3vpsS5zaUx5blmwut8crvHyNuE1nZV7u49BJOzwxN+pcuH007DJF9X MnH1y5G9MnyJE+DGRdBqswFOhlHsVdGgGFwDWtdmNU3GQWQZBt5hnymnkWsyx9FNt8iJ BNSyrC3Nh6tjtztCCQjW9y3BMd4BRKWGaulhagaIJqq/BpRRW/pSDdebDXS1763t14Ma o3mMv55QwC9jySRQf/uLrIuZmFrm2nWOMAzlwfmIGF4wWfCZikKrlvD0KcC7vJfuXDZB +UCNpavKC4HW5TLPWRwEjG4AkY/vyRYAzwfZqVeIou7qYmOuzvfUJo8u2h8iTlx1IMsT 72zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=okCdUHYHWt8s+0k5Gl5UgSWbhxR2JAmRuhLJNchPGYI=; b=rSzjPOp4A5AuQSz5HR5GCkW2mbzDgluiF6dvrxTRpefP/BbNOz2Gf4d3ZHeZ7lv9UK G8jY6HeeIkX6Kj9D07gHAFNllrro8Gc6oHOadawkwj2M6B7YpvICGmtE7rtae4bKES+9 efpFtzRNp2kpMgSWjnORCpMMuk0Zea8D2R091F4go3JB/RgPy51SV26FNthEtawJnSSd 0ZShBD/y43b+1pUAmMNSUWztCe+bSKPx+edLdSMoR+JkTpiG9SK9DpITtPfRc+wNIQ5K WYqKiRI/16pNnmy/XOKhZX7+pS7nbyRbX+wDdzKVFNq+B42vW6WbDO7VggfjvyGVhAav U2HQ== X-Gm-Message-State: APjAAAUZn1HRGWoHadDwUVu026DyTgJusB8Sjd7wIBxR6vx8tjLk9etT IpSR7oXXDe4/iJ/j9xiGbBjo5bcJRT8xEw== X-Google-Smtp-Source: APXvYqzLJ657/WQvIhrtl+/1INZDJrbRbFhnGrWe3DRgCNYGkxPq1v84s8c8ACnaplqfEsLwbpG2ww== X-Received: by 2002:a1c:1a87:: with SMTP id a129mr20621847wma.21.1566224647192; Mon, 19 Aug 2019 07:24:07 -0700 (PDT) Received: from localhost.localdomain (11.172.185.81.rev.sfr.net. [81.185.172.11]) by smtp.gmail.com with ESMTPSA id o17sm13643356wrx.60.2019.08.19.07.22.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Aug 2019 07:24:06 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel , Krzysztof Kozlowski , Vladimir Zapolskiy , Kamil Konieczny , linux-samsung-soc@vger.kernel.org Subject: [PATCH 1/2] crypto: s5p - deal gracefully with bogus input sizes Date: Mon, 19 Aug 2019 17:22:25 +0300 Message-Id: <20190819142226.1703-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190819142226.1703-1-ard.biesheuvel@linaro.org> References: <20190819142226.1703-1-ard.biesheuvel@linaro.org> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The s5p skcipher driver returns -EINVAL for zero length inputs, which deviates from the behavior of the generic ECB template, and causes fuzz tests to fail. In cases where the input is not a multiple of the AES block size (and the chaining mode is not CTR), it prints an error to the kernel log, which is a thing we usually try to avoid in response to situations that can be triggered by unprivileged users. Signed-off-by: Ard Biesheuvel Acked-by: Kamil Konieczny Reviewed-by: Krzysztof Kozlowski --- drivers/crypto/s5p-sss.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c index 9ef25230c199..ef90c58edb1f 100644 --- a/drivers/crypto/s5p-sss.c +++ b/drivers/crypto/s5p-sss.c @@ -2056,9 +2056,12 @@ static int s5p_aes_crypt(struct ablkcipher_request *req, unsigned long mode) struct s5p_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm); struct s5p_aes_dev *dev = ctx->dev; + if (!req->nbytes) + return 0; + if (!IS_ALIGNED(req->nbytes, AES_BLOCK_SIZE) && ((mode & FLAGS_AES_MODE_MASK) != FLAGS_AES_CTR)) { - dev_err(dev->dev, "request size is not exact amount of AES blocks\n"); + dev_dbg(dev->dev, "request size is not exact amount of AES blocks\n"); return -EINVAL; } From patchwork Mon Aug 19 14:22:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 11101177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 703321398 for ; Mon, 19 Aug 2019 14:24:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E0FB2883C for ; Mon, 19 Aug 2019 14:24:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5227E28515; Mon, 19 Aug 2019 14:24:12 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 0658228762 for ; Mon, 19 Aug 2019 14:24:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726343AbfHSOYL (ORCPT ); Mon, 19 Aug 2019 10:24:11 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:54031 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726186AbfHSOYL (ORCPT ); Mon, 19 Aug 2019 10:24:11 -0400 Received: by mail-wm1-f65.google.com with SMTP id 10so1803897wmp.3 for ; Mon, 19 Aug 2019 07:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ze9YdeG54uGI/7oCptuYPG1qBhEdnJDuSAQDXLeVnX8=; b=dDjKzbkH+8BuYJwEP1RMQY7sy1oABKnDPP6BZiuKeRpsp1tRLXNnZuDXQfS2QxV9wu 2Ndjj6gIYsj46tlKHLfCAl0hUJXoTnQymqYntNbhx2KyNdty+5H398adZV9NFh+bHEZw M/GNc2IAga8TN5JRedboXn68L9aHaGiPe33lnS3CB0DwT48xGzxuRU/WZxdwYqeLTlEr 0/8AQKldpcdz0u2su35MkNWYOkYYzsTUX230d01gOf6w3kmfEoXDOjrMHswvZHT10D9A vfakDyKoQ4heQd5Q61UiKtBlf+PIrUqTPdy2ZFOdxbpznrVayWnD7iZd5gA3qTZLl2xh CqwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ze9YdeG54uGI/7oCptuYPG1qBhEdnJDuSAQDXLeVnX8=; b=GHOiD0X7WjU3zDVmZdUV1fatFczZ+nl9A8t0PC9fx2ttpXH4xiWXJi+yK0kOyQJbiO 9jacZeQmNThLmQzbALkQGBFBdrUhMXGBFsbCj2QfpgwMDlMlSxzgoed3ywcIiPlvWR4/ cAeibINrEA70XnrmYCES8ZdD+n4Tw2D3eirUm3fSy1+Ft0TNHTRvIsKqaV/EnXj1BIP+ BcFst+6aGcIyQwsqz8K2YclLG20BKCmOUlvtBjZevqWw2CzU3uIImbFDDL8zjkgMJ3gx MOAbIRs5lnkxMleC5SUFDL4nxy/pGoBDN46nP/3/S5FqG31ZMX/1A19KnBOdUrbs8+2T ZyxQ== X-Gm-Message-State: APjAAAWAgc1F5GtJHhCMpthSJadqBxPzS892iipnTXCOCGEP8BA6r+Re kavvj1DTmlpVMbG8KNs2fUjwog== X-Google-Smtp-Source: APXvYqygMJUa/tZIg/byfGERZ+ObqMC3mPulIseS0856HX0WwZs8zbz1LXPdnk3TxkpIcf5Aetlp3A== X-Received: by 2002:a1c:1d42:: with SMTP id d63mr19913988wmd.34.1566224649604; Mon, 19 Aug 2019 07:24:09 -0700 (PDT) Received: from localhost.localdomain (11.172.185.81.rev.sfr.net. [81.185.172.11]) by smtp.gmail.com with ESMTPSA id o17sm13643356wrx.60.2019.08.19.07.24.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Aug 2019 07:24:09 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel , Krzysztof Kozlowski , Vladimir Zapolskiy , Kamil Konieczny , linux-samsung-soc@vger.kernel.org Subject: [PATCH 2/2] crypto: s5p - use correct block size of 1 for ctr(aes) Date: Mon, 19 Aug 2019 17:22:26 +0300 Message-Id: <20190819142226.1703-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190819142226.1703-1-ard.biesheuvel@linaro.org> References: <20190819142226.1703-1-ard.biesheuvel@linaro.org> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Align the s5p ctr(aes) implementation with other implementations of the same mode, by setting the block size to 1. Signed-off-by: Ard Biesheuvel Acked-by: Kamil Konieczny Reviewed-by: Krzysztof Kozlowski --- drivers/crypto/s5p-sss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c index ef90c58edb1f..010f1bb20dad 100644 --- a/drivers/crypto/s5p-sss.c +++ b/drivers/crypto/s5p-sss.c @@ -2173,7 +2173,7 @@ static struct crypto_alg algs[] = { .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY, - .cra_blocksize = AES_BLOCK_SIZE, + .cra_blocksize = 1, .cra_ctxsize = sizeof(struct s5p_aes_ctx), .cra_alignmask = 0x0f, .cra_type = &crypto_ablkcipher_type,