mailing list of musl libc
 help / color / mirror / code / Atom feed
* Non-stub setvbuf
@ 2016-01-17  1:43 Rich Felker
  2016-01-17  8:59 ` Jens Gustedt
  0 siblings, 1 reply; 4+ messages in thread
From: Rich Felker @ 2016-01-17  1:43 UTC (permalink / raw)
  To: musl

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-01-17 11:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-17  1:43 Non-stub setvbuf Rich Felker
2016-01-17  8:59 ` Jens Gustedt
2016-01-17 11:03   ` Markus Wichmann
2016-01-17 11:32     ` Jens Gustedt

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