lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180316055346.GB5139@jagdpanzerIV>
Date:   Fri, 16 Mar 2018 14:53:46 +0900
From:   Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
To:     Linus Torvalds <torvalds@...ux-foundation.org>,
        Petr Mladek <pmladek@...e.com>,
        Steven Rostedt <rostedt@...dmis.org>
Cc:     Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        "Tobin C . Harding" <me@...in.cc>, Joe Perches <joe@...ches.com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Michal Hocko <mhocko@...e.cz>,
        Sergey Senozhatsky <sergey.senozhatsky@...il.com>
Subject: Re: [PATCH v3] vsprintf: Prevent crash when dereferencing invalid
 pointers

On (03/15/18 18:35), Linus Torvalds wrote:
> On Thu, Mar 15, 2018 at 6:18 PM, Sergey Senozhatsky
> <sergey.senozhatsky.work@...il.com> wrote:
> >
> > Hm, may be sizeof(ptr) still won't suffice. It would be great if we
> > could always look at spec.field_width, which can be up to 2 * sizeof(void *),
> > and then just probe_kernel_read(spec.field_width). E.g., %b/%bl prints out a
> > bitmap, accessing max_t(int, spec.field_width, 0) bits, which is good. But,
> > for instance, %U (uuid printout) doesn't look at spec.field_width, and reads
> > in 16 bytes from the given memory address. Then we have ipv4/ipv6, mac, etc.
> > So I think that checking just 1 byte or sizeof(ptr) is not really enough if
> > we want to fix vsprintf. What do you think?
> 
> Honestly, I think it would be better to move the whole logic to the
> functions that actually do the printout.
> 
> Then you can do it right, and you don't need to have the strchr() either.
>
> There really isn't any commonality between the different versions.
> field_width is meaningless, since it's about the size of the _printed_
> field, not the size in memory.

Agreed!

> Would it be a few more lines? Yes. But it would also clarify the code
> and get all the cases right. Look at hex_string() for example, and
> imagine fetching a byte at a time and just getting the corner cases
> automatically right.

So, basically, what I tried to say - any byte past the first sizeof(ptr)
bytes or past the first byte that we check_access() can cause problems,
which this patch is trying to address. As an example, FORMAT_TYPE_STR
case

	printk("%.*s\n", p->buf)
	 vsnprintf()
	  string()

Where ->buf is a _nearly always_ properly nul terminated char buf[128]
array in struct foo. So moving that check_access() to every function that
does printout sounds good to me, as well as checking every byte we access
[assuming that we want to cure vsprintf], not just the first one or the
first sizeof(ptr) bytes.

	-ss

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