Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4821995pxj; Wed, 12 May 2021 14:09:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO49mtrNIvRAFCYJF44PKFJbJ+awmOOv+yfw+pfBiWStC80hVik89fywHe6SLdaXefU6MX X-Received: by 2002:a17:906:3042:: with SMTP id d2mr40172932ejd.234.1620853745785; Wed, 12 May 2021 14:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620853745; cv=none; d=google.com; s=arc-20160816; b=nPb33UgJTUYVevJikLbq/+xVVG2wKT0CTbuswVsptNc5Y8SnUv0sn7QSAhV9PdYuRU Wta6/gRQ5zJ4UT/72omX9giRmWm32H5IM6CoARe34UY5RHHCzg535q6ZjiZvlgEWHh5u t+7mDN03SJjntEiz0r5w0YGjjSNWsZZItB1jMlDRChyvYMKY+R3y/D7GATaJ9lwAOlmB JEesySFnBJEeWYEdDmEuE1lf+kyJKV+8DBRzat5LMiQTgNtjtBaUe6EZBh+rFVkqLOkG d80Re3N1rSApwDa+Co3XOSoZf9hyWubPscbM2klx81KN7gniVBLPbQmsZc1rsEmB3Z5D Yb1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tyzZG/2NfEJlWglY8IDKCitTdk46LqnDd7RcMasonWM=; b=OGHQToU1B5eSAygewLUIspZRWMEsu0IMoP3ecMcW0whbJ31K998zhABJ/5AMlnHYYO H0k7fhfw8GAK8LrjGjaiGHXV8ncMoEYKwQWPSImHJiss4uArtOS2LrbCMTRl/p95DNDJ 4wJaRmpcI4oTdjihZrusgqlmTonwd3lQs9ocWvtWR0mdbWt2uVLPsP4PE+J7KlAri5t+ B7RhDZwWV0r1gM9pW72p/lrUZj2aSZa4ta4ArKc/nFHAXyBmyMQWXMDcqeywoPLMWOit 9WN9h3dN0laV2xuT5j9oEgmFcHjRE7e1CBiTh7aGgnwu4F3NMy7b1nnrNXPJEnEtLWNY 60vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qPbmnlRz; 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 qh7si53296ejb.11.2021.05.12.14.08.07; Wed, 12 May 2021 14:09:05 -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=qPbmnlRz; 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 S238505AbhELVIH (ORCPT + 99 others); Wed, 12 May 2021 17:08:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:54332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385214AbhELUHL (ORCPT ); Wed, 12 May 2021 16:07:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7028C61408; Wed, 12 May 2021 20:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620849962; bh=QQfyPA2bVAhyX/rOl9YJ4esWVuFWaoi+C+eJcg9P1ZI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qPbmnlRzEOq2EYn0QnCivlyyxTPzs67SCwCKbY/BC0Hec2HrNRKomvk/+GKtXsTKC gdGL9CDENOLpR/PxmhMdJc1iuwAobNUVf7Rr6E/fPItTVPkXY3Cmz4IZAN7xfwtAwG MGoRPT1Illjx+wtlYVEQUjbQkeoKq/xnCTf2FZL6tW2ZejnDJCRpZRiku9NgIfDqR9 UiYkwC8TBrGvEo/b94tjKQua+0oDSeEtMF5lQVw0SwliIZli+amH1/HrqtGIGzvjP7 DDxRm7JopOF3o3Jv+9BFaYZTHJEnZJyMcnT918RItEKTUFNYc6X4AxFvbC5vs0kF4e zQSFZN5WwAnvw== Date: Wed, 12 May 2021 13:06:00 -0700 From: Eric Biggers To: Ard Biesheuvel Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, herbert@gondor.apana.org.au, will@kernel.org, kernel-team@android.com Subject: Re: [PATCH v3 2/7] crypto: aead - disallow en/decrypt for non-task or non-softirq context Message-ID: References: <20210512184439.8778-1-ardb@kernel.org> <20210512184439.8778-3-ardb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210512184439.8778-3-ardb@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, May 12, 2021 at 08:44:34PM +0200, Ard Biesheuvel wrote: > 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 | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/crypto/aead.c b/crypto/aead.c > index 16991095270d..b5304b3d3314 100644 > --- a/crypto/aead.c > +++ b/crypto/aead.c > @@ -87,6 +87,11 @@ int crypto_aead_encrypt(struct aead_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_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY) > ret = -ENOKEY; > @@ -104,6 +109,11 @@ int crypto_aead_decrypt(struct aead_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_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY) > ret = -ENOKEY; This probably should go after crypto_stats_get() so that the error gets counted in the stats (if stats are enabled) -- analogous to how the ENOKEY error is counted. Likewise for the skcipher patch. - Eric