Date: Wed, 18 Oct 2017 14:44:31 +0900 From: Sergey Senozhatsky Message-ID: <20171018054431.GA597@jagdpanzerIV> References: <1508300515-28824-1-git-send-email-me@tobin.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1508300515-28824-1-git-send-email-me@tobin.cc> Subject: [kernel-hardening] Re: [PATCH v4] printk: hash addresses printed with %p To: "Tobin C. Harding" Cc: kernel-hardening@lists.openwall.com, 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 , Steven Rostedt , Chris Fries , Dave Weinstein , Daniel Micay , Djalal Harouni , linux-kernel@vger.kernel.org List-ID: On (10/18/17 15:21), Tobin C. Harding wrote: [..] > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index 86c3385b9eb3..4609738cd2cd 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -33,6 +33,8 @@ > #include > #include > #include > +#include > +#include > #ifdef CONFIG_BLOCK > #include > #endif > @@ -1591,6 +1593,70 @@ char *device_node_string(char *buf, char *end, struct device_node *dn, > return widen_string(buf, buf - buf_start, end, spec); > } > > +/* protects ptr_secret and have_key */ > +DEFINE_SPINLOCK(key_lock); > +static siphash_key_t ptr_secret __read_mostly; > +static atomic_t have_key = ATOMIC_INIT(0); > + > +static int initialize_ptr_secret(void) > +{ > + spin_lock(&key_lock); > + if (atomic_read(&have_key) == 1) > + goto unlock; > + > + get_random_bytes(&ptr_secret, sizeof(ptr_secret)); > + atomic_set(&have_key, 1); > + > +unlock: > + spin_unlock(&key_lock); > + return 0; > +} is this spinlock legal? what happens if we are getting interrupted by NMI? printk() vprintk_emit() vscnprintf() pointer() ptr_to_id() initialize_ptr_secret() spin_lock(&key_lock) ----> NMI printk() printk_safe_log_store() vscnprintf() pointer() ptr_to_id() initialize_ptr_secret() spin_lock(&key_lock) <<<< or am I completely misreading the patch? sorry if so. -ss