mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "George Spelvin" <linux@horizon.com>
To: joe@perches.com, keescook@chromium.org
Cc: akpm@linux-foundation.org, dan.carpenter@oracle.com,
	davem@davemloft.net, eldad@fogrefinery.com, jbeulich@suse.com,
	jkosina@suse.cz, linux-kernel@vger.kernel.org, linux@horizon.com,
	penguin-kernel@i-love.sakura.ne.jp, rdunlap@infradead.org,
	viro@zeniv.linux.org.uk
Subject: Re: [PATCH] vsprintf: drop comment claiming %n is ignored
Date: 15 Sep 2013 22:53:21 -0400	[thread overview]
Message-ID: <20130916025321.15502.qmail@science.horizon.com> (raw)
In-Reply-To: <1379114610.2066.37.camel@joe-AO722>

> Anyone else have an opinion?

tl;dr: seq_printf() whould return void.


Well, certainly *if* seq_printf returns a value, it should be consistent
with printf, i.e. length or -errno.

If it's going to be anything else, then it should be incompatible with
an integer, so attempted uses cause compile-time errors.  Except for
the fairly unreasonable options of a pointer or a structure, void is
the only available type.

Looking at the callers, a lot of them are trying to compute a summary
length, which is actually really easy to find by just snapshotting
m->count before and after the region being printed.  And there's an
existing seq_overflow() function for detecting errors.

But more importantly, seq_show doesn't *need* the total length returned!
What they various show() functions are achieving by summing the return
values from seq_printf is generating 0 if all prints succeeded and some
negative number of failed prints otherwise.

But show() is supposed to return -errno, and *not* return an error
on overflow (fs/seq_file.c/traverse() checks seq_overflow separately),
so this is Just Plain Broken.  This pattern appears everywhere, and it
appears that somebody misunderstood the specs once, and the result has
been cargo cult copied all over the kernel.

What happens on overflow is that you get some random errno returned to user
space.  Bad bad bad.

Since show() functions *aren't supposed to check* for overflows from
seq_printf (if they do, it breaks the "reallocate and try again" logic),
I support making it return void so that this broken code style errors
out and someone has to really try to mess it up.

(Another code stupidity is that I have no idea why traverse() doesn't
just take care of the -EAGAIN case internally and simplify the calling
convention; it's not like either of the callers check any conditions
before calling right back in again.)

  reply	other threads:[~2013-09-16  2:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-11 19:30 Kees Cook
2013-09-11 20:06 ` Joe Perches
2013-09-11 20:18   ` Kees Cook
2013-09-11 20:20     ` Joe Perches
2013-09-11 20:30       ` KOSAKI Motohiro
2013-09-11 20:28     ` Joe Perches
2013-09-13 19:53       ` George Spelvin
2013-09-13 22:27         ` Joe Perches
2013-09-13 23:03           ` Kees Cook
2013-09-13 23:23             ` Joe Perches
2013-09-16  2:53               ` George Spelvin [this message]
2013-09-14  2:17             ` Al Viro
2013-09-14  2:49             ` Tetsuo Handa
2013-09-14  3:05               ` Al Viro
2013-09-14  3:48                 ` Al Viro
2013-09-14  4:53                   ` Al Viro
2013-09-14  5:26                     ` Joe Perches
2013-09-12  7:03     ` Jan Beulich
2013-09-12  7:31       ` Kees Cook
2013-09-12  7:51         ` Jan Beulich
2013-09-12  7:57       ` Dan Carpenter
2013-09-13 19:49       ` George Spelvin

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=20130916025321.15502.qmail@science.horizon.com \
    --to=linux@horizon.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=eldad@fogrefinery.com \
    --cc=jbeulich@suse.com \
    --cc=jkosina@suse.cz \
    --cc=joe@perches.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=rdunlap@infradead.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®