linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Joe Perches <joe@perches.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Denis Efremov <efremov@linux.com>,
	Julia Lawall <julia.lawall@inria.fr>,
	Alex Dewar <alex.dewar90@gmail.com>,
	linux-kernel@vger.kernel.org, Jonathan Corbet <corbet@lwn.net>,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH V3 1/8] sysfs: Add sysfs_emit and sysfs_emit_at to format sysfs output
Date: Fri, 2 Oct 2020 15:27:35 -0700	[thread overview]
Message-ID: <202010021526.84B4D81268@keescook> (raw)
In-Reply-To: <20201001205029.GC915579@kroah.com>

On Thu, Oct 01, 2020 at 10:50:29PM +0200, Greg Kroah-Hartman wrote:
> On Wed, Sep 30, 2020 at 09:17:03PM -0700, Kees Cook wrote:
> > On Wed, Sep 30, 2020 at 01:57:40PM +0200, Greg Kroah-Hartman wrote:
> > > Kees, and Rafael, I don't know if you saw this proposal from Joe for
> > > sysfs files, questions below:
> > 
> > I'm a fan. I think the use of sprintf() in sysfs might have been one of
> > my earliest complaints about unsafe code patterns in the kernel. ;)
> 
> Ok, great.
> 
> > > > +/**
> > > > + *	sysfs_emit - scnprintf equivalent, aware of PAGE_SIZE buffer.
> > > > + *	@buf:	start of PAGE_SIZE buffer.
> > > > + *	@fmt:	format
> > > > + *	@...:	optional arguments to @format
> > > > + *
> > > > + *
> > > > + * Returns number of characters written to @buf.
> > > > + */
> > > > +int sysfs_emit(char *buf, const char *fmt, ...)
> > > > +{
> > > > +	va_list args;
> > > > +	int len;
> > > > +
> > > > +	if (WARN(!buf || offset_in_page(buf),
> > > > +		 "invalid sysfs_emit: buf:%p\n", buf))
> > 
> > I don't want the %p here, but otherwise, sure. I'd also make it a _ONCE
> > variant:
> > 
> > 	if (WARN_ONCE(!buf || offset_in_page(buf),
> > 		 "invalid sysfs_emit: offset_in_page(buf):%zd\n",
> > 		  buf ? offset_in_page(buf) : 0))
> 
> As Joe points out, _ONCE doesn't work because this happens from all
> sysfs files, not just one.

Sure, it's just a question if you want log spamming vs how reachable you
think something might be. I would expect this to be uncommon to
encounter, but very repeatable for whatever system DOES hit it, so doing
_ONCE means they see the report and don't get completely flooded with
it.

I'm fine either way.

-- 
Kees Cook

      reply	other threads:[~2020-10-02 22:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16 20:40 [PATCH V3 0/8] sysfs: drivers core: Add and use sysfs_emit and sysfs_emit_at Joe Perches
2020-09-16 20:40 ` [PATCH V3 1/8] sysfs: Add sysfs_emit and sysfs_emit_at to format sysfs output Joe Perches
2020-09-30 11:57   ` Greg Kroah-Hartman
2020-09-30 13:58     ` Joe Perches
2020-10-02 11:25       ` Greg Kroah-Hartman
2020-10-01  4:17     ` Kees Cook
2020-10-01  4:22       ` Joe Perches
2020-10-02 22:30         ` Kees Cook
2020-10-03 13:55           ` Greg Kroah-Hartman
2020-10-03 14:59             ` Joe Perches
2020-10-03 22:15             ` Kees Cook
2020-10-01 20:50       ` Greg Kroah-Hartman
2020-10-02 22:27         ` Kees Cook [this message]

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=202010021526.84B4D81268@keescook \
    --to=keescook@chromium.org \
    --cc=alex.dewar90@gmail.com \
    --cc=corbet@lwn.net \
    --cc=efremov@linux.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=julia.lawall@inria.fr \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.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).