From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933182AbdJ3Vda (ORCPT ); Mon, 30 Oct 2017 17:33:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:33630 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932796AbdJ3Vd1 (ORCPT ); Mon, 30 Oct 2017 17:33:27 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4F5821911 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=goodmis.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=rostedt@goodmis.org Date: Mon, 30 Oct 2017 17:33:22 -0400 From: Steven Rostedt To: "Tobin C. Harding" Cc: kernel-hardening@lists.openwall.com, "Jason A. Donenfeld" , "Theodore Ts'o" , Linus Torvalds , Kees Cook , Paolo Bonzini , Tycho Andersen , "Roberts, William C" , Tejun Heo , Jordan Glover , Greg KH , Petr Mladek , Joe Perches , Ian Campbell , Sergey Senozhatsky , Catalin Marinas , Will Deacon , Chris Fries , Dave Weinstein , Daniel Micay , Djalal Harouni , linux-kernel@vger.kernel.org Subject: Re: [PATCH V8 2/2] printk: hash addresses printed with %p Message-ID: <20171030173322.6ebed7db@gandalf.local.home> In-Reply-To: <20171026025838.GG12341@eros> References: <1508986436-31966-1-git-send-email-me@tobin.cc> <1508986436-31966-3-git-send-email-me@tobin.cc> <20171026025838.GG12341@eros> X-Mailer: Claws Mail 3.14.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 26 Oct 2017 13:58:38 +1100 "Tobin C. Harding" wrote: > > +static bool have_filled_random_ptr_key; > > +static siphash_key_t ptr_key __read_mostly; > > + > > +static void fill_random_ptr_key(struct random_ready_callback *unused) > > +{ > > + get_random_bytes(&ptr_key, sizeof(ptr_key)); > > + WRITE_ONCE(have_filled_random_ptr_key, true); > > This usage of WRITE_ONCE was suggested by Jason A. Donenfeld. I read > include/linux/compiler.h but was not able to grok it. Is this enough to > stop the compiler re-ordering these two statements? > > Or do I need to read Documentation/memory-barriers.txt [again]? No, the WRITE_ONCE does not stop the compiler from reordering those statements. If you need that, then you need to do: get_random_bytes(&ptr_key, sizeof(ptr_key)); barrier(); WRITE_ONCE(have_filled_random_ptr_key, true); and that only works against interrupts. If you need synchronization across CPUs, then you need smp_mb(). -- Steve