From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 855B3C433E0 for ; Thu, 4 Jun 2020 20:08:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64641206E6 for ; Thu, 4 Jun 2020 20:08:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591301334; bh=xPvrxpe04r9lHjjseZ45mkyHnTnynq5sp/BoGDlAdc4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=VjqBUBGjKMM7RW/KoQ99/RLLkHbqBstqTddkqWCYcoIEVtIejdQhXcLbrl/9PxZuC vPNMLq4lU5rD38MqCK55wG3RqSA3XL7NlwCPanLnhSFFSa3b3/Tl8cqYeJ5c22NyIS HjN62rvi9djy4M8ccqL0vkBmEVhICxQZ2PsufMnw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728145AbgFDUIx (ORCPT ); Thu, 4 Jun 2020 16:08:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:58638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727111AbgFDUIx (ORCPT ); Thu, 4 Jun 2020 16:08:53 -0400 Received: from gmail.com (unknown [104.132.1.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE14020659; Thu, 4 Jun 2020 20:08:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591301333; bh=xPvrxpe04r9lHjjseZ45mkyHnTnynq5sp/BoGDlAdc4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qvN/SDLHwWO5DzktmbfvDgd9rDOr1MmYzRCY1MaVIfEY+88AfDv4ac/xgUTGEGmbt lawF6Hh7fmIBB0e9Ntx91H0GEl/OS2ILj2DlpUdpH1J+v1IWjgbPKiPohhiMK8xpHh cwfUFQhdhRNBTWQudIIHOl/z2Fc3xzLz5QGixth0= Date: Thu, 4 Jun 2020 13:08:51 -0700 From: Eric Biggers To: linux-crypto@vger.kernel.org, Herbert Xu Cc: stable@vger.kernel.org, "Martin K . Petersen" , Mike Gerow , Kai =?iso-8859-1?Q?L=FCke?= Subject: Re: [PATCH] crypto: algboss - don't wait during notifier callback Message-ID: <20200604200851.GB147774@gmail.com> References: <20200604185253.5119-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200604185253.5119-1-ebiggers@kernel.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, Jun 04, 2020 at 11:52:53AM -0700, Eric Biggers wrote: > From: Eric Biggers > > When a crypto template needs to be instantiated, CRYPTO_MSG_ALG_REQUEST > is sent to crypto_chain. cryptomgr_schedule_probe() handles this by > starting a thread to instantiate the template, then waiting for this > thread to complete via crypto_larval::completion. > > This can deadlock because instantiating the template may require loading > modules, and this (apparently depending on userspace) may need to wait > for the crc-t10dif module (lib/crc-t10dif.c) to be loaded. But > crc-t10dif's module_init function uses crypto_register_notifier() and > therefore takes crypto_chain.rwsem for write. That can't proceed until > the notifier callback has finished, as it holds this semaphore for read. > > Fix this by removing the wait on crypto_larval::completion from within > cryptomgr_schedule_probe(). It's actually unnecessary because > crypto_alg_mod_lookup() calls crypto_larval_wait() itself after sending > CRYPTO_MSG_ALG_REQUEST. > > This only actually became a problem in v4.20 due to commit b76377543b73 > ("crc-t10dif: Pick better transform if one becomes available"), but the > unnecessary wait was much older. > > BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=207159 > Reported-by: Mike Gerow I forgot about the person who originally filed the bugzilla bug. Kai, if you're okay with it, let's also add: Reported-by: Kai Lüke > Fixes: 398710379f51 ("crypto: algapi - Move larval completion into algboss") > Cc: # v3.6+ > Cc: Martin K. Petersen > Signed-off-by: Eric Biggers > --- > crypto/algboss.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/crypto/algboss.c b/crypto/algboss.c > index 535f1f87e6c1..5ebccbd6b74e 100644 > --- a/crypto/algboss.c > +++ b/crypto/algboss.c > @@ -178,8 +178,6 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval) > if (IS_ERR(thread)) > goto err_put_larval; > > - wait_for_completion_interruptible(&larval->completion); > - > return NOTIFY_STOP; > > err_put_larval: > -- > 2.27.0.rc2.251.g90737beb825-goog >