From patchwork Thu Apr 16 03:07:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 6223571 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EF07EBF4A6 for ; Thu, 16 Apr 2015 03:07:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E4E5201CE for ; Thu, 16 Apr 2015 03:07:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3A25201C0 for ; Thu, 16 Apr 2015 03:07:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754639AbbDPDH0 (ORCPT ); Wed, 15 Apr 2015 23:07:26 -0400 Received: from helcar.hengli.com.au ([209.40.204.226]:56579 "EHLO helcar.hengli.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752161AbbDPDH0 (ORCPT ); Wed, 15 Apr 2015 23:07:26 -0400 Received: from gondolin.me.apana.org.au ([192.168.0.6]) by norbury.hengli.com.au with esmtp (Exim 4.80 #3 (Debian)) id 1Yia97-0002Fx-Ky; Thu, 16 Apr 2015 13:07:17 +1000 Received: from herbert by gondolin.me.apana.org.au with local (Exim 4.80) (envelope-from ) id 1Yia94-00033h-3r; Thu, 16 Apr 2015 11:07:14 +0800 Date: Thu, 16 Apr 2015 11:07:13 +0800 From: Herbert Xu To: Linus Torvalds Cc: Stephan Mueller , "David S. Miller" , Linux Kernel Mailing List , Linux Crypto Mailing List Subject: Re: Crypto Update for 4.1 Message-ID: <20150416030713.GA11668@gondor.apana.org.au> References: <20140804130339.GA1178@gondor.apana.org.au> <20141007131826.GA29688@gondor.apana.org.au> <20141211125119.GA12380@gondor.apana.org.au> <20150214094328.GA7457@gondor.apana.org.au> <20150415033951.GA1406@gondor.apana.org.au> <20150416024252.GA11558@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Apr 15, 2015 at 07:49:01PM -0700, Linus Torvalds wrote: > On Wed, Apr 15, 2015 at 7:42 PM, Herbert Xu wrote: > > > > Is CONFIG_CRYPTO_MANAGER_DISABLE_TESTS set or unset in you .config? > > # CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is not set > > I'll send you the full .config in private (no need to spam the mailing > list) in case you have any other questions about my setup. Thanks! It actually appears to be a very simple bug that I somehow missed during reviewing. ---8<--- The commit 9c521a200bc3c12bd724e48a75c57d5358f672be ("crypto: api - remove instance when test failed") tried to grab a module reference count before the module was even set. Worse, it then goes on to free the module reference count after it is set so you quickly end up with a negative module reference count which prevents people from using any instances belonging to that module. This patch moves the module initialisation before the reference count. Reported-by: Linus Torvalds Signed-off-by: Herbert Xu diff --git a/crypto/algapi.c b/crypto/algapi.c index 2d0a1c6..d2627a3 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -525,12 +525,12 @@ int crypto_register_instance(struct crypto_template *tmpl, if (err) return err; - if (unlikely(!crypto_mod_get(&inst->alg))) - return -EAGAIN; - inst->alg.cra_module = tmpl->module; inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE; + if (unlikely(!crypto_mod_get(&inst->alg))) + return -EAGAIN; + down_write(&crypto_alg_sem); larval = __crypto_register_alg(&inst->alg);