From patchwork Mon Oct 31 19:26:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 13416 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2506311wru; Mon, 31 Oct 2022 12:39:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4miVKx3oy8AOu38+qIG/NMV+3+qFNSX2UaMzAIbxNgE99DElQnjGeygZbG6pQJq0U1UeoL X-Received: by 2002:a17:906:5d11:b0:78d:a41c:6a2d with SMTP id g17-20020a1709065d1100b0078da41c6a2dmr14416837ejt.215.1667245179601; Mon, 31 Oct 2022 12:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667245179; cv=none; d=google.com; s=arc-20160816; b=ucJFcAXl7r0iF2JYDvyZa2Tk2YEnzQxHzjxmVtXLugB35WxYlKPdx/pyS7MtI1yNxa eGGMMuR09cAmSwyNVyagq9OfP6OaVG/ru3cVVwM3ZcKz9oySxcfpmCB0MesUDNDEXIDG J0sJAIXOox57gJ2/c+62dOZ026J0/TDA+dcGZyRI5L495iDsdOzxKs/ySAOcnbwhSCbH wqYacOFt3QQr4Hwevas6pFFzmYDRVU8WHOnsLNaicvC4DfTnJoLUicqbbdXjc5rR8Pr4 yYxIX5wRjqq8hhly65KW1J9H4Kqv18/iGDX/n2Nhj4WhHoGFSvf9rOzECTu3lC/NRDp+ edmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=3D7hSGn0CvbQ9zOj43AcDS1HiRH7N6eiQqKa+886cCw=; b=TfFvTkalxJDOuaKTzz64i/H1c/vDyBbr+rearCQ2D1sko+AAqjiuzZqsRGbzqa5HDX zhlqvFVJ98wMR4Wac+6+M2A1BHUunpjZYxpauAo4lskeBlMj4F9pbXkkQdI8Pmat4P3T zKUYHIgpGqKdqXyIvAGUXb3dsIRXHlgb7bZGV3cwMLfLh5tC1vxINeUp3drJ/28H+Znn aiPYCPqJLyzRI/z1mULUHQEZJxqDlnankcjrRYgbvhFu/DhU55s3Q/HsfDysifr5xBeP zyEEkjdjzTyNSQ8fbhYnTeiQGrgkMnQIP/oFBaNWHSBs4sIBCsbzEPD1rqrm0QA6CvQY Cf9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zDC9L7Ue; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kl11-20020a170907994b00b00780def41dc4si7311265ejc.527.2022.10.31.12.39.12; Mon, 31 Oct 2022 12:39:39 -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=@linutronix.de header.s=2020 header.b=zDC9L7Ue; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230020AbiJaT1K (ORCPT + 99 others); Mon, 31 Oct 2022 15:27:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbiJaT1D (ORCPT ); Mon, 31 Oct 2022 15:27:03 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00BE512A91; Mon, 31 Oct 2022 12:27:02 -0700 (PDT) Date: Mon, 31 Oct 2022 19:26:59 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667244420; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3D7hSGn0CvbQ9zOj43AcDS1HiRH7N6eiQqKa+886cCw=; b=zDC9L7UeNyWewuULyQaGuaA0gFbmzXEJzcbYwiyKAgzMMr6BDwGvlSa+zzqWuE6NKEkzJ6 KxCodjeQnYmXiWJ0uTGPLRbzFKCKJrpLnjdJqKT5B9OA7uk7gUp/XLCPibPHhZJtd+bV1w QYV09UIR+4Q3Y0oy5aTmUGFkGeAsROsUEywFuvWIjLyFcVpDItoaasl85N7hKEdaoRXLiq KotKnRdDvhDRNSUfIZ+xnkmQIT+iyPFHPTcZCyyxcR0yCV7yVaUOe+xcaUIqTID3Kj4t+l 6ijZmhRaKfCCnVpeKJyVxuETsLB4ur+9nXdky75YTiCw0RVVrw08nPhBc/sJug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667244420; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3D7hSGn0CvbQ9zOj43AcDS1HiRH7N6eiQqKa+886cCw=; b=N7AzqcQ7o/OQlnFQ8OpabKi+FoKbRq93z+E4O/HwbydJmmz0hxYT4/yO4KOlfaY7zjhHZG 2itkhCBNqi/7WUDA== From: "tip-bot2 for Jason A. Donenfeld" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/misc] x86/espfix: Use get_random_long() rather than archrandom Cc: "Jason A. Donenfeld" , Borislav Petkov , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221029002613.143153-1-Jason@zx2c4.com> References: <20221029002613.143153-1-Jason@zx2c4.com> MIME-Version: 1.0 Message-ID: <166724441903.7716.9086577777719332166.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747980093259166765?= X-GMAIL-MSGID: =?utf-8?q?1748233281656668077?= The following commit has been merged into the x86/misc branch of tip: Commit-ID: 00ed1eabcc3b785aecf6f6cbb41d7b436bb54d28 Gitweb: https://git.kernel.org/tip/00ed1eabcc3b785aecf6f6cbb41d7b436bb54d28 Author: Jason A. Donenfeld AuthorDate: Sat, 29 Oct 2022 02:26:13 +02:00 Committer: Borislav Petkov CommitterDate: Mon, 31 Oct 2022 20:12:50 +01:00 x86/espfix: Use get_random_long() rather than archrandom A call is made to arch_get_random_longs() and rdtsc(), rather than just using get_random_long(), because this was written during a time when very early boot would give abysmal entropy. These days, a call to get_random_long() at early boot will incorporate RDRAND, RDTSC, and more, without having to do anything bespoke. In fact, the situation is now such that on the majority of x86 systems, the pool actually is initialized at this point, even though it doesn't need to be for get_random_long() to still return something better than what this function currently does. So simplify this to just call get_random_long() instead. Signed-off-by: Jason A. Donenfeld Signed-off-by: Borislav Petkov Link: https://lore.kernel.org/r/20221029002613.143153-1-Jason@zx2c4.com --- arch/x86/kernel/espfix_64.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c index 9417d5a..16f9814 100644 --- a/arch/x86/kernel/espfix_64.c +++ b/arch/x86/kernel/espfix_64.c @@ -94,17 +94,7 @@ static inline unsigned long espfix_base_addr(unsigned int cpu) static void init_espfix_random(void) { - unsigned long rand; - - /* - * This is run before the entropy pools are initialized, - * but this is hopefully better than nothing. - */ - if (!arch_get_random_longs(&rand, 1)) { - /* The constant is an arbitrary large prime */ - rand = rdtsc(); - rand *= 0xc345c6b72fd16123UL; - } + unsigned long rand = get_random_long(); slot_random = rand % ESPFIX_STACKS_PER_PAGE; page_random = (rand / ESPFIX_STACKS_PER_PAGE)