From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-1593853-1524507128-2-17508231594922633854 X-Sieve: CMU Sieve 3.0 X-Spam-known-sender: no X-Spam-score: 0.0 X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.25, MAILING_LIST_MULTI -1, ME_NOAUTH 0.01, RCVD_IN_DNSWL_HI -5, LANGUAGES en, BAYES_USED global, SA_VERSION 3.4.0 X-Spam-source: IP='209.132.180.67', Host='vger.kernel.org', Country='US', FromHeader='org', MailFrom='org' X-Spam-charsets: plain='us-ascii' X-Resolved-to: greg@kroah.com X-Delivered-to: greg@kroah.com X-Mail-from: stable-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=fm2; t= 1524507127; b=Et/L9J8BoL0mFnN8a35UxG0y536XfA8j6bZzV6HnOy9T0PxCEH Eb/vpvRVw/63XegyvYueibBOU0GHL94uKsVc3Zsn7ddFlfBGFEkRAVFK/PyBnRAa Clpr8f6C94l2uWIG+ET4WpbkOIXdZRsPtqLEqK2/8J3mtz7/X/agSgHO3rt1/GC4 t1Oyu2xBOkvrKq9+mGlWYCDjDwqgi1R8A9GdQ7KwFeUnCwNzzP+zWM/+J9M+uLPo qkP5Z4THurSNWAUZ9ttV/HpmEZhyy54Tadw8kU/LJR8DpKZc7l5mTkQEIEY7E/8T DG8/Yj3SPi3Q6WzaXtdfrnCdtdKfX8KI7rjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to:sender :list-id; s=fm2; t=1524507127; bh=OZnnkK4jtXuWZ2cEmU+HPPqNPa2imV uyj9egfj2uf2k=; b=Lxw8+jY7Ok5tu4qxOJdqedZVsnB7xd3nzp/cIKr1FoQRGY YEEIyiHC4FfrXVog/EixQbZWE/9X9dt6hkTZ/zPl64YPnWg6/w5m45oz/6hvh46J fCm/6OQY+ebao4QZm9upRQR01QrArOabHnGi2AnpOLfCor6b6rgEGJ34Pc1UxXtb rPqW9z9hn6HhuZRov2vwDdetaJqIU36c7phsFQWeJZTR/j5oC07rNJU3QukZGAMV BuZD1eXn1WTHhE6ifkffs2GdbCDy6tCJeH9gFoJITK4qhT07nlRYnliEhGTMXyQz H01C/SOjzbWI94fm1OqkOpzwkPQEtSW/hY2FxTJQ== ARC-Authentication-Results: i=1; mx2.messagingengine.com; arc=none (no signatures found); dkim=none (no signatures found); dmarc=none (p=none,has-list-id=yes,d=none) header.from=linuxfoundation.org; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-cm=none score=0; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=linuxfoundation.org header.result=pass header_is_org_domain=yes; x-vs=clean score=-100 state=0 Authentication-Results: mx2.messagingengine.com; arc=none (no signatures found); dkim=none (no signatures found); dmarc=none (p=none,has-list-id=yes,d=none) header.from=linuxfoundation.org; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-cm=none score=0; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=linuxfoundation.org header.result=pass header_is_org_domain=yes; x-vs=clean score=-100 state=0 X-ME-VSCategory: clean X-CM-Envelope: MS4wfCbTgAkrx7Tkyae46DO68B2A6R1pHIvKxuKNdCAzSlVFACpU7PVRmqzTfAeLGvTvGfNh9oMzklnT0H5Y1dDByYTXS/LGDHl2vlYzARXOvNg7JbUDXtai 0JdS0fd3VvytCw3Vnl19m7li5JQKAkbxfnig8AlSiwgkeUmUXFt4YgoReokan/USm+zA0gtEePjeSPwHWfns6+7ePsEKbSO9kuJhmL48I+fnOY2cFhmzt/+e X-CM-Analysis: v=2.3 cv=E8HjW5Vl c=1 sm=1 tr=0 a=UK1r566ZdBxH71SXbqIOeA==:117 a=UK1r566ZdBxH71SXbqIOeA==:17 a=kj9zAlcOel0A:10 a=Kd1tUaAdevIA:10 a=1XWaLZrsAAAA:8 a=VwQbUJbxAAAA:8 a=ag1SF4gXAAAA:8 a=UGG5zPGqAAAA:8 a=Ew5GXJEXc5wpnDYA0d4A:9 a=PCZodhpv4u1ay8y7:21 a=KbDZm0FV7_o699J5:21 a=CjuIK1q_8ugA:10 a=AjGcO6oz07-iQ99wixmX:22 a=Yupwre4RP9_Eg_Bd0iYG:22 a=17ibUXfGiVyGqR_YBevW:22 X-ME-CMScore: 0 X-ME-CMCategory: none Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932215AbeDWSME (ORCPT ); Mon, 23 Apr 2018 14:12:04 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49482 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932164AbeDWSME (ORCPT ); Mon, 23 Apr 2018 14:12:04 -0400 Date: Mon, 23 Apr 2018 20:11:57 +0200 From: Greg Kroah-Hartman To: Salvatore Bonaccorso Cc: Ben Hutchings , linux-kernel@vger.kernel.org, Theodore Tso , stable@vger.kernel.org, Jann Horn , stable@kernel.org Subject: Re: [PATCH 4.9 75/95] random: set up the NUMA crng instances after the CRNG is fully initialized Message-ID: <20180423181157.GA28110@kroah.com> References: <20180422135210.432103639@linuxfoundation.org> <20180422135213.491879480@linuxfoundation.org> <49fa7d5f484a06f02946afec0688c33849e018de.camel@decadent.org.uk> <20180423072148.jbnd2dodf47ffwej@lorien.valinor.li> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180423072148.jbnd2dodf47ffwej@lorien.valinor.li> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: stable-owner@vger.kernel.org X-Mailing-List: stable@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On Mon, Apr 23, 2018 at 09:21:48AM +0200, Salvatore Bonaccorso wrote: > Hi > > On Sun, Apr 22, 2018 at 11:28:52PM +0100, Ben Hutchings wrote: > > On Sun, 2018-04-22 at 15:53 +0200, Greg Kroah-Hartman wrote: > > > 4.9-stable review patch. If anyone has any objections, please let me know. > > > > > > ------------------ > > > > > > From: Theodore Ts'o > > > > > > commit 8ef35c866f8862df074a49a93b0309725812dea8 upstream. > > > > > > Until the primary_crng is fully initialized, don't initialize the NUMA > > > crng nodes. Otherwise users of /dev/urandom on NUMA systems before > > > the CRNG is fully initialized can get very bad quality randomness. Of > > > course everyone should move to getrandom(2) where this won't be an > > > issue, but there's a lot of legacy code out there. This related to > > > CVE-2018-1108. > > > > > > Reported-by: Jann Horn > > > Fixes: 1e7f583af67b ("random: make /dev/urandom scalable for silly...") > > > Cc: stable@kernel.org # 4.8+ > > > Signed-off-by: Theodore Ts'o > > > Signed-off-by: Greg Kroah-Hartman > > > > In 4.9 (and probably older branches too) this leads to a deadlock: > > > > crng_reseed(primary_crng, ...) takes primary_crng.lock > > -> numa_rcng_init() > > -> crng_initialize() > > -> get_random_bytes() > > -> extract_crng() > > -> _extract_crng(primary_crng, ...) tries to take primary_crng.lock > > > > I think this can be fixed by backporting commit 4a072c71f49b > > "random: silence compiler warnings and fix race" but I'm not sure > > whether that depends on other changes. > > That is, the following test patch on top of the 4.9-stable review > queue seem to resolve the issue. The commit message of the original > commit 4a072c71f49b0a0e495ea13423bdb850da73c58c would though not match > anymore. > > Regards, > Salvatore > From: "Jason A. Donenfeld" > Date: Thu, 15 Jun 2017 00:45:26 +0200 > Subject: random: silence compiler warnings and fix race > Origin: https://git.kernel.org/linus/4a072c71f49b0a0e495ea13423bdb850da73c58c > > Odd versions of gcc for the sh4 architecture will actually warn about > flags being used while uninitialized, so we set them to zero. Non crazy > gccs will optimize that out again, so it doesn't make a difference. > > Next, over aggressive gccs could inline the expression that defines > use_lock, which could then introduce a race resulting in a lock > imbalance. By using READ_ONCE, we prevent that fate. Finally, we make > that assignment const, so that gcc can still optimize a nice amount. > > Finally, we fix a potential deadlock between primary_crng.lock and > batched_entropy_reset_lock, where they could be called in opposite > order. Moving the call to invalidate_batched_entropy to outside the lock > rectifies this issue. > > Fixes: b169c13de473a85b3c859bb36216a4cb5f00a54a > Signed-off-by: Jason A. Donenfeld > Signed-off-by: Theodore Ts'o > Cc: stable@vger.kernel.org > [Salvatore Bonaccorso: backport to 4.9: context changes, only apply change to > address potential deadlock] > --- > drivers/char/random.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > Index: linux-stable/drivers/char/random.c > =================================================================== > --- linux-stable.orig/drivers/char/random.c > +++ linux-stable/drivers/char/random.c > @@ -810,12 +810,12 @@ static int crng_fast_load(const char *cp > p[crng_init_cnt % CHACHA20_KEY_SIZE] ^= *cp; > cp++; crng_init_cnt++; len--; > } > + spin_unlock_irqrestore(&primary_crng.lock, flags); > if (crng_init_cnt >= CRNG_INIT_CNT_THRESH) { > crng_init = 1; > wake_up_interruptible(&crng_init_wait); > pr_notice("random: fast init done\n"); > } > - spin_unlock_irqrestore(&primary_crng.lock, flags); > return 1; > } > > @@ -873,6 +873,7 @@ static void crng_reseed(struct crng_stat > } > memzero_explicit(&buf, sizeof(buf)); > crng->init_time = jiffies; > + spin_unlock_irqrestore(&crng->lock, flags); > if (crng == &primary_crng && crng_init < 2) { > numa_crng_init(); > crng_init = 2; > @@ -880,7 +881,6 @@ static void crng_reseed(struct crng_stat > wake_up_interruptible(&crng_init_wait); > pr_notice("random: crng init done\n"); > } > - spin_unlock_irqrestore(&crng->lock, flags); > } > > static inline void maybe_reseed_primary_crng(void) As this depends on other patches, that are not in 4.9, I don't think this will solve the problem correctly. I've dropped the offending patch for now, hopefully that should be good for the moment. thanks, greg k-h