From: Kees Cook <keescook@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: joe@perches.com, George Spelvin <linux@horizon.com>,
dan.carpenter@oracle.com, viro@zeniv.linux.org.uk,
Jan Beulich <JBeulich@suse.com>,
KOSAKI Motohiro <kosaki.motohiro@gmail.com>,
Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
akpm@linux-foundation.org, Kees Cook <keescook@chromium.org>
Subject: [PATCH 2/2] vsprintf: ignore %n again
Date: Mon, 16 Sep 2013 00:43:57 -0700 [thread overview]
Message-ID: <1379317437-28329-3-git-send-email-keescook@chromium.org> (raw)
In-Reply-To: <1379317437-28329-1-git-send-email-keescook@chromium.org>
This ignores %n in printf again, as was originally documented. Implementing
%n poses a greater security risk than utility, so it should stay ignored.
To help anyone attempting to use %n, a warning will be emitted if it is
encountered.
Based on earlier patch by Joe Perches.
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Joe Perches <joe@perches.com>
---
lib/vsprintf.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 26559bd..478c30e 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1683,18 +1683,16 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
break;
case FORMAT_TYPE_NRCHARS: {
- u8 qualifier = spec.qualifier;
+ /*
+ * Since %n poses a greater security risk than
+ * utility, ignore %n and skip its argument.
+ */
+ void *skip_arg;
- if (qualifier == 'l') {
- long *ip = va_arg(args, long *);
- *ip = (str - buf);
- } else if (_tolower(qualifier) == 'z') {
- size_t *ip = va_arg(args, size_t *);
- *ip = (str - buf);
- } else {
- int *ip = va_arg(args, int *);
- *ip = (str - buf);
- }
+ WARN_ONCE(1, "Please remove ignored %%n in '%s'\n",
+ old_fmt);
+
+ skip_arg = va_arg(args, void *);
break;
}
--
1.7.9.5
next prev parent reply other threads:[~2013-09-16 7:44 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-16 7:43 [PATCH 0/2] " Kees Cook
2013-09-16 7:43 ` [PATCH 1/2] remove all uses of printf's %n Kees Cook
2013-09-16 8:09 ` Geert Uytterhoeven
2013-09-16 15:00 ` Kees Cook
2013-09-17 13:06 ` Tetsuo Handa
2013-09-17 14:34 ` Kees Cook
2013-09-17 20:57 ` George Spelvin
2013-09-19 8:56 ` Tetsuo Handa
2013-09-19 14:28 ` Kees Cook
2013-09-20 4:09 ` Tetsuo Handa
2013-09-20 4:23 ` Joe Perches
2013-09-20 4:53 ` Kees Cook
2013-09-20 8:08 ` Jiri Slaby
2013-09-20 19:24 ` Kees Cook
2013-09-20 19:33 ` Joe Perches
2013-09-21 0:28 ` Tetsuo Handa
2013-09-22 8:09 ` George Spelvin
2013-09-22 8:16 ` Geert Uytterhoeven
2013-09-23 21:24 ` Kees Cook
2013-09-30 8:16 ` Tetsuo Handa
2013-09-16 11:41 ` Tetsuo Handa
2013-09-16 14:59 ` Kees Cook
2013-09-16 15:09 ` Joe Perches
2013-09-16 15:25 ` Kees Cook
2013-09-16 15:44 ` Joe Perches
2013-09-16 17:21 ` George Spelvin
2013-09-16 18:03 ` Joe Perches
2013-09-16 16:07 ` George Spelvin
2013-09-16 16:13 ` Joe Perches
2013-09-16 16:39 ` George Spelvin
2013-09-16 17:53 ` Joe Perches
2013-09-16 19:15 ` George Spelvin
2013-09-16 19:25 ` Joe Perches
2013-09-16 7:43 ` Kees Cook [this message]
2013-09-16 15:55 ` [PATCH 0/2] vsprintf: ignore %n again Al Viro
2013-09-16 16:15 ` Lars-Peter Clausen
2013-09-16 16:30 ` George Spelvin
2013-09-16 18:20 ` Kees Cook
2013-09-18 13:14 ` Tetsuo Handa
2013-09-18 14:11 ` Dan Carpenter
2013-09-18 14:28 ` Dan Carpenter
2013-09-18 15:22 ` George Spelvin
2013-09-18 14:32 ` Kees Cook
2013-09-19 2:11 ` Tetsuo Handa
2013-09-19 7:08 ` Tetsuo Handa
2013-09-18 14:47 ` Kees Cook
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=1379317437-28329-3-git-send-email-keescook@chromium.org \
--to=keescook@chromium.org \
--cc=JBeulich@suse.com \
--cc=akpm@linux-foundation.org \
--cc=dan.carpenter@oracle.com \
--cc=joe@perches.com \
--cc=kosaki.motohiro@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@horizon.com \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--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®