Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2710172pxj; Mon, 10 May 2021 09:02:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1vegXqvRqsLwS6ghWhg8/Ks9yHbqcvMFKuzyu6MYykGpxdCGmg0kWzQ/G9Q4izFSEy572 X-Received: by 2002:a50:ec89:: with SMTP id e9mr30361370edr.347.1620662570416; Mon, 10 May 2021 09:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620662570; cv=none; d=google.com; s=arc-20160816; b=ZgVreGz9s2t7nniyQdwCaqiZpACRE3AZT55Yls1rccC2zan+b51oUKx0BU6BQh2fGR XjfGs4KH7NDqL0tRxnb4+KYFAmfyZVWm2BLteamDJyKED5NxYy0L2NY2SgOlAcC6q/Z7 DqNAjZVjmPcA0pE+Xz0CEzJ/1ddHEADmgtYnKw0NOUBARkIGJOdQuIwMzneU/MMuMEXA VAnmhQ5vBGY5oW/NmirkptGqhu4LfGRYDRxa5l7vXOIlZonn6DuOvfbI9IvYRoZJyxkD 4N+1C2o0KxA7gdF4xuKqAyoWKTa/at3c1g17JdJxzaW0RyUe99SPXfWIv5nuAxkW54Yn Fj7Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vmVqUX572V3YsIejMYypSpe0CYNL8kY/hhz4gFKkwjo=; b=eF1aMC8vKBz1ZGmV9HQwNtxLXoNHZd4zwfsWYk7MTUF9Fc1IcouJ/MbDyFCy/+qMgw FeqVReZCMsIcR21m5jr/bMaFc/ajVpmxCpLs+w6RNsZpWgWwmkxwo/Sjs8DwfAklHv1T DWi0Wzmml5z1VyCd2DWGwt4qysu78nxBJccCTlQX7a1z24gT/hB227lqGetIpke0UWnY IVJjxPXO/4AGljOewf+Ojyw4+bRcyncnlYQCpBaTDqUuCNu03Cqc5vK1moTJPESWSjoF HJm0Di+++OoqVg+ecRJcSy+rZF8SYUwx+7kkQRXzCQYK82B3qxjV5Q5BYSZBTS3wOYms YcIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="aUPy/bzB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r12si13136298edp.101.2021.05.10.09.02.23; Mon, 10 May 2021 09:02:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b="aUPy/bzB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240752AbhEJLga (ORCPT + 99 others); Mon, 10 May 2021 07:36:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:41914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231167AbhEJKwX (ORCPT ); Mon, 10 May 2021 06:52:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8C03461A33; Mon, 10 May 2021 10:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643271; bh=syKh//1zBxW2bsse+MyJ23bGnmI1eRoX+g3ccSSI15E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aUPy/bzBoSQ8Kr4glNUXakkYeF2fO5Ne/uhF93zWkDD+k5Q8hJFtJYOwfYmliR1f5 giXISy3RfPKhQtUbsU5G1DWecwnUcOD2Xaf63sVOqAwgPx5TAraZRwtJFHUR/7KcrH +08N1X7Bb2Y6KNgFvAbz/qVgZbzclhnkMv050hAY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , Herbert Xu Subject: [PATCH 5.10 248/299] crypto: rng - fix crypto_rng_reset() refcounting when !CRYPTO_STATS Date: Mon, 10 May 2021 12:20:45 +0200 Message-Id: <20210510102013.149821787@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers commit 30d0f6a956fc74bb2e948398daf3278c6b08c7e9 upstream. 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 Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- crypto/rng.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) --- a/crypto/rng.c +++ b/crypto/rng.c @@ -34,22 +34,18 @@ int crypto_rng_reset(struct crypto_rng * 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: