Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4821804pxj; Wed, 12 May 2021 14:08:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLZgdsEiwL8iQswQVuk7LtYPvzJK7TYfJcqakT3Cx4TWzNLGtlzUQ55deWrLT/QJlvYMeQ X-Received: by 2002:aa7:c34b:: with SMTP id j11mr47181556edr.188.1620853733090; Wed, 12 May 2021 14:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620853733; cv=none; d=google.com; s=arc-20160816; b=TJmKkITKTyKyWV3um3KIJuuy8BlHFJ35IWAwDPIaIBFNh0nqPYZUNijioBa7gWsWEQ q7ggMQawYWuGMtcQyxXJyL+6oFIgm/Wq3z5usAjjMU/wa/696QuCE9qEYUQG/YJvHGb9 QNvLLWr3s4MaL4836ADorXwzrbpq48Hkc63SNeQaNBI2IYvaXMHXdHW3dy9Za1EvLQnV Z5me9ou0oLuleytwLfm/2M2xMz+Q+vmA6lM6ud2FuQyd4a5POZRdEzm0ojtFFFix2MZW Q+n/i5vmrhU/bX8nZEVbSb+nq5ErY5jIDxYuaE2ghvV1mi3Pz/AsMc1KFlMOQg2S9uTM lSdw== 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=bIO9ENbnc5g3U1ZzsC5FAF5m4NJt0+ptlcTvWOhcMrI=; b=cy4lJEc2trAT6cXiqUeO4UPIOZ7UbBe3p/Rn12yXuA0pxaaEpPodPy7cTbNGyNU/vt +quwY4M1TgfvCaNouKJ0zzyWM0gR7TIx4b+cPC7wX4C0nUFKbr0bEXlKB529deh8SYQG L070EGXbpGUrHuGtUxe0fclo1UJhDbkQM11XA8Dd5ApNm/SK5Jp7sM0BXe3pwBoC+u7P Ab5+SAnqH+c24Uxg3EF9zJkuLwouklWs1Q3EwXTGcWEfpGGBzWijV+VgELWDLehFGwyT 9wbeDG4UoXiO5RXcNrNsbI4SPTb0g1MSMhC+PJaSJLG1jl6AMuHhoJ7EFdLGXOfJOJ0W Tn9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XZEm9yTT; 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 o20si505565edr.268.2021.05.12.14.08.07; Wed, 12 May 2021 14:08:53 -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=XZEm9yTT; 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 S234466AbhELVHz (ORCPT + 99 others); Wed, 12 May 2021 17:07:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:56198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245234AbhELSqO (ORCPT ); Wed, 12 May 2021 14:46:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 504286141C; Wed, 12 May 2021 18:44:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620845090; bh=isWmI38USeF4NjdMkoUIY8ZmRIz+cWLvwEpazjfnYh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZEm9yTT3ICvLwUoBNGxZGZS9t+cp+ZGmnNwEPUPmavpwQqIZirSnL90Q4RKx2Nqs fnl5Hd30euD37o9wmeOQVTy4E4Cbi83pdff4SGSydHpPUV75yTpNTDqMUpaOlU4uwL QwCrLRDikY5sDJ5OSs2hK6u/iINNmEHepHlNb0NP04BJhg/f5u392RPq87HTmT1etB bn2nKRwL3mpxbP830Z8cfJi3xwqu/VJRfj7gSaBz58zMF0GIlt7cEfKP5z+iDTkJ7k 5IfDQr3AGqX6rD6R8lAK808ET6MLqlt1JGI1onFRBkoJZbTo8lRXx5aAjUs7JTv4Np JSXDaaP4noP9w== 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 v3 2/7] crypto: aead - disallow en/decrypt for non-task or non-softirq context Date: Wed, 12 May 2021 20:44:34 +0200 Message-Id: <20210512184439.8778-3-ardb@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210512184439.8778-1-ardb@kernel.org> References: <20210512184439.8778-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 | 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; -- 2.20.1