All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tobin C. Harding" <me@tobin.cc>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Tobin C. Harding" <me@tobin.cc>,
	"David Laight" <David.Laight@aculab.com>,
	"Kees Cook" <keescook@chromium.org>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	"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@google.com>,
	"Daniel Micay" <danielmicay@gmail.com>,
	"Djalal Harouni" <tixxdz@gmail.com>,
	"Radim Krcmár" <rkrcmar@redhat.com>,
	"David Miller" <davem@davemloft.net>,
	"Stephen Rothwell" <sfr@canb.auug.org.au>,
	"Andrey Ryabinin" <aryabinin@virtuozzo.com>,
	"Alexander Potapenko" <glider@google.com>,
	"Dmitry Vyukov" <dvyukov@google.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	kernel-hardening@lists.openwall.com,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Network Development" <netdev@vger.kernel.org>
Subject: [PATCH 2/2] printk: add specifier %pz, for zeroed address
Date: Thu, 30 Nov 2017 10:38:38 +1100	[thread overview]
Message-ID: <1511998718-4158-3-git-send-email-me@tobin.cc> (raw)
In-Reply-To: <1511998718-4158-1-git-send-email-me@tobin.cc>

Currently %pK [at times] zeros addresses. It would be nice to remove %pK
entirely. Printing zero addresses is useful if we want to sanitize an
address but there may be userland tools that currently rely on the
address format (i.e the correct width).

Add printk specifier %pz.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
 Documentation/printk-formats.txt | 11 +++++++++++
 lib/vsprintf.c                   | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index aa0a776c817a..f88b06485378 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -122,6 +122,17 @@ uniquely grep'able. If, in the future, we need to modify the way the Kernel
 handles printing pointers it will be nice to be able to find the call
 sites.
 
+Zeroed Addresses
+================
+
+::
+
+	%pz	00000000 or 0000000000000000
+
+For printing zeroed addresses. This is useful if you are want to sanitize
+an address but there may be userland tools that depend on the correct width
+of the address for parsing.
+
 Struct Resources
 ================
 
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 81e9ce8f52f9..ebf911618858 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1727,6 +1727,19 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
 	return number(buf, end, hashval, spec);
 }
 
+static noinline_for_stack
+char *zero_string(char *buf, char *end, struct printf_spec spec)
+{
+	spec.base = 16;
+	spec.flags |= SMALL;
+	if (spec.field_width == -1) {
+		spec.field_width = 2 * sizeof(void *);
+		spec.flags |= ZEROPAD;
+	}
+
+	return number(buf, end, 0, spec);
+}
+
 /*
  * Show a '%p' thing.  A kernel extension is that the '%p' is followed
  * by an extra set of alphanumeric characters that are extended format
@@ -1833,6 +1846,9 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
  *                        C full compatible string
  *
  * - 'x' For printing the address. Equivalent to "%lx".
+ * - 'z' For printing zeroed addresses. This is useful if you are want to
+ *       sanitize an address but there may be userland tools that depend on the
+ *       correct width of the address for parsing.
  *
  * ** Please update also Documentation/printk-formats.txt when making changes **
  *
@@ -1960,6 +1976,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		}
 	case 'x':
 		return pointer_string(buf, end, ptr, spec);
+	case 'z':
+		return zero_string(buf, end, spec);
 	}
 
 	/* default is to _not_ leak addresses, hash before printing */
-- 
2.7.4

WARNING: multiple messages have this Message-ID (diff)
From: "Tobin C. Harding" <me@tobin.cc>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Tobin C. Harding" <me@tobin.cc>,
	"David Laight" <David.Laight@aculab.com>,
	"Kees Cook" <keescook@chromium.org>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	"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@google.com>,
	"Daniel Micay" <danielmicay@gmail.com>,
	"Djalal Harouni" <tixxdz@gmail.com>,
	"Radim Krcmár" <rkrcmar@redhat.com>
