Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3163034pxf; Sun, 21 Mar 2021 22:10:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8P4T+Dy9nlRayK0j7vU6wFvNrjmlBhJgix6FPAx6h/v3UsPSJSJ/XpL/eWatl3YmH6yWd X-Received: by 2002:a17:906:cecc:: with SMTP id si12mr17414640ejb.461.1616389844990; Sun, 21 Mar 2021 22:10:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616389844; cv=none; d=google.com; s=arc-20160816; b=xstkteUr2um+D1gKZGyueMOVHhpoA9oyEVN81kOm5wreKpkJDNQQDlk0l6RQwLx/hr ha2trltmlJOrgu8foSHGGNKnVP0+UXsXDntlepdpoLrvAG/Uj+RhYBZg08zfG6ZOi4Aw Ct6SYMz2Hs21c0DQvdVbMJxoQk8rZFBe7/r8N36j/QvRvWLUx/BILmDICeU90EUJAz7s BiDbnDiQmMOmlJBsGmOuAxZrsrJbLC1B51vgXKbqAqpB+aXG/8Q2YaLYEoJNTGvr64jh CwDYx+4Yy9v1MkGYGxYSN1myjzutG5zGLAJiK3CZfbST/7zER+2sfHI3MFNbeabj4VHH fMMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=enrmSMBEg4D//mlkMQqjvUNqpdGw9bcUfTgH6kp86Rw=; b=vtqTUdW92uEyXCUrbOfIGL4GJfOWKLA1nGiU9Giw+K8Yb/euV94d8k+arl0IfAgBWa zw0GOhmeRT1eVFxOnlo/T0GIxjg+D17B0MPdz1UwaHbxcps2W+QVHbdLaxcUeHpJbECs xMkF5AV4kasvLrcdhNSnuUCqEEbAx0JARHo74/Ku5+MhjVj1EbOFocACIx7ooG0ClaT3 8Twv9mSjSwnip40pHgNvJDV5xPXxK9EQkJhcN+O9VqzsBO9RJHYqSSlXNCGxxLEeSlqK RK2omW4vQ2fHLml9extuTIRu/GXnnJrrSDBgVDza1MPFpfftA1EFFH1R/5Q1zTBWS926 weLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gLz7Xtd5; 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 jg8si10937427ejc.657.2021.03.21.22.10.12; Sun, 21 Mar 2021 22:10:44 -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=gLz7Xtd5; 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 S229764AbhCVFJ0 (ORCPT + 99 others); Mon, 22 Mar 2021 01:09:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:43464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbhCVFJK (ORCPT ); Mon, 22 Mar 2021 01:09:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 764F261924; Mon, 22 Mar 2021 05:09:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616389749; bh=suu6mNgZOnCVzT4QdfXxKiTmiuK9LXZ9LoMgZcHk18E=; h=From:To:Cc:Subject:Date:From; b=gLz7Xtd5o8gAf/yYS3Rq871q7SEsl094SNnIakhVstMUZ+VTIT6EDGoYHe3g2NA/W 34XzyoUzAd37m+T9c1FPbMiM5afPN0ByKudacVzlJgtFVL9B1yv7Z7Zuz3qxgIW4cL LcVe7CMejgAgZkrCTGWcXvolYVlFf6UMOwKASz7xhPrn8hNTPKQzu0TCshZZaj2udB ajztQZ1TzHvOdUv0AXod+toMMIOpB25tKHmIPApUV85+0Bl9/IfX17F+f626RMR2NX DuILuyjApAfRvAoZi+FgZZIr5p1K2FIsDmZpm0RPoqsDPDwdAY9XO7va2p2J0t183Y EznsgilmRneQg== From: Eric Biggers To: linux-crypto@vger.kernel.org Cc: Dan Carpenter , Neil Horman , Corentin Labbe , stable@vger.kernel.org Subject: [PATCH] crypto: rng - fix crypto_rng_reset() refcounting when !CRYPTO_STATS Date: Sun, 21 Mar 2021 22:07:48 -0700 Message-Id: <20210322050748.265604-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Eric Biggers crypto_stats_get() is a no-op when the kernel is compiled without CONFIG_CRYPTO_STATS, so pairing it with crypto_alg_put() unconditionally (as crypto_rng_reset() does) is wrong. Fix this by moving the call to crypto_stats_get() to just before the actual algorithm operation which might need it. This makes it always paired with crypto_stats_rng_seed(). Fixes: eed74b3eba9e ("crypto: rng - Fix a refcounting bug in crypto_rng_reset()") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers --- crypto/rng.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/crypto/rng.c b/crypto/rng.c index a888d84b524a4..fea082b25fe4b 100644 --- a/crypto/rng.c +++ b/crypto/rng.c @@ -34,22 +34,18 @@ int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen) u8 *buf = NULL; int err; - crypto_stats_get(alg); if (!seed && slen) { buf = kmalloc(slen, GFP_KERNEL); - if (!buf) { - crypto_alg_put(alg); + if (!buf) return -ENOMEM; - } err = get_random_bytes_wait(buf, slen); - if (err) { - crypto_alg_put(alg); + if (err) goto out; - } seed = buf; } + crypto_stats_get(alg); err = crypto_rng_alg(tfm)->seed(tfm, seed, slen); crypto_stats_rng_seed(alg, err); out: -- 2.31.0