|
Message-ID: <CAHmME9oawjpRQEqo_rHgqjC6S8pSrEr2sbr06Gkhm93DXq9kqA@mail.gmail.com> Date: Thu, 19 Oct 2017 03:03:48 +0200 From: "Jason A. Donenfeld" <Jason@...c4.com> To: "Tobin C. Harding" <me@...in.cc> Cc: kernel-hardening@...ts.openwall.com, "Theodore Ts'o" <tytso@....edu>, Linus Torvalds <torvalds@...ux-foundation.org>, Kees Cook <keescook@...omium.org>, Paolo Bonzini <pbonzini@...hat.com>, Tycho Andersen <tycho@...ker.com>, "Roberts, William C" <william.c.roberts@...el.com>, Tejun Heo <tj@...nel.org>, Jordan Glover <Golden_Miller83@...tonmail.ch>, Greg KH <gregkh@...uxfoundation.org>, Petr Mladek <pmladek@...e.com>, Joe Perches <joe@...ches.com>, Ian Campbell <ijc@...lion.org.uk>, Sergey Senozhatsky <sergey.senozhatsky@...il.com>, Catalin Marinas <catalin.marinas@....com>, Will Deacon <wilal.deacon@....com>, Steven Rostedt <rostedt@...dmis.org>, Chris Fries <cfries@...gle.com>, Dave Weinstein <olorin@...gle.com>, Daniel Micay <danielmicay@...il.com>, Djalal Harouni <tixxdz@...il.com>, LKML <linux-kernel@...r.kernel.org> Subject: Re: [PATCH v5] printk: hash addresses printed with %p On Wed, Oct 18, 2017 at 11:30 PM, Tobin C. Harding <me@...in.cc> wrote: > +static siphash_key_t ptr_secret __read_mostly; > +static atomic_t have_key = ATOMIC_INIT(0); > + > +static void initialize_ptr_secret(void) > +{ > + if (atomic_read(&have_key) == 1) > + return; > + > + get_random_bytes(&ptr_secret, sizeof(ptr_secret)); > + atomic_set(&have_key, 1); > +} > + case -EALREADY: > + initialize_ptr_secret(); > + break; Unfortunately the above is racy, and the spinlock you had before was actually correct (though using an atomic inside a spinlock wasn't strictly necessary). The race is that two callers might hit initialize_ptr_secret at the same time, and have_key will be zero at the beginning for both. Then they'll both scribble over ptr_secret, and might wind up using a different value after if one finishes before the other. I see two ways of correcting this: 1) Go back to the spinlock yourself. 2) Use get_random_bytes_once(&ptr_secret, sizeof(ptr_secret)). I don't know lib/once.c especially well, but from cursory look, it appears to be taking a spinlock too, which means you're probably good. + if (atomic_read(&have_key) == 0) { + random_ready.owner = NULL; + random_ready.func = schedule_async_key_init; You can probably take care of this part in the initialization: static struct random_ready_callback random_ready = { .func = schedule_async_key_init }; Alternatively, you could put the actual call to add_random_ready_callback in an init function, but maybe how you have it is easier. Jason
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.