Subject: [PATCH 2/2] printk: add specifier %pz, for zeroed address
Date: Thu, 30 Nov 2017 10:38:38 +1100	[thread overview]
Message-ID: <1511998718-4158-3-git-send-email-me@tobin.cc> (raw)
In-Reply-To: <1511998718-4158-1-git-send-email-me@tobin.cc>

Currently %pK [at times] zeros addresses. It would be nice to remove %pK
entirely. Printing zero addresses is useful if we want to sanitize an
address but there may be userland tools that currently rely on the
address format (i.e the correct width).

Add printk specifier %pz.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
 Documentation/printk-formats.txt | 11 +++++++++++
 lib/vsprintf.c                   | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index aa0a776c817a..f88b06485378 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -122,6 +122,17 @@ uniquely grep'able. If, in the future, we need to modify the way the Kernel
 handles printing pointers it will be nice to be able to find the call
 sites.
 
+Zeroed Addresses
+================
+
+::
+
+	%pz	00000000 or 0000000000000000
+
+For printing zeroed addresses. This is useful if you are want to sanitize
+an address but there may be userland tools that depend on the correct width
+of the address for parsing.
+
 Struct Resources
 ================
 
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 81e9ce8f52f9..ebf911618858 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1727,6 +1727,19 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
 	return number(buf, end, hashval, spec);
 }
 
+static noinline_for_stack
+char *zero_string(char *buf, char *end, struct printf_spec spec)
+{
+	spec.base = 16;
+	spec.flags |= SMALL;
+	if (spec.field_width == -1) {
+		spec.field_width = 2 * sizeof(void *);
+		spec.flags |= ZEROPAD;
+	}
+
+	return number(buf, end, 0, spec);
+}
+
 /*
  * Show a '%p' thing.  A kernel extension is that the '%p' is followed
  * by an extra set of alphanumeric characters that are extended format
@@ -1833,6 +1846,9 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
  *                        C full compatible string
  *
  * - 'x' For printing the address. Equivalent to "%lx".
+ * - 'z' For printing zeroed addresses. This is useful if you are want to
+ *       sanitize an address but there may be userland tools that depend on the
+ *       correct width of the address for parsing.
  *
  * ** Please update also Documentation/printk-formats.txt when making changes **
  *
@@ -1960,6 +1976,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		}
 	case 'x':
 		return pointer_string(buf, end, ptr, spec);
+	case 'z':
+		return zero_string(buf, end, spec);
 	}
 
 	/* default is to _not_ leak addresses, hash before printing */
-- 
2.7.4

WARNING: multiple messages have this Message-ID (diff)
From: "Tobin C. Harding" <me@tobin.cc>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Tobin C. Harding" <me@tobin.cc>,
	"David Laight" <David.Laight@aculab.com>,
	"Kees Cook" <keescook@chromium.org>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	"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@google.com>,
	"Daniel Micay" <danielmicay@gmail.com>,
	"Djalal Harouni" <tixxdz@gmail.com>,
	"Radim Krcmár" <rkrcmar@redhat.com>,
	"David Miller" <davem@davemloft.net>,
	"Stephen Rothwell" <sfr@canb.auug.org.au>,
	"Andrey Ryabinin" <aryabinin@virtuozzo.com>,
	"Alexander Potapenko" <glider@google.com>,
	"Dmitry Vyukov" <dvyukov@google.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	kernel-hardening@lists.openwall.com,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Network Development" <netdev@vger.kernel.org>
Subject: [kernel-hardening] [PATCH 2/2] printk: add specifier %pz, for zeroed address
Date: Thu, 30 Nov 2017 10:38:38 +1100	[thread overview]
Message-ID: <1511998718-4158-3-git-send-email-me@tobin.cc> (raw)
In-Reply-To: <1511998718-4158-1-git-send-email-me@tobin.cc>

