Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2436672ioo; Sat, 28 May 2022 13:38:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycnji484/ecchxXqb37H0POYZ3PxPHCSsW8YFvbnJPIQHQFkjXb5FR+stTci2Y+lR6qh0Q X-Received: by 2002:a17:902:9a42:b0:158:bf91:ecec with SMTP id x2-20020a1709029a4200b00158bf91ececmr49212930plv.115.1653770320197; Sat, 28 May 2022 13:38:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770320; cv=none; d=google.com; s=arc-20160816; b=H7tixONU/pLlslOjSFjAKctmQQEw+Ix2vlRnAg5qyiANPQ+sYcLjsqdB9uX1mSi7vn 7kJSM8UFW3qqevRL2Ps7OUfemk3IQvHhLsaDzkoehsGXTDTUwv8sYHk5QdDR2xoWLT20 JX3VOajnv9BjR1v+LpDilf8HTcdC6iClo+MhOb/1TfRUWixA6CaGdCVOHqWqSPsGiUYl 64c0RZSHXeq+H0NMRf7aR9RsLR32CXcvJXLj3xuookhaQnGOhvtYzQCYxaAUY7oHGCKp X66SAPBVIG1aZ6VsLieF83NDD4EJgRw0hbvsvsw7Y2optTnnvK+pdiOuiaWgny7JEjtv BzUg== 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=JirI1g9nHaFe1OJF28Z4S8scqCfJiJG6Uh4yH2191uUUFESlU2Xs3DFE/ayD1BVHsW EjfIF9JJWk1JeqbJ2h1RJsW/0qfZsRkYvIOBklpzqLEJlc0LXLiKTE5fzi27q5+6mKIn emmrPISEGzyzeEfkZgwxBn78YM8U67fpVObgxROvzb6NOqosTQA7xx4Ol2HOHeiwmpZf xbZGNz23xcW0naEbDDGqKh1d3aetl3Bpx/7s/+Sx0L637//2Hymhgt/fYylBMCjL84Ne T0VEtU7HggsqkFWAmblqMmxzRZg01YicFn+jddL5BEA4Ma5XjQhxE6IHDFutCvK/w7Wz O5hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=njdPXKN9; 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 j38-20020a635526000000b003816043ee99si10751385pgb.142.2022.05.28.13.38.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:38:40 -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=njdPXKN9; 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 5CE8B60069; Sat, 28 May 2022 12:40:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352284AbiE0Lxh (ORCPT + 99 others); Fri, 27 May 2022 07:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352164AbiE0LuK (ORCPT ); Fri, 27 May 2022 07:50:10 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A59514CA1F; Fri, 27 May 2022 04:44:13 -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 ams.source.kernel.org (Postfix) with ESMTPS id C5B5BB824D7; Fri, 27 May 2022 11:44:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D724C385A9; Fri, 27 May 2022 11:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653651850; bh=hwxcHasEV/bb2nOwjqLI3dCmvo+Iqwr+zYuY74pKObQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=njdPXKN95iv+lWpC4613DqxpdRgrWyRUQtTqu4T8iYCC9v7WVcq23shmYU0LyiPtc I9CeMrh5JMkaWdXhn3X6BOwG2ho46ae4QiaTeDRcuCfqqg9nGxQRxfOMh2fQx/N3tu z5/oEjnkVRMRve7fkJguT1N7N3nQGIWwTvbo6uSc= 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.15 050/145] random: do not xor RDRAND when writing into /dev/random Date: Fri, 27 May 2022 10:49:11 +0200 Message-Id: <20220527084856.832414757@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220527084850.364560116@linuxfoundation.org> References: <20220527084850.364560116@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(); }