All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Justin He <Justin.He@arm.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Luca Coelho <luciano.coelho@intel.com>,
	Kalle Valo <kvalo@codeaurora.org>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Johannes Berg <johannes.berg@intel.com>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-s390@vger.kernel.org" <linux-s390@vger.kernel.org>
Subject: Re: [PATCH RFCv2 2/3] lib/vsprintf.c: make %pD print full path for file
Date: Mon, 31 May 2021 11:40:34 +0200	[thread overview]
Message-ID: <YLSvEqQQj5RLjAJ/@alley> (raw)
In-Reply-To: <YLOsvz8ZbpjfcuGO@casper.infradead.org>

On Sun 2021-05-30 16:18:23, Matthew Wilcox wrote:
> On Fri, May 28, 2021 at 10:06:37PM +0200, Rasmus Villemoes wrote:
> > On 28/05/2021 16.22, Justin He wrote:
> > > 
> > >> From: Matthew Wilcox <willy@infradead.org>
> > 
> > >> How is it "safer"?  You already have a buffer passed from the caller.
> > >> Are you saying that d_path_fast() might overrun a really small buffer
> > >> but won't overrun a 256 byte buffer?
> > > No, it won't overrun a 256 byte buf. When the full path size is larger than 256, the p->len is < 0 in prepend_name, and this overrun will be
> > > dectected in extract_string() with "-ENAMETOOLONG".
> > > 
> > > Each printk contains 2 vsnprintf. vsnprintf() returns the required size after formatting the string.>
> > > 1. vprintk_store() will invoke 1st vsnprintf() will 8 bytes space to get the reserve_size. In this case, the _buf_ could be less than _end_ by design.
> > > 2. Then it invokes 2nd printk_sprint()->vscnprintf()->vsnprintf() to really fill the space.
> > 
> > Please do not assume that printk is the only user of vsnprintf() or the
> > only one that would use a given %p<foo> extension.
> > 
> > Also, is it clear that nothing can change underneath you in between two
> > calls to vsnprintf()? IOW, is it certain that the path will fit upon a
> > second call using the size returned from the first?
> 
> No, but that's also true of %s.  I think vprintk_store() is foolish to
> do it this way.

Just for record. vprintk_store() is foolish here by intention.
It avoids the need of static per-CPU X per-context buffers
and it is simple.

I believe that it should be good enough in practice. Any race here
would make the result racy anyway.

Of course, we might need to reconsider it if there are real life
problems with this approach.

Best Regards,
Petr

  reply	other threads:[~2021-05-31  9:40 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28 11:39 [PATCH RFCv2 0/3] make '%pD' print full path for file Jia He
2021-05-28 11:39 ` [PATCH RFCv2 1/3] fs: introduce helper d_path_fast() Jia He
2021-05-28 12:37   ` kernel test robot
2021-05-28 12:44   ` Al Viro
2021-05-28 12:51   ` Matthew Wilcox
2021-05-28 14:23     ` Justin He
2021-05-28 16:02   ` kernel test robot
2021-05-28 11:39 ` [PATCH RFCv2 2/3] lib/vsprintf.c: make %pD print full path for file Jia He
2021-05-28 12:59   ` Matthew Wilcox
2021-05-28 14:22     ` Justin He
2021-05-28 14:52       ` Matthew Wilcox
2021-05-28 15:09         ` Justin He
2021-05-28 15:22           ` Matthew Wilcox
2021-05-31  0:39             ` Justin He
2021-06-01 14:42             ` Justin He
2021-06-01 15:30               ` Matthew Wilcox
2021-06-01 15:36                 ` Andy Shevchenko
2021-06-01 15:44                   ` Matthew Wilcox
2021-06-01 15:53                     ` Andy Shevchenko
2021-06-01 16:10                       ` Andy Shevchenko
2021-06-01 17:05                         ` Matthew Wilcox
2021-06-01 19:01                           ` Rasmus Villemoes
2021-06-02  5:47                             ` Justin He
2021-05-28 20:06       ` Rasmus Villemoes
2021-05-30 15:18         ` Matthew Wilcox
2021-05-31  9:40           ` Petr Mladek [this message]
2021-05-30 20:51   ` kernel test robot
2021-05-28 11:39 ` [PATCH RFCv2 3/3] s390/hmcdrv: remove the redundant directory path in debug message Jia He
2021-05-29  0:26 [PATCH RFCv2 2/3] lib/vsprintf.c: make %pD print full path for file kernel test robot

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=YLSvEqQQj5RLjAJ/@alley \
    --to=pmladek@suse.com \
    --cc=Justin.He@arm.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=borntraeger@de.ibm.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=johannes.berg@intel.com \
    --cc=kuba@kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=luciano.coelho@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --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 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.