mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/2] vsprintf: Don't leak pointers
@ 2026-10-15 16:06 Sebastian Andrzej Siewior
  2026-10-15 16:06 ` [PATCH v3 1/2] vsprintf: Don't leak pointers for %ps without KALLSYMS enabled Sebastian Andrzej Siewior
  2026-10-15 16:06 ` [PATCH v3 2/2] kallsyms: Don't leak pointers for unresolved symbols Sebastian Andrzej Siewior
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-15 16:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sebastian Andrzej Siewior, Andrew Morton, Andy Shevchenko,
	Kees Cook, Petr Mladek, Rasmus Villemoes, Sergey Senozhatsky,
	Steven Rostedt, Tycho Andersen, Namhyung Kim

It is possible to leak pointers via %ps without KALLSYMS enabled.
With KALLSYMS pointers can be leaked if they can not be resolved.

The tiny series has two patches, one for each issue.
I do follow the %p format instead of printing "(unknown)" since I care
more about getting it out of the way than the actual content (as long as
it is not the leaked pointer). Last time the discussion added the h:
prefix to a hashed pointer to identify it as such. I would like to keep
this part out of the series since there are few users that expect a
certain pointer width and adding two extra characters would break that
(we could strip the two 0 on 64bit but again, not related to this
problem here).

v2…v3: https://lore.kernel.org/all/20260821152614.2202196-1-bigeasy@linutronix.de/
 - Instead of "(unknown)" the hashed pointer is printed. This follows
   the generic %p flow.
 - In v2 I argued that it is better so print the actual pointer instead
   hiding it for post-mortem analysis. After looking at some backtraces
   with invalid pointers (not part of the kernel image) I realised the
   the PC is already part of the register dump. There I changed it back
   to what %p would do if it can't resolve a pointer. Again, following
   %p flow so it can be overridden at boot.

v1…v2: https://lore.kernel.org/all/20260814144854.746840-1-bigeasy@linutronix.de/
 - For %ps and !KALLSYMS no_hash_pointers is used to decide if the
   pointer should be written or not. This aligns with the %p policy.
 - For %ps and KALLSYMS, unresolved pointer continue to be leaked. It
   has been pointed out it might be useful to see them in backtraces/
   crashes if the return address became invalid.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Tycho Andersen <tycho@tycho.pizza>
To: linux-kernel@vger.kernel.org

Sebastian

---
Sebastian Andrzej Siewior (2):
      vsprintf: Don't leak pointers for %ps without KALLSYMS enabled
      kallsyms: Don't leak pointers for unresolved symbols

 include/linux/sprintf.h |  1 +
 kernel/kallsyms.c       |  3 ++-
 lib/vsprintf.c          | 27 ++++++++++++++++++++++++++-
 3 files changed, 29 insertions(+), 2 deletions(-)
---
base-commit: ec8bf8280261294a9b9b4520414b42704c7f9f6b
change-id: 20261015-vsprintf_kallsym-73d5ed6f800e

Best regards,
--  
Sebastian Andrzej Siewior <bigeasy@linutronix.de>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/2] vsprintf: Don't leak pointers for %ps without KALLSYMS enabled
  2026-10-15 16:06 [PATCH v3 0/2] vsprintf: Don't leak pointers Sebastian Andrzej Siewior
@ 2026-10-15 16:06 ` Sebastian Andrzej Siewior
  2026-10-16  3:28   ` kernel test robot
  2026-10-15 16:06 ` [PATCH v3 2/2] kallsyms: Don't leak pointers for unresolved symbols Sebastian Andrzej Siewior
  1 sibling, 1 reply; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-15 16:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sebastian Andrzej Siewior, Andrew Morton, Andy Shevchenko,
	Kees Cook, Petr Mladek, Rasmus Villemoes, Sergey Senozhatsky,
	Steven Rostedt, Tycho Andersen

The "%ps" format modifier prints the name of the symbol which is more
valuable in terms of debugging and does not leak the actual pointer.

Without KALLSYMS it will leak the pointer which is not intended. The
default policy for pointers is to print a hashed value and not to leak
the actual pointer.

Print a hashed pointer for any symbol resolution witout KALLSYMS
enabled like it is the case for %p.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 lib/vsprintf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 1d95ab9314bf7..a3db25cc1e567 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1008,7 +1008,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
 
 	return string_nocheck(buf, end, sym, spec);
 #else
-	return special_hex_number(buf, end, value, sizeof(void *));
+	return default_pointer(buf, end, ptr, spec);
 #endif
 }
 

-- 
2.55.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] kallsyms: Don't leak pointers for unresolved symbols
  2026-10-15 16:06 [PATCH v3 0/2] vsprintf: Don't leak pointers Sebastian Andrzej Siewior
  2026-10-15 16:06 ` [PATCH v3 1/2] vsprintf: Don't leak pointers for %ps without KALLSYMS enabled Sebastian Andrzej Siewior
