linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Timur Tabi <timur@kernel.org>
Cc: Kees Cook <keescook@chromium.org>,
	Matthew Wilcox <willy@infradead.org>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	roman.fietze@magna.com, Steven Rostedt <rostedt@goodmis.org>,
	John Ogness <john.ogness@linutronix.de>,
	linux-mm@kvack.org, Akinobu Mita <akinobu.mita@gmail.com>
Subject: Re: [PATCH 0/2] introduce DUMP_PREFIX_UNHASHED for hex dumps
Date: Wed, 20 Jan 2021 10:19:17 +0100	[thread overview]
Message-ID: <YAf1lS8zsHwhShCr@alley> (raw)
In-Reply-To: <29122c86-bfea-2f25-d111-00641cc660ba@kernel.org>

On Tue 2021-01-19 13:55:29, Timur Tabi wrote:
> On 1/19/21 1:45 PM, Kees Cook wrote:
> > How about this so the base address is hashed once, with the offset added
> > to it for each line instead of each line having a "new" hash that makes
> > no sense:
> > 
> > diff --git a/lib/hexdump.c b/lib/hexdump.c
> > index 9301578f98e8..20264828752d 100644
> > --- a/lib/hexdump.c
> > +++ b/lib/hexdump.c
> > @@ -242,12 +242,17 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
> >   		    const void *buf, size_t len, bool ascii)
> >   {
> >   	const u8 *ptr = buf;
> > +	const u8 *addr;
> >   	int i, linelen, remaining = len;
> >   	unsigned char linebuf[32 * 3 + 2 + 32 + 1];
> >   	if (rowsize != 16 && rowsize != 32)
> >   		rowsize = 16;
> > +	if (prefix_type == DUMP_PREFIX_ADDRESS &&
> > +	    ptr_to_hashval(ptr, &addr))
> > +		addr = 0;
> > +
> >   	for (i = 0; i < len; i += rowsize) {
> >   		linelen = min(remaining, rowsize);
> >   		remaining -= rowsize;
> > @@ -258,7 +263,7 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
> >   		switch (prefix_type) {
> >   		case DUMP_PREFIX_ADDRESS:
> >   			printk("%s%s%p: %s\n",
> > -			       level, prefix_str, ptr + i, linebuf);
> > +			       level, prefix_str, addr + i, linebuf);
> 
> Well, this is better than nothing, but not by much.  Again, as long as %px
> exists for printk(), I just cannot understand any resistance to allowing it
> in print_hex_dump().
> 
> Frankly, I think this patch and my patch should both be added.  During
> debugging, it's very difficult if not impossible to work with hashed
> addresses.  I use print_hex_dump() with an unhashed address all the time,
> either by applying my patch to my own kernel or just replacing the %p with
> %px.

This was my view as well. People should not need to add features into
hexdump code when they want to use is for debugging. And the address
is pretty useful.

A solution might be to prevent using this in the mainline:

   + it might be reported by checkpatch.pl

   + it might print some bold warning on the first use, similar to
     trace_printk().

Or we need this in the mainline. Then the use of %pK looks
like the best compromise to me. We could also add some warning
as a comment and use some provocative name for the flag
as suggested by Matthew.

And we should definitely add Linus into CC when sending v2.
His expected opinion has been mentioned several times in this
thread. It would be better to avoid these speculations
and get his real opinion. IMHO, it is too late to add
him in this long thread.

Best Regards,
Petr

  parent reply	other threads:[~2021-01-20 10:25 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-16 22:09 [PATCH 0/2] introduce DUMP_PREFIX_UNHASHED for hex dumps Timur Tabi
2021-01-16 22:09 ` [PATCH 1/2] [v2] lib/hexdump: introduce DUMP_PREFIX_UNHASHED for unhashed addresses Timur Tabi
2021-01-18 10:03   ` Andy Shevchenko
2021-01-18 15:57     ` Timur Tabi
2021-01-18 17:14       ` Andy Shevchenko
2021-01-18 17:53         ` Timur Tabi
2021-01-16 22:09 ` [PATCH 2/2] mm/page_poison: use unhashed address in hexdump for check_poison_mem() Timur Tabi
2021-01-18 18:26 ` [PATCH 0/2] introduce DUMP_PREFIX_UNHASHED for hex dumps Matthew Wilcox
2021-01-18 19:03   ` Timur Tabi
2021-01-19  0:53     ` Sergey Senozhatsky
2021-01-19  1:47       ` Matthew Wilcox
2021-01-19 10:38         ` Sergey Senozhatsky
2021-01-19 19:45           ` Kees Cook
2021-01-26 16:47           ` Vlastimil Babka
2021-01-26 16:59             ` Timur Tabi
2021-01-26 17:14               ` Steven Rostedt
2021-01-26 17:14               ` Vlastimil Babka
2021-01-26 17:30                 ` Timur Tabi
2021-01-26 17:39                   ` Steven Rostedt
2021-01-26 17:40                     ` Steven Rostedt
2021-01-26 19:23                       ` John Ogness
2021-01-27  2:11                         ` Sergey Senozhatsky
2021-01-27  3:22                           ` Timur Tabi
2021-01-27 10:11                       ` Petr Mladek
2021-01-27 10:38                         ` Vlastimil Babka
2021-01-19 19:45         ` Kees Cook
2021-01-19 19:55           ` Timur Tabi
2021-01-19 20:10             ` Steven Rostedt
2021-01-19 20:49               ` Timur Tabi
2021-01-19 21:15                 ` Steven Rostedt
2021-01-19 21:25                   ` Timur Tabi
2021-01-20  9:19             ` Petr Mladek [this message]
2021-01-20 12:17               ` Matthew Wilcox
2021-01-20 19:39               ` Linus Torvalds
2021-01-19 20:18           ` Randy Dunlap
2021-01-20 20:28             ` Kees Cook
2021-01-19  2:30       ` Timur Tabi

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=YAf1lS8zsHwhShCr@alley \
    --to=pmladek@suse.com \
    --cc=akinobu.mita@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=john.ogness@linutronix.de \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=roman.fietze@magna.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=timur@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.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
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).