Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6135045iog; Thu, 23 Jun 2022 12:04:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vWHuuLIVmzKVevZ2aW/J1KX8CKmjP4VGN3YmiZvKX9WWAL5oa/Wvw02PbwYXZiUHusJYlg X-Received: by 2002:a63:1566:0:b0:405:3aa3:23de with SMTP id 38-20020a631566000000b004053aa323demr8535460pgv.528.1656011096746; Thu, 23 Jun 2022 12:04:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011096; cv=none; d=google.com; s=arc-20160816; b=c2/2ku3yrSqOtGxlJlsfQTcT4/zBiq/M5sHS/d3Eo6IDcTB2H3oHiAgVTXAzkcrDW2 XVL4vsE9HXoso7/rDW/A9sn8eUIZCRgA+vf4+1tdtCO8L50Nu9FIaC0b/pULGElX5dU6 wdWIpRCd4i5Eo6DmUeNPBjyihkRitjyeFIOY4w+T0xnKMY+Wt/jODiJKe/E/MXtz8CaX GhcY4sSFMB7ML3zVv6qNHhqsvgAX4hmDBnaboiLCjRQhssZQF41L1eHixt2Z0O6Tw+jI 76xL1msShqtzq1+6NqBSY7PI7Qb8Etq1ov9MFRZ2VMKkJEIdf/5/x65Fl5C4RGEJADBr gwdg== 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=lDSzIOXQiMv8VICsIxmHTAro0PPLOoIRjslwKr1ZyEE=; b=cKs5drATE9HA9uYDxl2jFtACsIGncO3DPTG1XpCwj2rV1eeLI95EBCmEYIROcV0X4n QJd2AxB2E3VDf50yUq8TkasV/DZx7ND4x/CzOPGKKjk8b9O5HPAB23YoUNvKVfSYITYG 6XpLZTDrC1Dh5tmP1Er+OmL+yIbh3Y2Up/NucjMzrdIVovwNp1gef+HBFpzYDcmSgNLi oEAlLR8iEkrGC/Rmie5pkZGKE7Nze0FySQpBwPp5nUv06wbZ4gcdTdwh7Tj6WVwHoHQJ iRO/Py0syBP1YhghvdnLhtOL9gmG/IDZBpm3zBbvun5NGsPROWH30ynnv+YwErjYQih7 FQEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ai3FiQuw; 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 d188-20020a6236c5000000b0052545059695si223335pfa.307.2022.06.23.12.04.44; Thu, 23 Jun 2022 12:04:56 -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=Ai3FiQuw; 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 S233093AbiFWRRL (ORCPT + 99 others); Thu, 23 Jun 2022 13:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231740AbiFWRLj (ORCPT ); Thu, 23 Jun 2022 13:11:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A48F18374; Thu, 23 Jun 2022 09:51:17 -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 A4EE661F90; Thu, 23 Jun 2022 16:51:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 793D4C3411B; Thu, 23 Jun 2022 16:51:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003075; bh=nEZOz36b4x2qt/eNS2zX1Z+zkb1SsCCGsKcLWiARx5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ai3FiQuwBeEdD78XCDKo02ZRBijDo2EE16HWOnupFQwwjmZoxB1VBb6G7vstBJZr0 uThW44K9Em/AHYsxpWDyxeXx8K7XUIp6z8v8QjJVlQnK779hQDZUews/CQwWZJFO4w m16g+rhGO7mRJtDauEokSVJP4b7HTJpPWDQ10zW8= 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 4.9 121/264] random: do not xor RDRAND when writing into /dev/random Date: Thu, 23 Jun 2022 18:41:54 +0200 Message-Id: <20220623164347.490872627@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 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 @@ -1357,25 +1357,15 @@ static unsigned int random_poll(struct f 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(); }