From patchwork Tue Jan 10 13:50:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 41484 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2759002wrt; Tue, 10 Jan 2023 05:56:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXvxqWSoHR3N8hE0ZA6Ps2cx2YODPcnSobf3k282xHTpFeHjhPlZlkJv+8BjibpI5jBbIKvl X-Received: by 2002:a17:90a:6002:b0:216:cdc7:58bb with SMTP id y2-20020a17090a600200b00216cdc758bbmr17681146pji.34.1673359007862; Tue, 10 Jan 2023 05:56:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673359007; cv=none; d=google.com; s=arc-20160816; b=DgtgMSyOySvOSJDd1A9tce/HkTV9tDCdQ6ThM7pdWt3yjhglwts0DrrCScz/Ihq3yS ffX0RF9sMtJ/CxQSzNnfFvI03j9j8cyVChNaP6eDuC3PvAoprlEJGLXjE2nlHnOCcAaF 9DKul2fooNCri/g5EP5kC7KXtRYv2unZFQ3Q918zm1VJxwxPzqN/6rbgmqrcX1yko1nU Lfh8W7gIQ7QKbQbfsM5zh/kfM/NDKzEx2sgrZKnYBbCuTC2+mwC+ZtzzgyG2NPR0NcAj FezrtRs+NNTL1Vtr9SCNUYS3FAN5+MDwecFjHiVesZl0sPdL9a0KLMfvqHhrfHbACLK5 BeJA== 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=aLzM1DqrhyrQcK4KEJ/Hu+9Ne9qneBcLpxAgA6Jk/n8=; b=ClpAXfMGNxO6WTakmr5JFqQvHS2a8f3f5IPa6PecAi6zJhKsEUCahQWQcMqFaDKyVl 1LvewV3jWrFocClVLa4TH89mfeEH2372CFr3ivw7PUPlZPbuCKKK2eCfMSTO8sSz+e5B OBAWkJ7iikkwYIEkl2TrX2J2l4Tal/ZFddiW2/ES2b0okHE0bOsPcw/LDT934NkxXxrC RJusX0poAp1Z9PbVjxOoqIdQK/h3qxKstibUSF48tNkUYni3Fg3S/mm+VlPgVjL5TZVf MPdBpaOa04nho8hhK1BcPh0EYSjfeYgDUNQ1p9csveJPeQhbgSesu2wKHLNIT4skjBoG u0bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b="Yhvk8/Lw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lr2-20020a17090b4b8200b0021409b2423esi16876127pjb.86.2023.01.10.05.56.34; Tue, 10 Jan 2023 05:56:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b="Yhvk8/Lw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238680AbjAJNvp (ORCPT + 99 others); Tue, 10 Jan 2023 08:51:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238403AbjAJNvE (ORCPT ); Tue, 10 Jan 2023 08:51:04 -0500 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1439CA45C; Tue, 10 Jan 2023 05:51:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358662; x=1704894662; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aLzM1DqrhyrQcK4KEJ/Hu+9Ne9qneBcLpxAgA6Jk/n8=; b=Yhvk8/Lwf0TTW//K06FShn0nKFZRo7wAi4oEconRPllfGI+cTNvmmBub U6eH5vro7Kkv4yF+64FTkb12ykjZc8ONyN63Lf9rzYhV0Ul+VmeAG50ot hlk2EepWKMfcR+e9CzBqtuGlafyAAaagujN+Jdj5L5DBu2cwVb1VF1ZpK bLCul3r1qHajg2L0eN+ZTRO/oIWWPogndnnJmT86oyGZKyM++jAhJvjXO YKtqBGGq1aLkuIsITW23qtuTy4DdkWoF6KzQu5/CupnmZPj3+L93OWUaE pmvbofEvwGhQPyeXVscge+mZLoc1crjudxIK44nXqX5gSmK8Ls5loLa11 Q==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 06/12] crypto: axis - reject invalid sizes Date: Tue, 10 Jan 2023 14:50:36 +0100 Message-ID: <20230110135042.2940847-7-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754644095286725866?= X-GMAIL-MSGID: =?utf-8?q?1754644095286725866?= Reject invalid sizes in block ciphers to fix hangs in CRYPTO_MANAGER_EXTRA_TESTS like this: artpec6-ecb-aes "random: len=55 klen=32" decryption random: inplace_one_sglist use_final nosimd src_divs=[87.4%@+1524, 12.96%@+3553] key_offset=84 Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index 0ffe6e0045aa..78d067ce4138 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -1188,6 +1188,22 @@ static int artpec6_crypto_decrypt(struct skcipher_request *req) return artpec6_crypto_submit(&req_ctx->common); } +static int artpec6_crypto_block_encrypt(struct skcipher_request *req) +{ + if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) + return -EINVAL; + + return artpec6_crypto_encrypt(req); +} + +static int artpec6_crypto_block_decrypt(struct skcipher_request *req) +{ + if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) + return -EINVAL; + + return artpec6_crypto_decrypt(req); +} + static int artpec6_crypto_ctr_crypt(struct skcipher_request *req, bool encrypt) { @@ -2757,8 +2773,8 @@ static struct skcipher_alg crypto_algos[] = { .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, .setkey = artpec6_crypto_cipher_set_key, - .encrypt = artpec6_crypto_encrypt, - .decrypt = artpec6_crypto_decrypt, + .encrypt = artpec6_crypto_block_encrypt, + .decrypt = artpec6_crypto_block_decrypt, .init = artpec6_crypto_aes_ecb_init, .exit = artpec6_crypto_aes_exit, }, @@ -2802,8 +2818,8 @@ static struct skcipher_alg crypto_algos[] = { .max_keysize = AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, .setkey = artpec6_crypto_cipher_set_key, - .encrypt = artpec6_crypto_encrypt, - .decrypt = artpec6_crypto_decrypt, + .encrypt = artpec6_crypto_block_encrypt, + .decrypt = artpec6_crypto_block_decrypt, .init = artpec6_crypto_aes_cbc_init, .exit = artpec6_crypto_aes_exit },