mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Kees Cook <keescook@chromium.org>,
	Frederic Weisbecker <fweisbec@gmail.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	devel@driverdev.osuosl.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Tushar Behera <tushar.behera@linaro.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Lidza Louina <lidza.louina@gmail.com>
Subject: Re: [PATCH] staging: dgnc: fix potential format string flaw
Date: Wed, 11 Sep 2013 12:45:00 -0700	[thread overview]
Message-ID: <1378928700.4714.17.camel@joe-AO722> (raw)
In-Reply-To: <CAGXu5jLO6109fkejXqX=WhkQnfAUeWtTcow0v1BNqyi=8=Qa3Q@mail.gmail.com>

On Wed, 2013-09-11 at 12:25 -0700, Kees Cook wrote:
> On Wed, Sep 11, 2013 at 12:09 PM, Joe Perches <joe@perches.com> wrote:
> > On Wed, 2013-09-11 at 11:19 -0700, Kees Cook wrote:
> >> On Wed, Sep 11, 2013 at 2:31 AM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >> > On Tue, Sep 10, 2013 at 10:19:17PM -0700, Kees Cook wrote:
> >> >> In the former case, format characters will get processed by the
> >> >> sprintf logic. In the latter, they are printed as-is. In this specific
> >> >> case, if there was a way to inject strings like "ohai %n" into the
> >> >> msgbuf string, the former would actually attempt to resolve the %n. In
> >> >> the simple case, this could lead to Oopses, and in the unlucky case,
> >> >> it could allow arbitrary memory writing and execution control.
> >> >>
> >> >> http://en.wikipedia.org/wiki/Uncontrolled_format_string
> >> >
> >> > The kernel ignores %n so hopefully it can't actually write to memory.
> >>
> >> I wish! This is not the case, though. See FORMAT_TYPE_NRCHARS in
> >> lib/vsprintf.c's vsnprintf().
> >>
> >> $ git grep '%n' | wc -l
> >> 111
> >
> > Umm.
> >
> > See: lib/vsprintf.c
> >
> > /**
> >  * vsnprintf - Format a string and place it in a buffer
> > [...]
> >  * %n is ignored
> >
> > %n does work for vsscanf though.
> 
> The comment is a lie:
> 
>         int len = 0;
>         printk("len:%d\n", len);
>         printk("%s%n\n", "Ohai!", &len);
>         printk("len:%d\n", len);
> 
> [    0.025930] len:0
> [    0.026003] Ohai!
> [    0.026261] len:5
> 
> The functionality between scanf and printf was, I think, merged in
> 2009, if I'm reading the git blame correctly.

Yeah.

commit fef20d9c1380f04ba9492d6463148db07b413708
Author: Frederic Weisbecker <fweisbec@gmail.com>
Date:   Fri Mar 6 17:21:50 2009 +0100

    vsprintf: unify the format decoding layer for its 3 users

Maybe it should be reignored...

There are a few more in net/ though that may be pretty
easy to change to use the seq_printf return value.


net/ipv4/fib_trie.c-                            seq_printf(seq,
net/ipv4/fib_trie.c-                                     "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
net/ipv4/fib_trie.c:                                     "%d\t%08X\t%d\t%u\t%u%n",
net/ipv4/fib_trie.c-                                     fi->fib_dev ? fi->fib_dev->name : "*",
--
net/ipv4/fib_trie.c-                            seq_printf(seq,
net/ipv4/fib_trie.c-                                     "*\t%08X\t%08X\t%04X\t%d\t%u\t"
net/ipv4/fib_trie.c:                                     "%d\t%08X\t%d\t%u\t%u%n",
net/ipv4/fib_trie.c-                                     prefix, 0, flags, 0, 0, 0,
--
net/ipv4/ping.c-        seq_printf(f, "%5d: %08X:%04X %08X:%04X"
net/ipv4/ping.c:                " %02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %d%n",
net/ipv4/ping.c-                bucket, src, srcp, dest, destp, sp->sk_state,
--
net/ipv4/tcp_ipv4.c-    seq_printf(f, "%4d: %08X:%04X %08X:%04X"
net/ipv4/tcp_ipv4.c:            " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK%n",
net/ipv4/tcp_ipv4.c-            i,
--
net/ipv4/tcp_ipv4.c-    seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
net/ipv4/tcp_ipv4.c:                    "%08X %5u %8d %lu %d %pK %lu %lu %u %u %d%n",
net/ipv4/tcp_ipv4.c-            i, src, srcp, dest, destp, sk->sk_state,
--
net/ipv4/tcp_ipv4.c-    seq_printf(f, "%4d: %08X:%04X %08X:%04X"
net/ipv4/tcp_ipv4.c:            " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
net/ipv4/tcp_ipv4.c-            i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
--
net/ipv4/udp.c- seq_printf(f, "%5d: %08X:%04X %08X:%04X"
net/ipv4/udp.c:         " %02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %d%n",
net/ipv4/udp.c-         bucket, src, srcp, dest, destp, sp->sk_state,
--
net/sctp/objcnt.c:	seq_printf(seq, "%s: %d%n", sctp_dbg_objcnt[i].label,
net/sctp/objcnt.c-				atomic_read(sctp_dbg_objcnt[i].counter), &len);




  reply	other threads:[~2013-09-11 19:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-11  4:41 Kees Cook
2013-09-11  5:00 ` Joe Perches
2013-09-11  5:19   ` Kees Cook
2013-09-11  9:31     ` Dan Carpenter
2013-09-11 18:19       ` Kees Cook
2013-09-11 19:09         ` Joe Perches
2013-09-11 19:25           ` Kees Cook
2013-09-11 19:45             ` Joe Perches [this message]
2013-09-11 19:47               ` Kees Cook
2013-09-11 23:22                 ` [RFC PATCH] vsnprintf: Remove use of %n and convert existing uses Joe Perches
2013-09-11 23:29                   ` Kees Cook
2013-09-11 23:43                     ` Joe Perches
2013-09-11 23:40                   ` Tetsuo Handa
2013-09-12  0:04                     ` Joe Perches
2013-09-12  0:19                       ` Al Viro
2013-09-12  0:41                         ` Joe Perches
2013-09-12  8:06                         ` David Laight
2013-09-12 15:59                           ` Joe Perches
2013-09-11 19:28           ` [PATCH] staging: dgnc: fix potential format string flaw Dan Carpenter
2013-09-11 19:22         ` Dan Carpenter
2013-09-11 19:26           ` 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=1378928700.4714.17.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=fweisbec@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=lidza.louina@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tushar.behera@linaro.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

all inboxes | Powered by JetHome®