Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4875785pxj; Wed, 12 May 2021 15:24:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOO1rYKzJ5Bv+Wj05lhMv7saDmiPISRpsj30qxH8/Dqp8wDGrlKHd1sYCRMElqZOg0NkkV X-Received: by 2002:a17:907:c1c:: with SMTP id ga28mr40248130ejc.122.1620858286384; Wed, 12 May 2021 15:24:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620858286; cv=none; d=google.com; s=arc-20160816; b=kv+4cDJP409dbI4z/xoKNHi4sh0JoOn5eB3+bTuaU7CRrm9uESkyMels2iSeMBs3Hk gpoPQzaKAdUF5Yuar6shAPlYH3BdPNhypJWnc64JhjNIhTsthe0Lq4q+5jhIeZvP1ioe EROS1ezeDPf4zEMuREPDkmy+poB4fkeqQgBC3URKBI9GVmpirqANl/FZvY6alLewGe6u Af531QsxKHPbW53Lv+B0dEas6s9OWW56VpV4C/EOVXfmTOelbA+ZBoEDR3g9d3BaP15e uyWIvBWbuNOq5Tfno3VM2RjzBpdBuIyckvcnE8hYeq5zypJGTLAQXdAOv5/yec+r7xcS Wq1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ffSJXKpyrLd2e22BNh8CozzcziIiwSR/pJU62Tr1ugk=; b=HUCxbuv2YyCE+8gzKDt+aT04icOXVHJDrbLNGRHrQXqy55JdEXsL4vnpp5sRu/Xl/9 TwhSa6w+zbHTETCgVmdUwFZsRg2gkXTYBskSulyIFgDkaRV35h1JaL5sAccbCFBPIg7q SBWfotnJXBkvHMiznSEVPcrbKFARiU4ixY74pGY8sVXnUHCIEZHgHy3XJccar6aUUDgC s0PyyRebBPwLfIHGg0oRXnAMXGkdi/ZBIfgC1mssFlEo+IYQbw0f8b29+7sF/rgBjgfs 9jNmZ8rQeEIVtgSTEmRsAzl3iFq3g0tdntUKGuUUgdzpsPWC05PSMayudbQCXFio7FEQ uZxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HZguiLPH; 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 dn20si1169073ejc.549.2021.05.12.15.24.15; Wed, 12 May 2021 15:24:46 -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=HZguiLPH; 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 S229854AbhELWYR (ORCPT + 99 others); Wed, 12 May 2021 18:24:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:49648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391312AbhELV0L (ORCPT ); Wed, 12 May 2021 17:26:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1608F613F7 for ; Wed, 12 May 2021 21:25:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620854703; bh=f95kky9fWPP9zmOAqEAX7s3lv8BZDFV+H/qK5UnLA5Y=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=HZguiLPH5qdbXAdBg478u9jptd5qxHD/I1Amhw3QGV1r4dOZcrZ0BrqqZcgJiYPUK NabD9JhMOTmZrHnm95ThqAbRAhmYImRURAdQraL/FNwiunW91rOoEKCWivfsNi8bUY ZlPvK4za5i6NpONGTNYQW4TSfT8e/JdR6v7v0UYYQ6TkTuOELqI/pWlbivg3JXXk39 ZD/0bPkgeJ7kXbVHw3UbitKM/oGXOPQZ9mwsseb1XFajKkd63rTU4iqEwHBP8zx+Yg Lxhht5t/s74TgeHcsviEACyGjrAxPl1OIXDmU+sj974I71bRt5Nh0cjTRVrdP58OMj DRYS3HiU5SMsg== Received: by mail-ot1-f44.google.com with SMTP id i23-20020a9d68d70000b02902dc19ed4c15so17889057oto.0 for ; Wed, 12 May 2021 14:25:03 -0700 (PDT) X-Gm-Message-State: AOAM532wdHMlygSDARvgBI8aSSzDIS2WihK0kSxM6xjrvLb0x++rXLEA uuJtLyrJV3CrdpmMZnJrkm9y6mSc/oQ2BoZGA5g= X-Received: by 2002:aca:4056:: with SMTP id n83mr386361oia.47.1620854702296; Wed, 12 May 2021 14:25:02 -0700 (PDT) MIME-Version: 1.0 References: <20210512184439.8778-1-ardb@kernel.org> <20210512184439.8778-3-ardb@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Wed, 12 May 2021 23:24:51 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 2/7] crypto: aead - disallow en/decrypt for non-task or non-softirq context To: Eric Biggers Cc: Linux Crypto Mailing List , Linux ARM , Herbert Xu , Will Deacon , Android Kernel Team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, 12 May 2021 at 22:06, Eric Biggers wrote: > > 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. > Good point, I'll fix that