@ 2026-10-15 16:06 ` Sebastian Andrzej Siewior
  2026-10-16  4:54   ` kernel test robot
  1 sibling, 1 reply; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-10-15 16:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sebastian Andrzej Siewior, Andrew Morton, Andy Shevchenko,
	Kees Cook, Petr Mladek, Rasmus Villemoes, Sergey Senozhatsky,
	Steven Rostedt, Tycho Andersen, Namhyung Kim

__sprint_symbol() is supposed to resolve the passed address to a symbol
name. If the symbol can not be resolved it will print the actual pointer
that was passed. The pointer policy is to not reveal actual pointer
values.
For post-mortem analysis the pointer in the backtrace shouldn't be
relevant. In BUG(), WARN() and panic() related backtraces the PC
register will contain the actual value.

Add snprintf_default_pointer() as a wrapper around default_pointer() and
use it __sprint_symbol() if the pointer has not been resolved.

Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 include/linux/sprintf.h |  1 +
 kernel/kallsyms.c       |  3 ++-
 lib/vsprintf.c          | 25 +++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/include/linux/sprintf.h b/include/linux/sprintf.h
index f06f7b7850911..596c73a57371e 100644
--- a/include/linux/sprintf.h
+++ b/include/linux/sprintf.h
@@ -24,6 +24,7 @@ __scanf(2, 0) int vsscanf(const char *, const char *, va_list);
 /* These are for specific cases, do not use without real need */
 extern bool no_hash_pointers;
 void hash_pointers_finalize(bool slub_debug);
+int snprintf_default_pointer(char *buf, unsigned int len, const void *ptr);
 
 /* Used for Rust formatting ('%pA') */
 char *rust_fmt_argument(char *buf, char *end, const void *ptr);
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index aec2f06858afd..5d51c825c1e71 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -483,7 +483,8 @@ static int __sprint_symbol(char *buffer, unsigned long address,
 	len = kallsyms_lookup_buildid(address, &size, &offset, &modname, &buildid,
 				       buffer);
 	if (!len)
-		return sprintf(buffer, "0x%lx", address - symbol_offset);
+		return snprintf_default_pointer(buffer, KSYM_SYMBOL_LEN,
+						(void *)(address - symbol_offset));
 
 	offset -= symbol_offset;
 
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index a3db25cc1e567..0ed7134ad2f41 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -849,6 +849,31 @@ static char *default_pointer(char *buf, char *end, const void *ptr,
 	return ptr_to_id(buf, end, ptr, spec);
 }
 
+/**
+ * snprintf_default_pointer - Format a pointer and place it in a buffer
+ * @buf: The buffer to place the result into
+ * @size: The size of the buffer, including the trailing null space
+ * @ptr: The pointer to format
+ *
+ * Formats the passed pointer the same way as the %p modifier. Does not write
+ * more than len bytes to buf including the NULL terminator.
+ *
+ * Returns the number of written bytes.
+ */
+int snprintf_default_pointer(char *buf, unsigned int len, const void *ptr)
+{
+	struct printf_spec spec = {
+		.base = 10,
+		.precision = -1,
+		.field_width = -1,
+	};
+	char *endp;
+
+	endp = default_pointer(buf, buf + len, ptr, spec);
+	*endp = '\0';
+	return endp - buf;
+}
+
 int kptr_restrict __read_mostly;
 EXPORT_SYMBOL_FOR_MODULES(kptr_restrict, "printf_kunit");
 

-- 
2.55.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 1/2] vsprintf: Don't leak pointers for %ps without KALLSYMS enabled
  2026-10-15 16:06 ` [PATCH v3 1/2] vsprintf: Don't leak pointers for %ps without KALLSYMS enabled Sebastian Andrzej Siewior
@ 2026-10-16  3:28   ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2026-10-16  3:28 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel
  Cc: oe-kbuild-all, Sebastian Andrzej Siewior, Andrew Morton,
	Linux Memory Management List, Andy Shevchenko, Kees Cook,
	Petr Mladek, Rasmus Villemoes, Sergey Senozhatsky,
	Steven Rostedt, Tycho Andersen

Hi Sebastian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on ec8bf8280261294a9b9b4520414b42704c7f9f6b]

url:    https://github.com/intel-lab-lkp/linux/commits/Sebastian-Andrzej-Siewior/vsprintf-Don-t-leak-pointers-for-ps-without-KALLSYMS-enabled/20261015-180648
base:   ec8bf8280261294a9b9b4520414b42704c7f9f6b
patch link:    https://lore.kernel.org/r/20261015-vsprintf_kallsym-v3-1-c175c27f38b7%40linutronix.de
patch subject: [PATCH v3 1/2] vsprintf: Don't leak pointers for %ps without KALLSYMS enabled
config: openrisc-defconfig (https://download.01.org/0day-ci/archive/20261016/202610161107.ckH3ptvE-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261016/202610161107.ckH3ptvE-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202610161107.ckH3ptvE-lkp@intel.com/

All warnings (new ones prefixed by >>):

   lib/vsprintf.c: In function 'symbol_string':
>> lib/vsprintf.c:988:23: warning: variable 'value' set but not used [-Wunused-but-set-variable=]
     988 |         unsigned long value;
         |                       ^~~~~


vim +/value +988 lib/vsprintf.c

1031bc589228ca3 Dmitry Monakhov 2015-04-13  983  
cf3b429b03e827c Joe Perches     2010-05-24  984  static noinline_for_stack
cf3b429b03e827c Joe Perches     2010-05-24  985  char *symbol_string(char *buf, char *end, void *ptr,
b0d33c2bd77bcf2 Joe Perches     2012-12-12  986  		    struct printf_spec spec, const char *fmt)
0fe1ef24f7bd002 Linus Torvalds  2008-07-06  987  {
b0d33c2bd77bcf2 Joe Perches     2012-12-12 @988  	unsigned long value;
0fe1ef24f7bd002 Linus Torvalds  2008-07-06  989  #ifdef CONFIG_KALLSYMS
0fe1ef24f7bd002 Linus Torvalds  2008-07-06  990  	char sym[KSYM_SYMBOL_LEN];
b0d33c2bd77bcf2 Joe Perches     2012-12-12  991  #endif
b0d33c2bd77bcf2 Joe Perches     2012-12-12  992  
b0d33c2bd77bcf2 Joe Perches     2012-12-12  993  	if (fmt[1] == 'R')
b0d33c2bd77bcf2 Joe Perches     2012-12-12  994  		ptr = __builtin_extract_return_addr(ptr);
b0d33c2bd77bcf2 Joe Perches     2012-12-12  995  	value = (unsigned long)ptr;
b0d33c2bd77bcf2 Joe Perches     2012-12-12  996  

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] kallsyms: Don't leak pointers for unresolved symbols
  2026-10-15 16:06 ` [PATCH v3 2/2] kallsyms: Don't leak pointers for unresolved symbols Sebastian Andrzej Siewior
