Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2438758ioo; Sat, 28 May 2022 13:43:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwohhDOJaZzsyCVXhBanayaWpZdBi5h2bPoHrm4m1kay+aDJWAnSZc93kFnigF3rawDTxQ1 X-Received: by 2002:a17:902:8c90:b0:163:b989:3cd6 with SMTP id t16-20020a1709028c9000b00163b9893cd6mr2019030plo.170.1653770617033; Sat, 28 May 2022 13:43:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770617; cv=none; d=google.com; s=arc-20160816; b=CoqKiWInbxuEMcW0OhqKUYYQB+J2q0gU0vwzqSntYQDLRNzNfT69zIV9mZPDgrlOeL MG4WcLZNEVi7jsJeKq5CzSaA4qVlkQn2bzv3pve58icyCh34l5n2KACHhqqU65RS3n3K 7xwoCAj3yy7zrShJddojoCeWW0ljU41MASLOnX5PSjPFcDgQ0lChXdxNhjeQ/d98SSaJ I4F1jbkVrPcEtSFpAqH0g9yjDMOpSqbQGllGRJY8oWDjt3K6Ou4QjYgjJHqsRNexzSUa Wmas+JK6qWl5b9t/fHNWSWDc6wr3CiC7tnFzlF/QXDQBrcsBMQwwlZ+fo9pr+8aY+dyQ O4aw== 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=eAtFtVgfawLLz0vXnn/CZ+FEV5wxYmUH+2AK8NwM7J4=; b=mo2TQh+Ayoo18olJr/X9kzsCwL8y03Ic5rsWD7jwHK86tafVxJsoq4x7zmuUw4pbiP QzptJFKGhMyP9ecNpK4F0sAZEtNFdByYj6qvxsKXcvowgSTHgx1i86u7N+RF2gE8Jc5d VMV4PJaRYEJKszkyEz0qpGIjUnlLdMf/0AhOTdscig1HeDYykbRcqXYGmrvMqSFSU/95 Sh47CHP/iTUvTNR+vCXQj/NJP7Q4WRUqg1HoJNHofGO/59QMJFhcIyqiy1dfEq2eaWWg JhIEtRBdneyVpmqapfmY742Bbr/v7YZ5f44OazY/hpuuImz+Terwgs4ZGMyVYpk4Rvh2 OMPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gDW3ldJ7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q18-20020a170902eb9200b0016392e24919si6477676plg.509.2022.05.28.13.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:43:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gDW3ldJ7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 434126569; Sat, 28 May 2022 12:43:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350287AbiE0I6h (ORCPT + 99 others); Fri, 27 May 2022 04:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350280AbiE0Izy (ORCPT ); Fri, 27 May 2022 04:55:54 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3332F1157D8; Fri, 27 May 2022 01:54:26 -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 sin.source.kernel.org (Postfix) with ESMTPS id A977DCE238F; Fri, 27 May 2022 08:54:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78FBFC385B8; Fri, 27 May 2022 08:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653641663; bh=hwxcHasEV/bb2nOwjqLI3dCmvo+Iqwr+zYuY74pKObQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gDW3ldJ7ifKU7ArWkdyp+x2/D0l932+013/M1FExTuFjLRAWjZl3DZDyDtFYe39V4 ZJNLJaQ7mFUgQDhQA/bXt2CbM1saIDDPBfc54CyWLZHOL1NbZw3NeEfBqGWhQHvouW T7+DGFlGKcnwdc6MqNELcLY0BrNnBdGyUecMFA7Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Dominik Brodowski , Eric Biggers , "Jason A. Donenfeld" Subject: [PATCH 5.17 015/111] random: do not xor RDRAND when writing into /dev/random Date: Fri, 27 May 2022 10:48:47 +0200 Message-Id: <20220527084821.312132171@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220527084819.133490171@linuxfoundation.org> References: <20220527084819.133490171@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=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 91c2afca290ed3034841c8c8532e69ed9e16cf34 upstream. Continuing the reasoning of "random: ensure early RDSEED goes through mixer on init", we don't want RDRAND interacting with anything without going through the mixer function, as a backdoored CPU could presumably cancel out data during an xor, which it'd have a harder time doing when being forced through a cryptographic hash function. There's actually no need at all to be calling RDRAND in write_pool(), because before we extract from the pool, we always do so with 32 bytes of RDSEED hashed in at that stage. Xoring at this stage is needless and introduces a minor liability. Cc: Theodore Ts'o Reviewed-by: Dominik Brodowski Reviewed-by: Eric Biggers Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1305,25 +1305,15 @@ static __poll_t random_poll(struct file static int write_pool(const char __user *buffer, size_t count) { size_t bytes; - u32 t, buf[16]; + u8 buf[BLAKE2S_BLOCK_SIZE]; const char __user *p = buffer; while (count > 0) { - int b, i = 0; - bytes = min(count, sizeof(buf)); - if (copy_from_user(&buf, p, bytes)) + if (copy_from_user(buf, p, bytes)) return -EFAULT; - - for (b = bytes; b > 0; b -= sizeof(u32), i++) { - if (!arch_get_random_int(&t)) - break; - buf[i] ^= t; - } - count -= bytes; p += bytes; - mix_pool_bytes(buf, bytes); cond_resched(); }