All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/9] vsprintf: Prevent silent crashes and consolidate error handling
@ 2018-04-04  8:58 Petr Mladek
  2018-04-04  8:58 ` [PATCH v4 1/9] vsprintf: Shuffle ptr_to_id() code Petr Mladek
                   ` (8 more replies)
  0 siblings, 9 replies; 57+ messages in thread
From: Petr Mladek @ 2018-04-04  8:58 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Andy Shevchenko, Rasmus Villemoes, Tobin C . Harding,
	Joe Perches, Andrew Morton, Michal Hocko, Sergey Senozhatsky,
	Steven Rostedt, Sergey Senozhatsky, linux-kernel, Petr Mladek

Crash in vsprintf() might be silent when it happens under logbuf_lock
in vprintk_emit(). This patch set prevents most of the crashes by probing
the address. The check is done only by %s and some %p* specifiers that need
to dereference the address.

Only the first byte of the address is checked to keep it simple. It should
be enough to catch most problems.

The check is explicitly done in each function that does the dereference.
It helps to avoid the questionable strchr() of affected specifiers. This
change motivated me to do some preparation patches that consolidated
the error handling and cleaned the code a bit.

Changes against v3:

	+ Add valid_pointer_access() to do the check and store the error
	  message in one call.
	+ Remove strchr(). Instead, validate the address in functions
	  that dereference the address.
	+ Use probe_kernel_address() instead of probe_kernel_real().
	+ Do the check only for unknown address.
	+ Consolidate handling of unsupported pointer modifiers.

Changes against v2:

	+ Fix handling with strchr(string, '\0'). Happens with
	  %p at the very end of the string.
	+ Even more clear commit message
	+ Documentation/core-api/printk-formats.rst update.
	+ Add check into lib/test_printf.c.

Changes against v1:

	+ Do not check access for plain %p.
	+ More clear commit message.


Petr Mladek (9):
  vsprintf: Shuffle ptr_to_id() code
  vsprintf: Consistent %pK handling for kptr_restrict == 0
  vsprintf: Do not check address of well-known strings
  vsprintf: Consolidate handling of unknown pointer specifiers
  vsprintf: Factor out %p[iI] handler as ip_addr_string()
  vsprintf: Factor out %pV handler as va_format()
  vsprintf: Factor out %pO handler as kobject_string()
  vsprintf: Prevent crash when dereferencing invalid pointers
  vsprintf: Avoid confusion between invalid address and value

 Documentation/core-api/printk-formats.rst |   8 +
 lib/test_printf.c                         |  37 ++-
 lib/vsprintf.c                            | 451 ++++++++++++++++++------------
 3 files changed, 313 insertions(+), 183 deletions(-)

-- 
2.13.6

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

end of thread, other threads:[~2018-04-24 16:47 UTC | newest]

Thread overview: 57+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-04  8:58 [PATCH v4 0/9] vsprintf: Prevent silent crashes and consolidate error handling Petr Mladek
2018-04-04  8:58 ` [PATCH v4 1/9] vsprintf: Shuffle ptr_to_id() code Petr Mladek
2018-04-04  8:58 ` [PATCH v4 2/9] vsprintf: Consistent %pK handling for kptr_restrict == 0 Petr Mladek
2018-04-04 23:10   ` Sergey Senozhatsky
2018-04-05 14:34     ` Petr Mladek
2018-04-05 13:04   ` Andy Shevchenko
2018-04-05 14:46     ` Petr Mladek
2018-04-07 14:08       ` Andy Shevchenko
2018-04-09 12:05         ` Petr Mladek
2018-04-09 12:11           ` Andy Shevchenko
2018-04-04  8:58 ` [PATCH v4 3/9] vsprintf: Do not check address of well-known strings Petr Mladek
2018-04-05 13:30   ` Rasmus Villemoes
2018-04-06  9:15     ` Petr Mladek
2018-04-07 14:12       ` Andy Shevchenko
2018-04-09 12:19         ` Petr Mladek
2018-04-10 10:05           ` Andy Shevchenko
2018-04-04  8:58 ` [PATCH v4 4/9] vsprintf: Consolidate handling of unknown pointer specifiers Petr Mladek
2018-04-05 14:25   ` Rasmus Villemoes
2018-04-05 23:45     ` Joe Perches
2018-04-05 23:55       ` Joe Perches
2018-04-06 11:43         ` Petr Mladek
2018-04-06 13:17           ` Rasmus Villemoes
2018-04-06 14:27             ` Joe Perches
2018-04-09 12:30               ` Petr Mladek
2018-04-07 14:23             ` Andy Shevchenko
2018-04-06 23:52         ` Sergey Senozhatsky
2018-04-06 23:59           ` Joe Perches
2018-04-07  0:33             ` Sergey Senozhatsky
2018-04-07  1:00               ` Joe Perches
2018-04-07  1:17                 ` Sergey Senozhatsky
2018-04-06 11:25     ` Petr Mladek
2018-04-07 14:26   ` Andy Shevchenko
2018-04-09 13:50     ` Petr Mladek
2018-04-10 11:41       ` Andy Shevchenko
2018-04-11  9:52         ` Petr Mladek
2018-04-24 16:47           ` Andy Shevchenko
2018-04-04  8:58 ` [PATCH v4 5/9] vsprintf: Factor out %p[iI] handler as ip_addr_string() Petr Mladek
2018-04-04 23:58   ` Sergey Senozhatsky
2018-04-05 14:14     ` Petr Mladek
2018-04-07 14:30   ` Andy Shevchenko
2018-04-04  8:58 ` [PATCH v4 6/9] vsprintf: Factor out %pV handler as va_format() Petr Mladek
2018-04-04 14:26   ` Joe Perches
2018-04-06 13:12     ` Petr Mladek
2018-04-06 14:19       ` Joe Perches
2018-04-09 11:44         ` Petr Mladek
2018-04-09 11:59           ` Joe Perches
2018-04-04  8:58 ` [PATCH v4 7/9] vsprintf: Factor out %pO handler as kobject_string() Petr Mladek
2018-04-04 23:35   ` Sergey Senozhatsky
2018-04-04 23:43     ` Sergey Senozhatsky
2018-04-05 14:02     ` Petr Mladek
2018-04-04  8:58 ` [PATCH v4 8/9] vsprintf: Prevent crash when dereferencing invalid pointers Petr Mladek
2018-04-05 14:46   ` Rasmus Villemoes
2018-04-06 12:26     ` Petr Mladek
2018-04-06 13:12       ` Rasmus Villemoes
2018-04-10 13:26         ` Petr Mladek
2018-04-06  9:37   ` Rasmus Villemoes
2018-04-04  8:58 ` [PATCH v4 9/9] vsprintf: Avoid confusion between invalid address and value Petr Mladek

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.