Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6134086iog; Thu, 23 Jun 2022 12:04:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uVAkQrFwWN5Hw0hJGyRWv2SRh9uyNU74LbLCasHF1bkqQpmwuDaGkU99uPuh8N23D9WSoN X-Received: by 2002:a17:907:a410:b0:70b:db4d:784d with SMTP id sg16-20020a170907a41000b0070bdb4d784dmr9561873ejc.185.1656011042054; Thu, 23 Jun 2022 12:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011042; cv=none; d=google.com; s=arc-20160816; b=CgHeO6RySm01KWT+KTd6lswexrroIPhd3j8t9vFwe3RP44sQt8wdsqkLwsEZ0TgCZ7 sFGZuz7mnC0/3SyluA37ycPuulJ0gRQx1qjJcNbl5/h0TvM9KKFLV8bfV/ksAt55orJI 2GHEaJTVa33lA/VJzHijR7pweGcg8DvaITDtycX3AVohG2PH4F84TUF/Xo+BhoCb5Dfm wXIuMWs/qwGhH8GjSU1+vXcIuAHqqAzBvuwTovkPZvIIjOX2UPOK4Ou0zNGLZhXrPFWS xVckoq7caFBf31cBzggDIcqj9FSjpsxOImth6DbKwLWaIMUxMLgUfxJamhzTDogcTvpz 9/GA== 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=ZijV7uwR+rJiyJ9GgKt1gKhvelquN+5YyrfC3AUc4y4=; b=ISEVvBp9mWTYw6cbA9wL0wGbzTxNZUGuqEyXkz+pwhqRpugaaJpMTs4bLP6j78o1wR FcW4daUFNhHzEH6lmSMvdKxk0D0h3qDx5Zu0VLLK4o0BKIHw157oZlw+uzk21kbDkPh0 fwaoPQVHE2AxDbdVecHIESGRvBhqWXOaqnVoC6G5xmKPNUK3b331SPVcA+/lPLEntqAM jBo8fZmqFaqDIBu9IISE+Lev7fyVNN7BZovcY5a5JeaPstB5fhL3IS+2/55v8b1X7uvB YytinVk8q2aURGtvgyASOlLfjuaPTsULK1j2a3GdOUwNt4i3QTfHHZy01l3T/sE0gLpi ZdGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ayql+vIw; 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 m22-20020a509996000000b0043579ad55f1si367279edb.94.2022.06.23.12.03.35; Thu, 23 Jun 2022 12:04:02 -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=ayql+vIw; 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 S235799AbiFWSBs (ORCPT + 99 others); Thu, 23 Jun 2022 14:01:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235462AbiFWSAF (ORCPT ); Thu, 23 Jun 2022 14:00:05 -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 CD14BB2CD7; Thu, 23 Jun 2022 10:16: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 ams.source.kernel.org (Postfix) with ESMTPS id 43E11B824C3; Thu, 23 Jun 2022 17:16:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67D7EC3411B; Thu, 23 Jun 2022 17:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004584; bh=S3YMGlBQd+PdiEBvJrxDigLY2QzFeAmLcpbCH7wJ2jM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ayql+vIw7BEeaA4CkmkcUItw2bV6EoQ3Ve4I02uYNIkrEx+4JBpo2JwzFuM/p0XHP ABRil2o+NtKN4GEQFMwCZDv7wuc86vw+VDWew0ORbbMDqMSu8Oh3uRs2tDX48NV+TA RdznjYjfjx2DdldwqZATrJA6Qt04lD6xWF7VRPO8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel , Andre Przywara , Eric Biggers , Marc Zyngier , "Jason A. Donenfeld" , Will Deacon Subject: [PATCH 4.19 043/234] random: avoid arch_get_random_seed_long() when collecting IRQ randomness Date: Thu, 23 Jun 2022 18:41:50 +0200 Message-Id: <20220623164344.284764362@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: Ard Biesheuvel commit 390596c9959c2a4f5b456df339f0604df3d55fe0 upstream. When reseeding the CRNG periodically, arch_get_random_seed_long() is called to obtain entropy from an architecture specific source if one is implemented. In most cases, these are special instructions, but in some cases, such as on ARM, we may want to back this using firmware calls, which are considerably more expensive. Another call to arch_get_random_seed_long() exists in the CRNG driver, in add_interrupt_randomness(), which collects entropy by capturing inter-interrupt timing and relying on interrupt jitter to provide random bits. This is done by keeping a per-CPU state, and mixing in the IRQ number, the cycle counter and the return address every time an interrupt is taken, and mixing this per-CPU state into the entropy pool every 64 invocations, or at least once per second. The entropy that is gathered this way is credited as 1 bit of entropy. Every time this happens, arch_get_random_seed_long() is invoked, and the result is mixed in as well, and also credited with 1 bit of entropy. This means that arch_get_random_seed_long() is called at least once per second on every CPU, which seems excessive, and doesn't really scale, especially in a virtualization scenario where CPUs may be oversubscribed: in cases where arch_get_random_seed_long() is backed by an instruction that actually goes back to a shared hardware entropy source (such as RNDRRS on ARM), we will end up hitting it hundreds of times per second. So let's drop the call to arch_get_random_seed_long() from add_interrupt_randomness(), and instead, rely on crng_reseed() to call the arch hook to get random seed material from the platform. Signed-off-by: Ard Biesheuvel Reviewed-by: Andre Przywara Tested-by: Andre Przywara Reviewed-by: Eric Biggers Acked-by: Marc Zyngier Reviewed-by: Jason A. Donenfeld Link: https://lore.kernel.org/r/20201105152944.16953-1-ardb@kernel.org Signed-off-by: Will Deacon Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1280,8 +1280,6 @@ void add_interrupt_randomness(int irq, i cycles_t cycles = random_get_entropy(); __u32 c_high, j_high; __u64 ip; - unsigned long seed; - int credit = 0; if (cycles == 0) cycles = get_reg(fast_pool, regs); @@ -1317,23 +1315,12 @@ void add_interrupt_randomness(int irq, i fast_pool->last = now; __mix_pool_bytes(r, &fast_pool->pool, sizeof(fast_pool->pool)); - - /* - * If we have architectural seed generator, produce a seed and - * add it to the pool. For the sake of paranoia don't let the - * architectural seed generator dominate the input from the - * interrupt noise. - */ - if (arch_get_random_seed_long(&seed)) { - __mix_pool_bytes(r, &seed, sizeof(seed)); - credit = 1; - } spin_unlock(&r->lock); fast_pool->count = 0; /* award one bit for the contents of the fast pool */ - credit_entropy_bits(r, credit + 1); + credit_entropy_bits(r, 1); } EXPORT_SYMBOL_GPL(add_interrupt_randomness);