From patchwork Mon Apr 16 23:59:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10344063 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0F85460548 for ; Tue, 17 Apr 2018 00:00:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B356E289B2 for ; Tue, 17 Apr 2018 00:00:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A61E5289B1; Tue, 17 Apr 2018 00:00:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E06232897F for ; Tue, 17 Apr 2018 00:00:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751060AbeDQAA3 (ORCPT ); Mon, 16 Apr 2018 20:00:29 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35773 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751059AbeDQAA3 (ORCPT ); Mon, 16 Apr 2018 20:00:29 -0400 Received: by mail-pf0-f196.google.com with SMTP id j5so1765244pfh.2 for ; Mon, 16 Apr 2018 17:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=W3p7rUVUXnXdC/gr1gd6blAHFdvOBKLDm8Ifnq0n4v0=; b=M+1Cb5E005ZrZVIitdCXyUhGrlI68f0AIGQVtBumJv7aE2tQjCsXINEdwp91pIpNUO whdt3dml6CG2sKit6wFXcDJgi1BnF3y8PRVsgtG0aBNeaI/+bgvhtG31hcu8qBEbxh7y D6RAVFCcypwTsyE4hxwwoNzhsyJ0fnYijXWYMCIx1i2F+8Vk0lQ5gVrHYFT8/CaGUeD2 Y9xSWb+p501fP/BbYqrx6eWkth4NMWHf2ARrKeRe3dzjF0Dv9R26EjhkzQpeew3upUMI r2IVH5mHV9Ys1lTruK5XHHctzGqKQY+ChgJDLSinbN8Dj2GqehoWhYVsyJni1k8N6Z9x BUlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=W3p7rUVUXnXdC/gr1gd6blAHFdvOBKLDm8Ifnq0n4v0=; b=epl/hSIHSQyqMORV8rK5i2qBUiH8veoVGcTDQhsDcoUj0W/3iU1uD2ar/iX3yhJ+gl kKYSgz0SJVjnw96m/lwX2KhOuAwJqLRiHVdkZlPPC/nijEfdjsKP40EVxh/QTfp7Qe3/ +LfG+9F4ZQ1ZKkdjs0HXkJTCFdyW4D1WczeUy4k/718U9/F0yB4cZsQyXjiwar9CKiiF vaS41SuAwnMPcftiBYUgUZlRGc750MitnodSZ1P4TDvsgFoBrpVJpHzULAzC1MV/RgG5 7XS4gZdEtDBe/BzHBotkRgH0TbRk/a7/CiQQkf9Dwe7bAUyu5nP6Ujnv6guXh2oOuEVZ 1ONw== X-Gm-Message-State: ALQs6tCTOQB4jXqYTe4jR+R8v0bnG/wQ70gZ5YbphGP0NWFmFoxyEjJh DpW2rnq65DqqllYGcfdTVhNeA3IQ X-Google-Smtp-Source: AIpwx4/QcmuOi8WEBTpCiCMuIu2DKZ+vrVqF7r9W8+2apOZMlFy27BjkNr0GqDmi1ASn2g1ZQOMyaw== X-Received: by 10.98.7.83 with SMTP id b80mr23486474pfd.133.1523923227108; Mon, 16 Apr 2018 17:00:27 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id x137sm25952278pfd.162.2018.04.16.17.00.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Apr 2018 17:00:26 -0700 (PDT) From: Eric Biggers To: linux-crypto@vger.kernel.org, Herbert Xu Cc: Eric Biggers Subject: [PATCH] crypto: api - fix finding algorithm currently being tested Date: Mon, 16 Apr 2018 16:59:13 -0700 Message-Id: <20180416235913.41164-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Commit eb02c38f0197 ("crypto: api - Keep failed instances alive") is making allocating crypto transforms sometimes fail with ELIBBAD, when multiple processes try to access encrypted files with fscrypt for the first time since boot. The problem is that the "request larval" for the algorithm is being mistaken for an algorithm which failed its tests. Fix it by only returning ELIBBAD for "non-larval" algorithms. Also don't leak a reference to the algorithm. Fixes: eb02c38f0197 ("crypto: api - Keep failed instances alive") Signed-off-by: Eric Biggers --- crypto/api.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crypto/api.c b/crypto/api.c index 1d5290c67108..0ee632bba064 100644 --- a/crypto/api.c +++ b/crypto/api.c @@ -204,9 +204,14 @@ static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type, down_read(&crypto_alg_sem); alg = __crypto_alg_lookup(name, type | test, mask | test); - if (!alg && test) - alg = __crypto_alg_lookup(name, type, mask) ? - ERR_PTR(-ELIBBAD) : NULL; + if (!alg && test) { + alg = __crypto_alg_lookup(name, type, mask); + if (alg && !crypto_is_larval(alg)) { + /* Test failed */ + crypto_mod_put(alg); + alg = ERR_PTR(-ELIBBAD); + } + } up_read(&crypto_alg_sem); return alg;