@ 2026-10-16  4:54   ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2026-10-16  4:54 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel
  Cc: oe-kbuild-all, Sebastian Andrzej Siewior, Andrew Morton,
	Linux Memory Management List, Andy Shevchenko, Kees Cook,
	Petr Mladek, Rasmus Villemoes, Sergey Senozhatsky,
	Steven Rostedt, Tycho Andersen, Namhyung Kim

Hi Sebastian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on ec8bf8280261294a9b9b4520414b42704c7f9f6b]

url:    https://github.com/intel-lab-lkp/linux/commits/Sebastian-Andrzej-Siewior/vsprintf-Don-t-leak-pointers-for-ps-without-KALLSYMS-enabled/20261015-180648
base:   ec8bf8280261294a9b9b4520414b42704c7f9f6b
patch link:    https://lore.kernel.org/r/20261015-vsprintf_kallsym-v3-2-c175c27f38b7%40linutronix.de
patch subject: [PATCH v3 2/2] kallsyms: Don't leak pointers for unresolved symbols
config: openrisc-defconfig (https://download.01.org/0day-ci/archive/20261016/202610161209.43Dqkd4l-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261016/202610161209.43Dqkd4l-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202610161209.43Dqkd4l-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> Warning: lib/vsprintf.c:863 function parameter 'len' not described in 'snprintf_default_pointer'
>> Warning: lib/vsprintf.c:863 Excess function parameter 'size' description in 'snprintf_default_pointer'
>> Warning: lib/vsprintf.c:863 function parameter 'len' not described in 'snprintf_default_pointer'
>> Warning: lib/vsprintf.c:863 Excess function parameter 'size' description in 'snprintf_default_pointer'

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-10-16  4:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-15 16:06 [PATCH v3 0/2] vsprintf: Don't leak pointers Sebastian Andrzej Siewior
2026-10-15 16:06 ` [PATCH v3 1/2] vsprintf: Don't leak pointers for %ps without KALLSYMS enabled Sebastian Andrzej Siewior
2026-10-16  3:28   ` kernel test robot
2026-10-15 16:06 ` [PATCH v3 2/2] kallsyms: Don't leak pointers for unresolved symbols Sebastian Andrzej Siewior
2026-10-16  4:54   ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®