From patchwork Fri Dec 18 17:01:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 345534 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FF60C3526B for ; Fri, 18 Dec 2020 17:04:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7229723B74 for ; Fri, 18 Dec 2020 17:04:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732072AbgLRRDw (ORCPT ); Fri, 18 Dec 2020 12:03:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:54272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725797AbgLRRDw (ORCPT ); Fri, 18 Dec 2020 12:03:52 -0500 From: Ard Biesheuvel Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-crypto@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Ard Biesheuvel , Dave Martin , Mark Brown , Herbert Xu , Eric Biggers , Will Deacon , Catalin Marinas , Thomas Gleixner , Peter Zijlstra , Sebastian Andrzej Siewior , Ingo Molnar Subject: [RFC PATCH 2/5] crypto: skcipher - disallow en/decrypt for non-task or non-softirq context Date: Fri, 18 Dec 2020 18:01:03 +0100 Message-Id: <20201218170106.23280-3-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201218170106.23280-1-ardb@kernel.org> References: <20201218170106.23280-1-ardb@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org In order to ensure that kernel mode SIMD routines will not need a scalar fallback if they run with softirqs disabled, disallow any use of the skcipher encrypt and decrypt routines from outside of task or softirq context. Signed-off-by: Ard Biesheuvel --- crypto/skcipher.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crypto/skcipher.c b/crypto/skcipher.c index b4dae640de9f..d1a656d7d498 100644 --- a/crypto/skcipher.c +++ b/crypto/skcipher.c @@ -628,6 +628,11 @@ int crypto_skcipher_encrypt(struct skcipher_request *req) unsigned int cryptlen = req->cryptlen; int ret; + if (!(alg->cra_flags & CRYPTO_ALG_ASYNC) && + WARN_ONCE(!in_task() && !in_serving_softirq(), + "synchronous call from invalid context\n")) + return -EBUSY; + crypto_stats_get(alg); if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) ret = -ENOKEY; @@ -645,6 +650,11 @@ int crypto_skcipher_decrypt(struct skcipher_request *req) unsigned int cryptlen = req->cryptlen; int ret; + if (!(alg->cra_flags & CRYPTO_ALG_ASYNC) && + WARN_ONCE(!in_task() && !in_serving_softirq(), + "synchronous call from invalid context\n")) + return -EBUSY; + crypto_stats_get(alg); if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY) ret = -ENOKEY;