Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp1547131lkv; Wed, 19 May 2021 12:28:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqWiTidbZOsluXoXGw1Q9oQRnmQyKaON5xsrbnSg6R3lQumo0ZZKni+NKRbHeNfG5BXTrT X-Received: by 2002:a02:2a8c:: with SMTP id w134mr710135jaw.138.1621452525525; Wed, 19 May 2021 12:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621452525; cv=none; d=google.com; s=arc-20160816; b=e5Z5xIwOOG8z/gny6mkCi5aSRtDxjWuwzQAikYt+UKE548AbgdIw/brVuAuWD43omL FmPR4mzEUnitZ6BWYcQKtMLcJWUEj+djL0L7JpAdMqlzfWrDwmn0UZ2vEybsrasnnbBF VcnQcvUjcvKeTvNsRPTY5dH7AONOpH6cRqwjcnaec17dd1ivfIchEwWISUSeD/8zR3Ir kgdABuxZsZpM7wcqoRYIHSbPm956BhOFi+KMw+xLqjxGfxONW9Tt0qup7F/YnfAIclda d6tDuhJyyUX+eKPMW6KTP5OgFV9gxUFlzEj/mj3z2bHEdzMNamNTgNoe9EBvNtXxI7rJ p4ew== 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=HlmrqCFxXx3XbC42k+eYQ7vCsO6QbCHUDG9/4ewNQ/M=; b=ytiDIDuJFodvjz/Z2lfRFY5Hd8Zodsd9GMGzZJqzIKO4tWZsTFj2tyTgy63pmUKSox uUrHpLSsCRalZ01K9zcM6sEDOUL1fpd/h378G9bK9kcAmgbWbraF6Aouh1OU5t9Xpve/ yRGVQWigzf/Ggo837/WpZiYYMd+49dpQ8PrVkEKH5DulpNBaCyllYP+dEZD5b2q+YAHX osMqr3CUA6WcDMSkqMIEtlAZnsplEOA2J9VBcbzF2Rqt3axlMmu1JeSKiAQlD56Aw58I Vq+A7vIcdB+WVaZQ73nBW32O/eUxWhofzmRY6q3ku99PjHgSTiqxmLhK7G3fYhxOJDBl BE6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YTBW9tRu; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t14si182863ios.45.2021.05.19.12.28.26; Wed, 19 May 2021 12:28:45 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=YTBW9tRu; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241088AbhESLYO (ORCPT + 99 others); Wed, 19 May 2021 07:24:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:52828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350132AbhESLYI (ORCPT ); Wed, 19 May 2021 07:24:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0E1616135F; Wed, 19 May 2021 11:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621423368; bh=eLg/GSNSaqnJy8ioL9ZrQp36Kv1wIh+t1ziwjtWeq0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YTBW9tRuQbImgmgw59v2K5Fm3MCDjSuQOZvtdYxYSFtz7f/8icRBHiqYkn9ddoYc/ Qd35YfxLLgremuJZzMdltvKTfxivFo4FsSHou7MNya1roI1jrD6XgrDyppxtrQKOkV Cai76pWvXMKb6xNu1ZkI8n72zqyOZbCt6uZ7fgAtba4vSMPEFFOIuKxjcm6BL/Jaai xZYsyyszH+AkaCpl6EjtA3IjpEeoxYdyeTjJP4j6O4ISZr7rtRP1sOZLKVdZOfd9dW 3Z3+KcjoNXsfVgnG3woKlH3sUcwKGaIxDPbUARjjM049tp7wfnQEv18ViY79WZfwxQ y7i5fWp0gsaLg== From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, ebiggers@kernel.org, herbert@gondor.apana.org.au, will@kernel.org, kernel-team@android.com, Ard Biesheuvel Subject: [PATCH v4 2/7] crypto: aead - disallow en/decrypt for non-task or non-softirq context Date: Wed, 19 May 2021 13:22:34 +0200 Message-Id: <20210519112239.33664-3-ardb@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210519112239.33664-1-ardb@kernel.org> References: <20210519112239.33664-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 AEAD encrypt and decrypt routines from outside of task or softirq context. Signed-off-by: Ard Biesheuvel --- crypto/aead.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crypto/aead.c b/crypto/aead.c index 16991095270d..141c9369b02a 100644 --- a/crypto/aead.c +++ b/crypto/aead.c @@ -88,7 +88,11 @@ int crypto_aead_encrypt(struct aead_request *req) int ret; crypto_stats_get(alg); - if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY) + if (!(alg->cra_flags & CRYPTO_ALG_ASYNC) && + WARN_ONCE(!in_task() && !in_serving_softirq(), + "synchronous call from invalid context\n")) + ret = -EBUSY; + else if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY) ret = -ENOKEY; else ret = crypto_aead_alg(aead)->encrypt(req); @@ -105,7 +109,11 @@ int crypto_aead_decrypt(struct aead_request *req) int ret; crypto_stats_get(alg); - if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY) + if (!(alg->cra_flags & CRYPTO_ALG_ASYNC) && + WARN_ONCE(!in_task() && !in_serving_softirq(), + "synchronous call from invalid context\n")) + ret = -EBUSY; + else if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY) ret = -ENOKEY; else if (req->cryptlen < crypto_aead_authsize(aead)) ret = -EINVAL; -- 2.20.1