LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Anna-Maria Gleixner <anna-maria@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"Tobin C. Harding" <me@tobin.cc>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: Hashed pointer issues
Date: Mon, 30 Apr 2018 09:11:17 -0700
Message-ID: <CAGXu5jL1W=AC023asgeMRUXAnhU2vd-RJRqGtOOetQ=aXwDcFQ@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1804301741570.3243@hypnos.tec.linutronix.de>

On Mon, Apr 30, 2018 at 8:50 AM, Anna-Maria Gleixner
<anna-maria@linutronix.de> wrote:
> Hi,
>
> I stumbled over an issue with hashed pointers and tracing.
>
> I'm using trace points for examination and on error the trace buffers
> are dumped. The error occurs when entropy has not been set up, so the
> pointers are not hashed and only (ptrval) is printed instead. The
> pointers are required to distinguish the different objects in the
> trace.
>
> Beside workarounds like patching lib/vsprintf.c helpers before testing
> or dumping trace buffers later (given that kernel comes up properly
> and entropy is set up), is there a possible generic solution for this
> issue? A commandline option for disabling the pointer obfuscation
> would be a pretty handy tool.

I (or other folks?) had proposed this before, but, AIUI, Linus remains
opposed. I still think something like this would be useful:

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 30c0cb8cc9bc..22bf631395d1 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1703,12 +1703,27 @@ static int __init initialize_ptr_random(void)
 }
 early_initcall(initialize_ptr_random);

+static bool bypass_pointer_hashing __ro_after_init;
+
+static int __init early_bypass_pointer_hashing_param(char *buf)
+{
+       if (!buf)
+               return -EINVAL;
+       return strtobool(buf, &bypass_pointer_hashing);
+}
+early_param("bypass_pointer_hashing", early_bypass_pointer_hashing_param);
+
 /* 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(bypass_pointer_hashing)) {
+               hashval = (uintptr_t)ptr;
+               goto bypass;
+       }
+
        if (unlikely(!have_filled_random_ptr_key)) {
                spec.field_width = default_width;
                /* string length must be less than default_width */
@@ -1726,6 +1741,7 @@ static char *ptr_to_id(char *buf, char *end,
void *ptr, struct printf_spec spec)
        hashval = (unsigned long)siphash_1u32((u32)ptr, &ptr_key);
 #endif

+bypass:
        spec.flags |= SMALL;
        if (spec.field_width == -1) {
                spec.field_width = default_width;


(apologies for gmail-induced whitespace damage...)

-- 
Kees Cook
Pixel Security

  reply index

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-30 15:50 Anna-Maria Gleixner
2018-04-30 16:11 ` Kees Cook [this message]
2018-04-30 16:31   ` Linus Torvalds
2018-04-30 16:41     ` Steven Rostedt
2018-04-30 16:57       ` Linus Torvalds
2018-04-30 17:01         ` Linus Torvalds
2018-04-30 17:06           ` Randy Dunlap
2018-04-30 17:12             ` Linus Torvalds
2018-05-01  7:05               ` tcharding
2018-05-03  8:41             ` Geert Uytterhoeven
2018-04-30 18:38           ` Kees Cook
2018-04-30 19:00             ` Linus Torvalds
2018-04-30 19:16               ` Kees Cook
2018-04-30 20:01                 ` Linus Torvalds
2018-04-30 20:07                   ` Linus Torvalds
2018-04-30 21:23                 ` Tobin C. Harding

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='CAGXu5jL1W=AC023asgeMRUXAnhU2vd-RJRqGtOOetQ=aXwDcFQ@mail.gmail.com' \
    --to=keescook@chromium.org \
    --cc=anna-maria@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@tobin.cc \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    /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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git