From patchwork Thu Feb 11 20:01:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 381035 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp2374943jah; Thu, 11 Feb 2021 12:06:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvTp089SdB4/RGqMHh+lxg/Qr+MpOjAdqqnEZiBuW3AUane7rjgeZ59WTTsZ1igA2XyNiM X-Received: by 2002:a50:e14d:: with SMTP id i13mr9812373edl.106.1613073961562; Thu, 11 Feb 2021 12:06:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613073961; cv=none; d=google.com; s=arc-20160816; b=kSIivljW7U84NNO63JX9//Tm/oseCcwtps0PU8051rfD2yi0f2vpYi59HwyPiCOITN OQammwiMxe+D3VWDEIYdvzA0LOvo+ViDnHKTCkyUDI8icqXGyVy1S2QPEb09/ftJ1uPg H/eOPplOHHb9ck029W9rOdO9moxaQsa8cFQKiTj0cWD2am1mJ6D3ytxHpKMGCxlcegwJ fDXhudrOCa1ma+OVe4rAvKgMFn8BGQxS0MNdBCi7Od82lNa2IRUzB0plqORqFNBcPXol 0rujdzLLMjJzLVmOyt961PcI7tEmctrUJmeM9PvWWkhnwzYFPL9ivxRSGDDdqQd0g+y2 9Pvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YQw1QuSS5oaizNhzVqE2AsZ3JEvDzAP/RbpFDDieAO4=; b=keemu+gEZypaJ1qfN6yPRHXjMf72kkNT0SLwgDBlT5OqOLannyn6Tvd9OpLnOogAda emTP+hY3UeBIyiikCLEaSThA/QbSEzCWD/45g36W9C5edQNVH4e5NZgZZ6nI+JRdkXJW rtiExwZ0qfy89/ocOeNxiRxbORq+DLODoiZz1BSYwJNHZuQHTkht/82NNJXK2fWQy3kA GXgIdS3a1OPsJECIlT/KYQTPJT8s9ba7bNYkgXSSwgbZifY5asFxsGIOP+RAqufdEwV5 84RPjS9fy9jlU4dWhrV4AhpYZaiLmHXw/hxKKKI/4yQohFzzGgYuyi2f0thQOGZydIyE 8o0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=elxvkxij; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hy24si4520322ejc.149.2021.02.11.12.06.01; Thu, 11 Feb 2021 12:06:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=elxvkxij; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231667AbhBKUFI (ORCPT + 2 others); Thu, 11 Feb 2021 15:05:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231423AbhBKUDF (ORCPT ); Thu, 11 Feb 2021 15:03:05 -0500 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84B49C0617A9 for ; Thu, 11 Feb 2021 12:01:36 -0800 (PST) Received: by mail-qk1-x729.google.com with SMTP id w19so6064992qki.13 for ; Thu, 11 Feb 2021 12:01:36 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=YQw1QuSS5oaizNhzVqE2AsZ3JEvDzAP/RbpFDDieAO4=; b=elxvkxijIo5vM1d01jehM7Zocli7jXl4HHZG/sZjNMJgPZ5LJyofQWYcHuMde1I/OR tOryM5IAtZIQQ6EOCGjoC0dtjeVvxyT2L06Sx29SvB+/CUKZNMGKaGTz4YyFbSeM4xGE bOoEkE5moR10oJi0cJP3Nlk5iwsqCXT0mc6O3WiR1I6hib2MLVk24ecLg7jtSPIMfwvY aOr3dUrRbuXA6D0nEdLncYFbf4JkEd+azicP7JdWkYCxpQKUnYsnGTRSYQ6XvWiVgTHO SsePqoYsJ8XHMrOvUhDX5VllRl70bdotzaIfJ2v6tJv9O91rS8o5gnOsnMNW4a80u4sl 6aUw== 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:mime-version:content-transfer-encoding; bh=YQw1QuSS5oaizNhzVqE2AsZ3JEvDzAP/RbpFDDieAO4=; b=drnu+D85mauabfLkwAo3hTQqe/GnsseMQfrC301sqVCirpblDaystaD7HRzQcgCEKo ht9p9WKNvM0v4YPaNU5p/kPEltDRmmPOrAgvsAnjXPROkwBU8RiI11D2BqE7s1TAPPT4 ul341KtYZY0dsmPFRvkMhxuDdT/4UVHvfiv/KdKYUoQCJMMKTv8L3BrzeahRmuI5s8fE yudZSr6yZ89Ybtt9qRhSiduV4JCRUsCDyvjmU94wBfNQkaaeWuZLd03O4xE+ZDOYdJKc 56vZNXWo/gQpAfIVA3oFlM5aHSw4Y4jHZWptfLI6QrVznFtQ6sfY+Kio7OnOlpz5gZ0E tE0A== X-Gm-Message-State: AOAM532IHvSWYrwNc93dGtY0ZcDVRAD+3N1ZI2s5B6KqjBiwmPm8mvn6 l8dL8NY5m27vt4S2oQDjbOgYoA== X-Received: by 2002:ae9:eb95:: with SMTP id b143mr10182741qkg.442.1613073695803; Thu, 11 Feb 2021 12:01:35 -0800 (PST) Received: from pop-os.fios-router.home (pool-71-163-245-5.washdc.fios.verizon.net. [71.163.245.5]) by smtp.googlemail.com with ESMTPSA id 17sm4496243qtu.23.2021.02.11.12.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 12:01:35 -0800 (PST) From: Thara Gopinath To: herbert@gondor.apana.org.au, davem@davemloft.net, bjorn.andersson@linaro.org Cc: ebiggers@google.com, ardb@kernel.org, sivaprak@codeaurora.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 06/11] crypto: qce: skcipher: Return error for non-blocksize data(ECB/CBC algorithms) Date: Thu, 11 Feb 2021 15:01:23 -0500 Message-Id: <20210211200128.2886388-7-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210211200128.2886388-1-thara.gopinath@linaro.org> References: <20210211200128.2886388-1-thara.gopinath@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org ECB/CBC encryption/decryption requires the data to be blocksize aligned. Crypto engine hangs on non-block sized operations for these algorithms. Return invalid data if data size is not blocksize aligned for these algorithms. Signed-off-by: Thara Gopinath --- v5->v6: - Remove the wrong TODO which implied that AES CBC can do partial block sizes when it is actually CTS mode that can as pointed out by Eric Biggers. drivers/crypto/qce/skcipher.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.25.1 diff --git a/drivers/crypto/qce/skcipher.c b/drivers/crypto/qce/skcipher.c index 6b3dc3a9797c..c2f0469ffb22 100644 --- a/drivers/crypto/qce/skcipher.c +++ b/drivers/crypto/qce/skcipher.c @@ -254,6 +254,7 @@ static int qce_skcipher_crypt(struct skcipher_request *req, int encrypt) struct qce_cipher_ctx *ctx = crypto_skcipher_ctx(tfm); struct qce_cipher_reqctx *rctx = skcipher_request_ctx(req); struct qce_alg_template *tmpl = to_cipher_tmpl(tfm); + unsigned int blocksize = crypto_skcipher_blocksize(tfm); int keylen; int ret; @@ -265,6 +266,14 @@ static int qce_skcipher_crypt(struct skcipher_request *req, int encrypt) if (!req->cryptlen) return 0; + /* + * ECB and CBC algorithms require message lengths to be + * multiples of block size. + */ + if (IS_ECB(rctx->flags) || IS_CBC(rctx->flags)) + if (!IS_ALIGNED(req->cryptlen, blocksize)) + return -EINVAL; + /* qce is hanging when AES-XTS request len > QCE_SECTOR_SIZE and * is not a multiple of it; pass such requests to the fallback */