Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6031970iog; Thu, 23 Jun 2022 09:57:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t2vlbPcARB5YHmrGM3BBaCh0iYnhqfZIXdpj0YUJa5eudc9Z0rcbz2WVhwil3Q6eU6Rekk X-Received: by 2002:a17:907:3e84:b0:6fe:8c5f:d552 with SMTP id hs4-20020a1709073e8400b006fe8c5fd552mr8893254ejc.710.1656003440985; Thu, 23 Jun 2022 09:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656003440; cv=none; d=google.com; s=arc-20160816; b=cTfRGcuJ8bCCde8PwEMMvtHLMO9xTSnzXE9LBhhwzioRqK2MkYGmwtGsb+3tXTS4kF wqvPWpFHVYpCxJ2B0re1ZQgYLy1Q4x4BYe0BG5wfCwtxwoEHhrGXtc0pUs+hdWPiG4TR 3U8k0umzJxDmLhPGw/1hjTtqpiAGWcoTB74ZVoRdnk+C90hG3ClgkeQoclh4I57q4X0N NB/HVaTzL4z0qCyqZmdkCM4Oby2pxsMJgS2CsGXDEjU+7d2YCEsaa3hQ6y8rVpe2ftG6 bNi0AzHUJJVGlOCKIpAtZpjJdPWJmtdCsd5RTS8acV3GG6sIt8dagwcdOK9NDrrql0OX E+6A== 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=7AVR92ef/UH3/nOFnyKkrm374SVLSdxqO+PBp4Z/n2A=; b=ynYQyGJ7MsMahSzVsH298z2c9dyuCR0OI9KZZdenIuncbFrycWS/v88hnsXaw+smD+ DbOoSeg0KgSsI1E6nx72TYa8fSHeHrgsBfWLF8KYMX60snQn5RMRPtXxhz3LT/3eDoEI XvwhpFmjNE9DTzZFs52M+FX/HD0a6/vtPhz/ppEuhpHIQS0URiTihZHWx4OyJ7Av+t2m A0z7ungqPwPrVTOUEgBgGtzuxnkgto8JHyeQ4ymXzqkjODCD/FCVb4HBnJ7LkX/NLWXI pxHKKsShlMIIJL8VV0yeZxDCkqZpDd5PyKzrg5WMNGdGtFuKOEIUGOQc8mSe8NBH5BLg C7Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=slpWbAHE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p3-20020a056402044300b004356e670564si109495edw.48.2022.06.23.09.56.54; Thu, 23 Jun 2022 09:57:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=slpWbAHE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233098AbiFWQzO (ORCPT + 99 others); Thu, 23 Jun 2022 12:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233904AbiFWQvv (ORCPT ); Thu, 23 Jun 2022 12:51:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 798EB1B7BB; Thu, 23 Jun 2022 09:51:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1211F61F90; Thu, 23 Jun 2022 16:51:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA4E5C3411B; Thu, 23 Jun 2022 16:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003091; bh=hPzSIx7i+2amGZtsHQVbGBtJHY3W6XHd0htKHGw2fRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=slpWbAHE2xp43GTMsggESA97bUqLWNDk/S5jxcQ94LbiJk6YRf+MGdBFk9Oj8tPWr p/Rqgj9SWaPHXpGk4+q3GTHO9FrADoUACSKHYBioXuHfFzr7MWMWAbzHu1pbBlJuVy AnCwktpVf9r8S4zOvDAJAjjIvWkKnsPqAIStZXsI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dominik Brodowski , Jann Horn , Eric Biggers , "Jason A. Donenfeld" Subject: [PATCH 4.9 125/264] random: zero buffer after reading entropy from userspace Date: Thu, 23 Jun 2022 18:41:58 +0200 Message-Id: <20220623164347.603719337@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Jason A. Donenfeld" commit 7b5164fb1279bf0251371848e40bae646b59b3a8 upstream. This buffer may contain entropic data that shouldn't stick around longer than needed, so zero out the temporary buffer at the end of write_pool(). Reviewed-by: Dominik Brodowski Reviewed-by: Jann Horn Reviewed-by: Eric Biggers Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -552,6 +552,7 @@ static void crng_reseed(void) int entropy_count; unsigned long next_gen; u8 key[CHACHA20_KEY_SIZE]; + bool finalize_init = false; /* * First we make sure we have POOL_MIN_BITS of entropy in the pool, @@ -579,12 +580,14 @@ static void crng_reseed(void) ++next_gen; WRITE_ONCE(base_crng.generation, next_gen); WRITE_ONCE(base_crng.birth, jiffies); - spin_unlock_irqrestore(&base_crng.lock, flags); - memzero_explicit(key, sizeof(key)); - if (crng_init < 2) { invalidate_batched_entropy(); crng_init = 2; + finalize_init = true; + } + spin_unlock_irqrestore(&base_crng.lock, flags); + memzero_explicit(key, sizeof(key)); + if (finalize_init) { process_random_ready_list(); wake_up_interruptible(&crng_init_wait); kill_fasync(&fasync, SIGIO, POLL_IN); @@ -1386,19 +1389,24 @@ static unsigned int random_poll(struct f static int write_pool(const char __user *ubuf, size_t count) { size_t len; + int ret = 0; u8 block[BLAKE2S_BLOCK_SIZE]; while (count) { len = min(count, sizeof(block)); - if (copy_from_user(block, ubuf, len)) - return -EFAULT; + if (copy_from_user(block, ubuf, len)) { + ret = -EFAULT; + goto out; + } count -= len; ubuf += len; mix_pool_bytes(block, len); cond_resched(); } - return 0; +out: + memzero_explicit(block, sizeof(block)); + return ret; } static ssize_t random_write(struct file *file, const char __user *buffer,