Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6135682iog; Thu, 23 Jun 2022 12:05:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sPUuQGD0uRlymCc1eexHX7GJITIo96uWhmek2QTE2jhg3PsTyxAJqicg7LB/WBDKL1wqH0 X-Received: by 2002:a17:902:8f86:b0:168:9a69:fd4c with SMTP id z6-20020a1709028f8600b001689a69fd4cmr40857432plo.141.1656011135749; Thu, 23 Jun 2022 12:05:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011135; cv=none; d=google.com; s=arc-20160816; b=e0Pfw0MvcqN+E+0/P8xckoSQreOBZJOzdEccmmJ6P/O8/L9OGAkoEZ3cwFCxWIy4lZ w3hAAbK0+uNQ3XF7vu2y2AUqKQE/9H5fFahxwNQvkNmctT36Pzsi4HwVCtvwxnB0/+SQ FNFJUx2ppqevTqGO1Oinp4+gxzCCadKJxc+YI3LYjJGCvDVCqRmxZTGPPPjsZXnFSR/X tzOpHuRgA03ArNkiP3ilRO5Hw+wsz8bqP7Y+LzBGWVQz1QBLYNxYSyPnJdNmSpps9m2t iEl4EDwFvou38hZRL5l7LJ4hBL1/5QzuSNtZznpeL/86rZ7LDBXWK3InXD3xc7JydIPx pFWA== 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=kgyL5RqOIOMXtxAQIQu8karxmnMQ2lFdHd4+0D3Thx4=; b=IelqFov1ZMmjRF17G/jh/ZMQGKy5cm40v8IJ12AqBKNF7mHZsYajc8ATp2OMESNAkq wF0oQfeZ59Ys3n7S4y0u0ZDhXDSx+Fz0GGLPCJk737g+EVDfLp9SWjJo1lYjFkvQkZ3T xmArvb7MO96V0H75u3sVsOoivVO4tFCjOCadL3sNsDHN2WUFz6kwN6m8jpTOK6IcUFHk vP3fZT5W5ooD11G/8d+jPgRyx9w8sWGbA//cZaMGst48maWeeDDZG9oV3BMLfF/VA54n D+cA/0q0rLpAU9BsqRWweoVpdKHlv1pmr+gXzZA6cu+iNPZAOJKNbxG0hMsQw8aYJERK vVKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TR7YsUOI; 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 v63-20020a638942000000b0040d5fd63025si2184008pgd.794.2022.06.23.12.05.23; Thu, 23 Jun 2022 12:05:35 -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=TR7YsUOI; 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 S234634AbiFWSDm (ORCPT + 99 others); Thu, 23 Jun 2022 14:03:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235666AbiFWSBR (ORCPT ); Thu, 23 Jun 2022 14:01:17 -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 C8AF9B3D09; Thu, 23 Jun 2022 10:16:41 -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 4C5CC61DE5; Thu, 23 Jun 2022 17:16:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D27CC3411B; Thu, 23 Jun 2022 17:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004599; bh=hW+pvIhJEdfDOOcLSl+foKY7+VtKrgElChyroSgU2B0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TR7YsUOIq0l+eekXC0JFGbCAbYR+xg86i7PI95wdyHzpmOSplSzOd4GtEA80r8qxI ZhmOIgGu4Ka24Ytky1vSjliyxtF2CVlZqgfILqBnNOAuNsdtVZkKhUbH51zdQ04gXd VcUG3RCqEjZwmFNYxjB8/acGnyUlQ07BJuYmUqcc= 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.19 090/234] random: zero buffer after reading entropy from userspace Date: Thu, 23 Jun 2022 18:42:37 +0200 Message-Id: <20220623164345.605513587@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@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 @@ -500,6 +500,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, @@ -527,12 +528,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); @@ -1334,19 +1337,24 @@ static __poll_t random_poll(struct file 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,