From: "Tobin C. Harding" <me@tobin.cc>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: kernel-hardening@lists.openwall.com,
Linus Torvalds <torvalds@linux-foundation.org>,
"Jason A. Donenfeld" <Jason@zx2c4.com>,
Theodore Ts'o <tytso@mit.edu>, Kees Cook <keescook@chromium.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Tycho Andersen <tycho@tycho.ws>,
"Roberts, William C" <william.c.roberts@intel.com>,
Tejun Heo <tj@kernel.org>,
Jordan Glover <Golden_Miller83@protonmail.ch>,
Greg KH <gregkh@linuxfoundation.org>,
Petr Mladek <pmladek@suse.com>, Joe Perches <joe@perches.com>,
Ian Campbell <ijc@hellion.org.uk>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <wilal.deacon@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Chris Fries <cfries@google.com>,
Dave Weinstein <olorin@googl
Subject: Re: [PATCH V11 3/5] printk: hash addresses printed with %p
Date: Wed, 6 Dec 2017 07:44:02 +1100 [thread overview]
Message-ID: <20171205204402.GD11064@eros> (raw)
In-Reply-To: <CAMuHMdVZWUHNEbfO7OCPQV5Q3bA41c6VpwqfvT37ZEV9AR8chw@mail.gmail.com>
On Tue, Dec 05, 2017 at 09:20:57PM +0100, Geert Uytterhoeven wrote:
> Hi Tobin,
>
> On Wed, Nov 29, 2017 at 3:05 AM, Tobin C. Harding <me@tobin.cc> wrote:
> > Currently there exist approximately 14 000 places in the kernel where
> > addresses are being printed using an unadorned %p. This potentially
> > leaks sensitive information regarding the Kernel layout in memory. Many
> > of these calls are stale, instead of fixing every call lets hash the
> > address by default before printing. This will of course break some
> > users, forcing code printing needed addresses to be updated.
> >
> > Code that _really_ needs the address will soon be able to use the new
> > printk specifier %px to print the address.
>
> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
>
> > +/* Maps a pointer to a 32 bit unique identifier. */
> > +static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
> > +{
> > + unsigned long hashval;
> > + const int default_width = 2 * sizeof(ptr);
> > +
> > + if (unlikely(!have_filled_random_ptr_key)) {
> > + spec.field_width = default_width;
> > + /* string length must be less than default_width */
> > + return string(buf, end, "(ptrval)", spec);
> > + }
> > +
> > +#ifdef CONFIG_64BIT
> > + hashval = (unsigned long)siphash_1u64((u64)ptr, &ptr_key);
> > + /*
> > + * Mask off the first 32 bits, this makes explicit that we have
> > + * modified the address (and 32 bits is plenty for a unique ID).
> > + */
> > + hashval = hashval & 0xffffffff;
> > +#else
> > + hashval = (unsigned long)siphash_1u32((u32)ptr, &ptr_key);
> > +#endif
>
> Would it make sense to keep the 3 lowest bits of the address?
>
> Currently printed pointers no longer have any correlation with the actual
> alignment in memory of the object, which is a typical cause of a class of bugs.
We'd have to keep the lowest 4 since we are printing in hex, right? This
is easy enough to add. I wasn't the architect behind the hashing but I
can do up a patch and see if anyone who knows crypto objects.
thanks,
Tobin.
next prev parent reply other threads:[~2017-12-05 20:44 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-29 2:05 [PATCH V11 0/5] hash addresses printed with %p Tobin C. Harding
2017-11-29 2:05 ` [PATCH V11 1/5] docs: correct documentation for %pK Tobin C. Harding
2017-11-29 2:05 ` [PATCH V11 2/5] vsprintf: refactor %pK code out of pointer() Tobin C. Harding
2017-11-29 2:39 ` Steven Rostedt
2017-11-29 4:27 ` Tobin C. Harding
2017-11-29 11:54 ` Steven Rostedt
2017-11-29 2:05 ` [PATCH V11 3/5] printk: hash addresses printed with %p Tobin C. Harding
2017-11-29 23:21 ` Andrew Morton
2017-12-05 20:20 ` Geert Uytterhoeven
2017-12-05 20:31 ` David Miller
2017-12-06 10:31 ` David Laight
2017-12-06 23:21 ` Kees Cook
2017-12-06 23:28 ` Linus Torvalds
2017-12-05 20:44 ` Tobin C. Harding [this message]
2017-12-05 22:57 ` Geert Uytterhoeven
2017-12-05 23:33 ` Linus Torvalds
2017-12-06 8:48 ` Geert Uytterhoeven
2017-11-29 2:05 ` [PATCH V11 4/5] vsprintf: add printk specifier %px Tobin C. Harding
2017-11-29 2:29 ` Linus Torvalds
2017-11-29 4:29 ` Tobin C. Harding
2017-11-29 10:07 ` David Laight
2017-11-29 22:28 ` Kees Cook
2017-11-29 22:36 ` Roberts, William C
2017-11-29 22:47 ` Linus Torvalds
2017-11-30 10:38 ` David Laight
2017-12-05 21:08 ` Randy Dunlap
2017-12-05 21:22 ` Linus Torvalds
2017-12-06 1:36 ` Sergey Senozhatsky
2017-12-06 1:59 ` Linus Torvalds
2017-12-06 2:15 ` Sergey Senozhatsky
2017-12-06 8:32 ` Geert Uytterhoeven
2017-12-06 8:45 ` Sergey Senozhatsky
2017-12-07 5:17 ` Tobin C. Harding
2017-12-07 5:29 ` Linus Torvalds
2017-12-07 5:37 ` Sergey Senozhatsky
2017-12-07 5:12 ` Tobin C. Harding
2017-11-29 23:20 ` Andrew Morton
2017-11-29 23:26 ` Tobin C. Harding
2017-11-30 3:58 ` Joe Perches
2017-11-30 4:18 ` Tobin C. Harding
2017-11-30 4:41 ` Joe Perches
2017-11-30 5:00 ` Tobin C. Harding
2017-11-29 2:05 ` [PATCH V11 5/5] kasan: use %px to print addresses instead of %p Tobin C. Harding
2017-11-29 23:20 ` [PATCH V11 0/5] hash addresses printed with %p Andrew Morton
2017-11-29 23:34 ` Tobin C. Harding
2017-11-30 10:23 ` David Laight
2017-11-30 10:26 ` Sergey Senozhatsky
2017-12-01 6:15 ` Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171205204402.GD11064@eros \
--to=me@tobin.cc \
--cc=Golden_Miller83@protonmail.ch \
--cc=Jason@zx2c4.com \
--cc=catalin.marinas@arm.com \
--cc=cfries@google.com \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=ijc@hellion.org.uk \
--cc=joe@perches.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=olorin@googl \
--cc=pbonzini@redhat.com \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.com \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=tycho@tycho.ws \
--cc=tytso@mit.edu \
--cc=wilal.deacon@arm.com \
--cc=william.c.roberts@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).