No description
Find a file
Ahmed S. Darwish 451d1d6762 iochannel: Strictly specify PF_UNIX ancillary data boundaries
Users reported audio breakage for 32-bit pulse clients connected
to a 64-bit server over memfds. Investigating the issue further,
the problem is twofold:

1. iochannel's file-descriptor passing code is liberal in what it
   issues: produced ancillary data object's "data" section exceeds
   length field. How such an extra space is handled is a grey area
   in the POSIX.1g spec, the IETF RFC #2292 "Advanced Sockets API
   for IPv6" memo, and the cmsg(3) manpage.

2. A 64-bit kernel handling of such extra space differs by whether
   the app is 64-bit or 32-bit. For 64-bit apps, the kernel
   smartly ducks the issue. For 32-bit apps, an -EINVAL is
   directly returned; that's due to a kernel CMSG header traversal
   bug in the networking stack "32-bit sockets emulation layer".

   Compare Linux Kernel's socket.h cmsg_nxthdr() code and the
   32-bit emulation layer version of it at net/compat.c
   cmsg_compat_nxthdr() for further info. Notice how the former
   graciously ignores incomplete CMSGs while the latter _directly_
   complains about them -- as of kernel version 4.9-rc5.

   (A kernel patch is to be submitted)

Details:

iochannel typically uses sendmsg() for passing FDs & credentials.
>From RFC 2292, sendmsg() control data is just a heterogeneous
array of embedded ancillary objects that can differ in length.
Linguistically, a "control message" is an ancillary data object.

For example, below is a sendmsg() "msg_control" containing two
ancillary objects:

|<---------------------- msg_controllen---------------------->|
|                                                             |
|<--- ancillary data object -->|<----- ancillary data object->|
|<------- CMSG_SPACE() ------->|<------- CMSG_SPACE() ------->|
|                              |                              |
|<-------- cmsg_len ------->|  |<-------- cmsg_len ------->|  |
|<------- CMSG_LEN() ------>|  |<------- CMSG_LEN() ------>|  |
|                           |  |                           |  |
+-----+-----+-----+--+------+--+-----+-----+-----+--+------+--+
|cmsg_|cmsg_|cmsg_|XX|cmsg_ |XX|cmsg_|cmsg_|cmsg_|XX|cmsg_ |XX|
|len  |level|type |XX|data[]|XX|len  |level|type |XX|data[]|XX|
+-----+-----+-----+--+------+--+-----+-----+-----+--+----+-+--+
 ^^^^^^^ Ancil Object #1        ^^^^^^^ Ancil Object #2
         (control message)              (control message)
^
|
+--- sendmsg() "msg_control" points here

Problem is, while passing FDs, iochannel's code try to avoid
variable-length arrays by creating a single cmsg object that can
fit as much FDs as possible:

  union {
    struct cmsghdr hdr;
    uint8_t data[CMSG_SPACE(sizeof(int) * MAX_ANCIL_DATA_FDS)];
  } cmsg;                                 ^^^^^^^^^^^^^^^^^^

Most of the time though the number of FDs to be passed is less
than the maximum above, thus "cmsg_len" is set to the _actual_ FD
array size:

  cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int) * nfd);
                                             ^^^
This inconsistency tricks the kernel into thinking that we have 2
ancillay data objects instead of one! First cmsg is valid as
intended, but the second is instantly _corrupt_ since it has a
cmsg_len size of 0 -- thus failing kernel's CMSG_OK() tests.

For 32-bit apps on a 32-bit kernel, and 64-bit apps over a 64-bit
one, the kernel's own CMSG header traversal macros just ignore the
second "incomplete" cmsg. For 32-bit apps over a 64-bit kernel
though, the kernel 32-bit socket emulation macros does not forgive
such incompleteness and directly complains of invalid args (due to
a subtle bug).

