Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6093211iog; Thu, 23 Jun 2022 11:10:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1toQ7nKRiZyESkxBWPVlyUP+D3g7M2dxRPku8x0puU/BhE0aBFVec2alSIFW6g7Iy7GaG8Z X-Received: by 2002:a05:6402:4415:b0:434:fe11:742e with SMTP id y21-20020a056402441500b00434fe11742emr12340484eda.239.1656007801690; Thu, 23 Jun 2022 11:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656007801; cv=none; d=google.com; s=arc-20160816; b=yC0W4uVgFSgANuYvVTLlOS4x9wrVNM5oK0WYdREnyDCs8Ga8s6Ccqrn8Zh7CTsMI1n IhpFIDcve/kZ5gmItRgC4DZcvXKHpD4Y7QdwJnQbYsqgvONZd9mRISTTj92NEvkY9NJt nF6LTz3rbGoZqt223H6zYW/rCY0PmDy06E7qUabJTCgBxoTtVF7bvpEvGsczMWHMMm8z fa8T1H2StZG5oneDgwnVwQvrw1viegUw5h43f33EcaZ2ZxI2+O7v/bcvY+Cqv5dKlGpS Wuk1xkrX+qfZ7SD8BdnNqzoiZzznXAzLA9kVeKSQQ+V3Ycan/kCrv14ChsiLhJt1ADLL jZxg== 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=u9n7KkgomT+4lVSTXNlqD0xp1xgfC4frcOmbD3vDFaLDlN7GIAfXRhMbhRofYhyP7R 00eLSImSF1kTd1/xzs0k0tSz0Pw+lSMpM0h2LAjm+3bTqxKo9NHkrDlHsZ6DBkqrn0KO WU/IUjSK8sJ3u0LG6vG2GoAcfNR7kxZnN6mmTgGRgs+1O8L+bgin70Gnnq/ZnVC01CR5 KjF5EVI0zkO7fxiDGXEeH+zK90hhWtTTgQ8yX/nLnKsvb+QzWklrquJZvIK6dANCyOCd TIo1oZy351DAEP6IMIev6a/krhTmQjc+/smmFrb5F2Fu01adxiPZEW4MKhtoLpVey7Rc XCGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KDQHneSr; 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 t19-20020a50ab53000000b004359a63823esi258087edc.225.2022.06.23.11.09.32; Thu, 23 Jun 2022 11:10:01 -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=KDQHneSr; 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 S235922AbiFWSHN (ORCPT + 99 others); Thu, 23 Jun 2022 14:07:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232470AbiFWSGL (ORCPT ); Thu, 23 Jun 2022 14:06:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48108626F; Thu, 23 Jun 2022 10:18:39 -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 0A292B824B8; Thu, 23 Jun 2022 17:18:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62E73C3411B; Thu, 23 Jun 2022 17:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004716; bh=hwxcHasEV/bb2nOwjqLI3dCmvo+Iqwr+zYuY74pKObQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KDQHneSrwrzw9aRbx5LjSqp0vL6VABC5D+pUF0HxXzREF023+bJ3j6NcVfksHsPJq 8BmABg6ycoRxdz9xVXB44qn/3q0UELBVx5o3fPMJIFgJR6xBXIivSw2JoIZVk54T3E hBZ4SAFLsQ6AznCFYAEaotfD4+EIN+1zMEHL8xhg= 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.19 086/234] random: do not xor RDRAND when writing into /dev/random Date: Thu, 23 Jun 2022 18:42:33 +0200 Message-Id: <20220623164345.491991776@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 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(); }