mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Non-stub setvbuf
Date: Sat, 16 Jan 2016 20:43:50 -0500	[thread overview]
Message-ID: <20160117014350.GA31121@brightrain.aerifal.cx> (raw)

Right now, musl's stdio setvbuf function does nothing but set the
buffering mode; it does not honor the buffer provided by the caller.
This is perfectly conforming (whether or how the buffer is used is
unspecified), but I realized from the recent thread about OpenSSH's
CVE-2016-0777 on oss-security that a non-stub setvbuf admits a nice
type of hardening:

http://www.openwall.com/lists/oss-security/2016/01/15/15

In short, the application has no way to scrub implementation-internal
stdio buffers that might contain sensitive data read from or written
to files, but it can scrub buffers it provides via setvbuf. So, I'd
like to start actually using the latter, so that apps that attempt
this hardening measure can benefit from it on musl like they would on
other implementations.

The logic I have in mind is something like:

- Ignore application-provided buffers smaller than UNGET (8) bytes,
  possibly plus some reasonable epsilon, and either turn off buffering
  or keep the internal buffer in this case.

- If the application-provided buffer is larger than something
  threshold M (maybe 16k) and the file mode admits reading, only use
  the first M bytes of the buffer. Otherwise repeated fseek+getc is
  very slow (uselessly refilling a large buffer each time).
  Alternatively the logic to limit read buffer size could go in
  __stdio_read.

Does this sound reasonable?

I also reviewed the lack of locking in setvbuf, which looks like it
risks data races accessing f->flags, but it actually seems fine since
the only code that could run concurrently with it without invoking UB
is __stdio_exit (or perhaps fflush(NULL)) which just checks f->rpos,
f->wpos, etc. Perhaps some comments should be added to this effect,
though.

Rich


             reply	other threads:[~2016-01-17  1:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-17  1:43 Rich Felker [this message]
2016-01-17  8:59 ` Jens Gustedt
2016-01-17 11:03   ` Markus Wichmann
2016-01-17 11:32     ` Jens Gustedt

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=20160117014350.GA31121@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).