[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20171019000044.GA604@jagdpanzerIV>
Date: Thu, 19 Oct 2017 09:00:44 +0900
From: Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
To: "Tobin C. Harding" <me@...in.cc>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>,
kernel-hardening@...ts.openwall.com,
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 <will.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>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4] printk: hash addresses printed with %p
On (10/18/17 17:04), Tobin C. Harding wrote:
[..]
> > > +/* 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?
>
> I think we can do without the spinlock. I think I was already told that when
> I tried to put it [some where else] in v1.
>
> It's fun failing in public ;)
another note is that printk()->vscnprintf()->get_random_bytes()->warn_unseeded_randomness()
causes a printk() recursion, but we should be fine now, we are in printk_safe
mode by the time we vscnprintf().
but a bigger problem might the following thing:
vscnprintf()
pointer()
ptr_to_id()
initialize_ptr_secret()
get_random_bytes()
_get_random_bytes()
extract_crng()
_extract_crng()
spin_lock_irqsave(&crng->lock, flags); <<<<<
this, once again, can deadlock. can it? just like before:
> > 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) <<<<
-ss
Powered by blists - more mailing lists