Avoid this ugly problem, which can also bite us in a pure 64-bit
environment if MAX_ANCIL_DATA_FDS got extended to 5 FDs, by
setting "cmsg_data[]" array size to "cmsg_len".

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=97769

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
2016-11-17 19:07:36 +02:00
doc doc: Add an example stream-restore fallback table file. 2011-10-01 13:25:16 +01:00
doxygen update FSF addresses to FSF web page 2015-01-14 22:20:40 +02:00
m4 build-sys: Move to compiling with C11 support 2016-02-25 09:09:13 +05:30
man daemon-conf: enable memfd by default 2016-09-09 19:42:24 +03:00
po i18n: update Occitan translation 2016-10-13 15:28:43 +03:00
scripts scripts: Plot memory benchmarks using gnuplot 2015-10-31 15:29:48 +02:00
shell-completion core: Support memfd transport; bump protocol version 2016-04-27 18:37:08 +05:30
src iochannel: Strictly specify PF_UNIX ancillary data boundaries 2016-11-17 19:07:36 +02:00
vala vala: Added cnames to callback delegates in Vala VAPI 2016-01-22 13:25:29 +05:30
.gitignore gitignore: Add .orig and .rej to gitignore 2015-12-18 13:34:46 +01:00
.mailmap add a .mailmap file for git shortlog 2009-02-04 22:41:45 +01:00
.travis.yml travis: Run make install in travis. 2015-12-29 05:36:50 +05:30
autogen.sh update FSF addresses to FSF web page 2015-01-14 22:20:40 +02:00
bootstrap.sh build-sys: bootstrap.sh: Do a make only if configure has succeeded 2015-09-25 15:05:43 +03:00
configure.ac build: Check version of check library, require >= 0.9.10 2016-08-10 17:05:01 +03:00
git-version-gen git-version-gen: Avoid further processing when tarball-version is present 2015-10-20 16:55:23 +02:00
GPL * rename "LICENSE" to "LGPL" 2006-04-20 12:33:00 +00:00
LGPL * rename "LICENSE" to "LGPL" 2006-04-20 12:33:00 +00:00
libpulse-mainloop-glib.pc.in build: Fix static linking 2012-07-17 11:05:34 +05:30
libpulse-simple.pc.in build: Fix static linking 2012-07-17 11:05:34 +05:30
libpulse.pc.in build: Fix static linking 2012-07-17 11:05:34 +05:30
LICENSE lfe-filter: Import code from the Chrome OS audio server 2015-03-30 10:52:29 +02:00
Makefile.am scripts: Plot memory benchmarks using gnuplot 2015-10-31 15:29:48 +02:00
NEWS Update NEWS for 9.0 2016-06-22 12:22:04 +05:30
orc.mak build-sys: Move ORC_SOURCE definitions outside of "if HAVE_ORC" 2014-01-24 22:56:27 +02:00
PROTOCOL core: Support memfd transport; bump protocol version 2016-04-27 18:37:08 +05:30
pulseaudio-text.svg merge 'lennart' branch back into trunk. 2007-10-28 19:13:50 +00:00
pulseaudio.supp Add a Valgrind suppression file 2014-09-21 11:00:51 +03:00
pulseaudio.svg Add PulseAudio logo to tree. 2006-08-28 06:25:41 +00:00
PulseAudioConfig.cmake.in build-sys: Provide a simple CMake Config setup (similar to pkgconfig) 2011-10-19 23:49:23 +01:00
PulseAudioConfigVersion.cmake.in build-sys: Provide a simple CMake Config setup (similar to pkgconfig) 2011-10-19 23:49:23 +01:00
README Remove link to CIA from README 2014-10-28 17:36:21 +01:00
todo Update todo 2011-06-24 00:35:26 +01:00

PULSEAUDIO SOUND SERVER

WEB SITE:
	http://pulseaudio.org/

GIT:
	git://anongit.freedesktop.org/pulseaudio/pulseaudio

GITWEB/CGIT:
	http://cgit.freedesktop.org/pulseaudio/pulseaudio/

MAILING LIST:
	http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss

GIT COMMITS MAILING LIST:
	http://lists.freedesktop.org/mailman/listinfo/pulseaudio-commits

TRAC/BUGZILLA TICKET CHANGES MAILING LIST:
	http://lists.freedesktop.org/mailman/listinfo/pulseaudio-bugs

IRC:
	#pulseaudio on irc.freenode.org

FRESHMEAT:
	http://freshmeat.net/projects/pulseaudio/

OHLOH:
	http://www.ohloh.net/projects/4038

AUTHORS:
	Several

HACKING:
	In order to run pulseaudio from the build dir __OPTIMIZE__ should be
	disabled (look at src/pulsecore/core-util.h::pa_run_from_build_tree()),
	this can be done by passing "CFLAGS=-O0" to the configure script:
	  ./autogen.sh
	  CFLAGS="-ggdb3 -O0" LDFLAGS="-ggdb3" ./configure
	  make
	  ./src/pulseaudio -n -F src/default.pa -p $(pwd)/src/

SPELLING:
        PulseAudio