Currently %pK [at times] zeros addresses. It would be nice to remove %pK
entirely. Printing zero addresses is useful if we want to sanitize an
address but there may be userland tools that currently rely on the
address format (i.e the correct width).

Add printk specifier %pz.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
 Documentation/printk-formats.txt | 11 +++++++++++
 lib/vsprintf.c                   | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index aa0a776c817a..f88b06485378 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -122,6 +122,17 @@ uniquely grep'able. If, in the future, we need to modify the way the Kernel
 handles printing pointers it will be nice to be able to find the call
 sites.
 
+Zeroed Addresses
+================
+
+::
+
+	%pz	00000000 or 0000000000000000
+
+For printing zeroed addresses. This is useful if you are want to sanitize
+an address but there may be userland tools that depend on the correct width
+of the address for parsing.
+
 Struct Resources
 ================
 
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 81e9ce8f52f9..ebf911618858 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1727,6 +1727,19 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
 	return number(buf, end, hashval, spec);
 }
 
+static noinline_for_stack
+char *zero_string(char *buf, char *end, struct printf_spec spec)
+{
+	spec.base = 16;
+	spec.flags |= SMALL;
+	if (spec.field_width == -1) {
+		spec.field_width = 2 * sizeof(void *);
+		spec.flags |= ZEROPAD;
+	}
+
+	return number(buf, end, 0, spec);
+}
+
 /*
  * Show a '%p' thing.  A kernel extension is that the '%p' is followed
  * by an extra set of alphanumeric characters that are extended format
@@ -1833,6 +1846,9 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
  *                        C full compatible string
  *
  * - 'x' For printing the address. Equivalent to "%lx".
+ * - 'z' For printing zeroed addresses. This is useful if you are want to
+ *       sanitize an address but there may be userland tools that depend on the
+ *       correct width of the address for parsing.
  *
  * ** Please update also Documentation/printk-formats.txt when making changes **
  *
@@ -1960,6 +1976,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		}
 	case 'x':
 		return pointer_string(buf, end, ptr, spec);
+	case 'z':
+		return zero_string(buf, end, spec);
 	}
 
 	/* default is to _not_ leak addresses, hash before printing */
-- 
2.7.4

  parent reply	other threads:[~2017-11-29 23:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-29 23:38 [PATCH 0/2] replace %pK with %p Tobin C. Harding
2017-11-29 23:38 ` [kernel-hardening] " Tobin C. Harding
2017-11-29 23:38 ` Tobin C. Harding
2017-11-29 23:38 ` [PATCH 1/2] tree-wide: replace all users of " Tobin C. Harding
2017-11-29 23:38   ` [kernel-hardening] " Tobin C. Harding
2017-11-29 23:38   ` Tobin C. Harding
2017-11-29 23:38 ` Tobin C. Harding [this message]
2017-11-29 23:38   ` [kernel-hardening] [PATCH 2/2] printk: add specifier %pz, for zeroed address Tobin C. Harding
2017-11-29 23:38   ` Tobin C. Harding
2017-11-29 23:56 ` [PATCH 0/2] replace %pK with %p Kees Cook
2017-11-29 23:56   ` [kernel-hardening] " Kees Cook
2017-11-29 23:56   ` Kees Cook

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=1511998718-4158-3-git-send-email-me@tobin.cc \
    --to=me@tobin.cc \
    --cc=David.Laight@aculab.com \
    --cc=Golden_Miller83@protonmail.ch \
    --cc=Jason@zx2c4.com \
    --cc=akpm@linux-foundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=catalin.marinas@arm.com \
    --cc=cfries@google.com \
    --cc=danielmicay@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ijc@hellion.org.uk \
    --cc=joe@perches.com \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olorin@google.com \
    --cc=pbonzini@redhat.com \
    --cc=pmladek@suse.com \
    --cc=rkrcmar@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=sfr@canb.auug.org.au \
    --cc=tixxdz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.