From patchwork Thu Oct 19 20:45:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 10018303 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 32870600CC for ; Thu, 19 Oct 2017 20:46:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 252B828E58 for ; Thu, 19 Oct 2017 20:46:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23B8328E5A; Thu, 19 Oct 2017 20:46:11 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable 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 531C128EA9 for ; Thu, 19 Oct 2017 20:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754114AbdJSUpa (ORCPT ); Thu, 19 Oct 2017 16:45:30 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:57167 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753212AbdJSUp3 (ORCPT ); Thu, 19 Oct 2017 16:45:29 -0400 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 749f8369; Thu, 19 Oct 2017 20:44:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=mail; bh=jgw2 UfpQ7GeXiFQFfbceDY8is6c=; b=d08Zp0wMxbFFryFHONTWpQUED+axBoFiTXwj Rg4gRpVWjSt/yV5o02bti7yqUmRShcGC++2GjIR/XSX6eXqh9NYZXJF19/7JgZDp d5RRqe3qFdunEYdHyuagvYAmw+ZbGaShhQ57it0kPN2STzEtRBPUScEs/9hKmnYQ 3gB5VqCuIYcZoqlWIULqjEPhvf9RdLXVdUz9gnB+7p1+8B+RvduNZ+yr4LMU4uYv WX+JOMjFZdzQ4Y5a2dmliHynjtnlAixvD2kTAJh5MzKfhMt+0tB+HqrH8oxMrPaZ Q3fGWVbAu1yVH+Q3B5I2+MduUYEQZs7ZR/LHT1a5jGiZOMhRRg== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 812a6882 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Thu, 19 Oct 2017 20:44:33 +0000 (UTC) From: "Jason A. Donenfeld" To: Kees Cook , LKML , linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, tytso@mit.edu, gregkh@linuxfoundation.org Cc: "Jason A. Donenfeld" Subject: [PATCH 2/2] crypto/drbg: account for no longer returning -EALREADY Date: Thu, 19 Oct 2017 22:45:06 +0200 Message-Id: <20171019204506.25090-2-Jason@zx2c4.com> In-Reply-To: <20171019204506.25090-1-Jason@zx2c4.com> References: <20171019204506.25090-1-Jason@zx2c4.com> 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 We now structure things in a way that assumes the seeding function is always eventually called. Signed-off-by: Jason A. Donenfeld --- crypto/drbg.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/crypto/drbg.c b/crypto/drbg.c index 70018397e59a..501e013cb96c 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1411,18 +1411,8 @@ static int drbg_prepare_hrng(struct drbg_state *drbg) err = add_random_ready_callback(&drbg->random_ready); - switch (err) { - case 0: - break; - - case -EALREADY: - err = 0; - /* fall through */ - - default: - drbg->random_ready.func = NULL; + if (err) return err; - } drbg->jent = crypto_alloc_rng("jitterentropy_rng", 0, 0); @@ -1432,7 +1422,7 @@ static int drbg_prepare_hrng(struct drbg_state *drbg) */ drbg->reseed_threshold = 50; - return err; + return 0; } /* @@ -1526,9 +1516,9 @@ static int drbg_instantiate(struct drbg_state *drbg, struct drbg_string *pers, */ static int drbg_uninstantiate(struct drbg_state *drbg) { - if (drbg->random_ready.func) { - del_random_ready_callback(&drbg->random_ready); - cancel_work_sync(&drbg->seed_work); + del_random_ready_callback(&drbg->random_ready); + cancel_work_sync(&drbg->seed_work); + if (drbg->jent) { crypto_free_rng(drbg->jent); drbg->jent = NULL; }