<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>This looks like an interesting read.</div><div><br></div><div>Stephen Michael Kellat <br><br><br>Begin forwarded message:<br><br></div><blockquote type="cite"><div><b>From:</b> Seth Arnold <1203207@<a href="http://bugs.launchpad.net">bugs.launchpad.net</a>><br><b>Date:</b> October 7, 2013, 9:36:38 PM EDT<br><b>To:</b> <a href="mailto:skellat@fastmail.net">skellat@fastmail.net</a><br><b>Subject:</b> <b>[Bug 1203207] Re: [MIR] mir</b><br><b>Reply-To:</b> Bug 1203207 <1203207@<a href="http://bugs.launchpad.net">bugs.launchpad.net</a>><br><br></div></blockquote><blockquote type="cite"><div><span>I reviewed Mir version 0.0.12+13.10.20130926.1-0ubuntu1 as checked into</span><br><span>Saucy. This should not be considered a full security audit, but rather a</span><br><span>quick gauge of code quality.</span><br><span></span><br><span>- Mir is a new display server, intending to replace X11, to rely upon the</span><br><span>  features of high-powered modern graphics hardware available in both</span><br><span>  traditional computers and newfangled handheld devices. By starting over</span><br><span>  with higher demands on hardware and reduced demands on legacy features,</span><br><span>  the intention is to provide a display server that is faster and more</span><br><span>  secure (e.g., preventing mouse grabs and keyboard grabs from preventing</span><br><span>  screen saver lock, or client keypress sniffing, or other annoyances from</span><br><span>  the X11 legacy codebase).</span><br><span>- Build-Depends upon cmake, doxygen, xsltproc, graphviz, boost, protobuf,</span><br><span>  libdrm, libegl1-mesa, libgles2-mesa, libgdm, libglm, libhardware,</span><br><span>  libgoogle-glog, liblttns-ust, libxkbcommon, umockdev, libudev,</span><br><span>  google-mock, valgrind</span><br><span>- No cryptography</span><br><span>- Extensive local networking, no off-machine networking</span><br><span>- Not exactly the usual daemon; does not double-fork(2), setpgid(2) and</span><br><span>  setsid(2) happen via mgg::LinuxVirtualTerminal::open_vt() rather than at</span><br><span>  startup.</span><br><span>- No initscripts</span><br><span>- No dbus</span><br><span>- No setuid</span><br><span>- No sudo</span><br><span>- No cron</span><br><span>- Binaries in /usr/bin/:</span><br><span>  mir_demo_client_flicker</span><br><span>  mir_demo_server_basic</span><br><span>  mir_demo_standalone_input_filter</span><br><span>  mir_stress</span><br><span>  mir_demo_server_shell</span><br><span>  mir_demo_client_multiwin</span><br><span>  mir_demo_client_scroll</span><br><span>  mir_demo_client_fingerpaint</span><br><span>  mir_demo_client_eglplasma</span><br><span>  mir_demo_client_basic</span><br><span>  mir_demo_client_eglflash</span><br><span>  mir_demo_client_egltriangle</span><br><span>- Good test suite</span><br><span>- Fairly messy build logs, several instances of:</span><br><span>  - warning: format '%d' expects argument of type 'int', but argument 4</span><br><span>    has type 'size_t {aka long unsigned int}'</span><br><span>- Many instances of:</span><br><span>  - Warning: no uniquely matching class member found for ...</span><br><span>  - Warning: no matching class member found for</span><br><span>- Lintian errors:</span><br><span>  - E: libmirplatform: postinst-must-call-ldconfig</span><br><span>    usr/lib/x86_64-linux-gnu/libmirplatformgraphics.so</span><br><span>  - E: mir-test-tools: arch-dependent-file-not-in-arch-specific-directory</span><br><span>    usr/bin/mir_stress</span><br><span>- Lintian warnings:</span><br><span>  - (two) W: libmirplatform: shlib-without-versioned-soname</span><br><span>    usr/lib/x86_64-linux-gnu/libmirplatformgraphics.so</span><br><span>    libmirplatformgraphics.so</span><br><span>  - (twelve) W: mir-demos: binary-without-manpage</span><br><span>    usr/bin/mir_demo_client_basic</span><br><span>  - (one) W: mir-doc: embedded-javascript-library</span><br><span>    usr/share/doc/mir-doc/html/jquery.js</span><br><span></span><br><span></span><br><span>- One instance of spawning a subprocess, examples/basic_server.cpp, just</span><br><span>  passes along a command-line argument to system(3); not itself unsafe,</span><br><span>  but might be unsafe in some potential uses of this example.</span><br><span>- Most memory management is handled via C++ safe pointers</span><br><span>- File IO is largely two types: socket parsing and device ioctls, looked safe</span><br><span>- Logging looked safe, lttng toolkit provides nice tracing tools</span><br><span>- Environment variables used: MIR_CLIENT_RPC_REPORT, MIR_SOCKET,</span><br><span>  XDG_CONFIG_HOME, HOME, XDG_CONFIG_DIRS, MIR_BYPASS,</span><br><span>  MIR_SERVER_HOST_SOCKET, ANDROID_ROOT, ANDROID_DATA</span><br><span>- Environment variable use looked safe</span><br><span>- Extensive ioctl use, possible mistake detailed below</span><br><span>- Expects to run with sufficient privileges to manipulate hardware</span><br><span>  devices, does not separate into high-privileged and low-privileged</span><br><span>  portions during execution</span><br><span>- No cryptography</span><br><span>- Extensive Unix-domain networking, Google protobufs used in some cases to</span><br><span>  provide structure-over-socket support, RPC support</span><br><span>- Does not use WebKit</span><br><span>- Does not use qtjsbackend</span><br><span></span><br><span></span><br><span>Mir is professionally-written C++11 code; while it is well-written by</span><br><span>disciplined programmers, maintenance tasks on Mir will require experts</span><br><span>knowledgeable in its design and construction. The security team will</span><br><span>largely be reliant upon "upstream" for any fixes that may be needed</span><br><span>in the future, and it is vital that we retain in-house expertise on</span><br><span>this codebase for as long as we commit to supporting it.</span><br><span></span><br><span>I'm concerned about the instructions to "chmod 777 /tmp/mir_socket" that</span><br><span>appear in the documentation, and baked into another package: a Unix domain</span><br><span>socket should not have execute permissions, and such wide-open permissions</span><br><span>makes me worried about the reliability of this socket.</span><br><span></span><br><span>(Please forgive a small aside: normally, when I see instructions on</span><br><span>web sites along the lines of "chmod 777 /path/to/something", I usually</span><br><span>ignore the rest of that person's advice on the basis that they probably</span><br><span>didn't apply scientific thinking to their problem solving. We should</span><br><span>not encourage "chmod 777" as a solution to anything, even if the only</span><br><span>change is "chmod 666".)</span><br><span></span><br><span>Setting the permissions after the socket is created and a name is bound</span><br><span>to it is a race condition, one that might end up with users accidentally</span><br><span>executing content written by another user (if non-Ubuntu kernels are used</span><br><span>that lack our symlink and hardlink protections). Perhaps fchmod(2) can be</span><br><span>used to set the permissions after the socket has been bound into the</span><br><span>filesystem. If not, perhaps the umask(2) needs to be configured before the</span><br><span>socket is bound into the filesystem.</span><br><span></span><br><span>I'd love to see a test case like this added to the test suite, ideally it</span><br><span>would run concurrently with all the other tests:</span><br><span></span><br><span>while true do ; dd if=/dev/random of=/tmp/mir_socket bs=$RANDOM count=1</span><br><span>; done</span><br><span></span><br><span>Most methods assume input validation is handled elsewhere. This is</span><br><span>okay in the early stages of a project, where the demarcation lines are</span><br><span>clear and well-known to all members of the team, but in the long run I</span><br><span>fear that lacking internal defense may become a reliability problem. Some</span><br><span>methods have encouraging assert() macros to test preconditions; I would</span><br><span>like to see more use of defensive assert()s.</span><br><span></span><br><span>I took some assorted notes while reading the source; some are duplicates</span><br><span>of prose above (but the details seemed worth keeping). Feel free to handle</span><br><span>most of these whenever it is convenient.</span><br><span></span><br><span>- Includes copy of input.h from Linux kernel sources</span><br><span>  The version included in Mir shares the Android definitions of two</span><br><span>  ioctls:</span><br><span>    #define EVIOCGSUSPENDBLOCK  _IOR('E', 0x91, int)      /* get suspend block enable */</span><br><span>    #define EVIOCSSUSPENDBLOCK  _IOW('E', 0x91, int)      /* set suspend block enable */</span><br><span>  The version in the mainline Linux kernel has different symbols and</span><br><span>  meanings for these specific ioctls:</span><br><span>    #define EVIOCGRAB               _IOW('E', 0x90, int) /* Grab/Release device */</span><br><span>    #define EVIOCREVOKE             _IOW('E', 0x91, int) /* Revoke device access */</span><br><span></span><br><span>  This is used in</span><br><span>  3rd_party/android-input/android/frameworks/base/services/input/EventHub.cpp</span><br><span></span><br><span>- EventHub.cpp still uses usleep(2), which was removed from POSIX in 2008.</span><br><span>  usleep(2) may fail around clock skews; nanosleep(2) uses the MONOTONIC</span><br><span>  clock and thus won't fail around clock skews.</span><br><span></span><br><span>- progressbar.c still uses usleep(2)</span><br><span>- progressbar.c uses unsafe routines in signal handlers, assume it's a</span><br><span>  toy, no further investigation :)</span><br><span></span><br><span>- ./3rd_party/android-deps/std/properties.h property_get() uses</span><br><span>  default_value if it is given, regardless of value. No length checks are</span><br><span>  performed, and the handful of callers in the source base all give a</span><br><span>  value parameter that could not be overwritten if default_value weren't</span><br><span>  NULL. It's not broken within this package, but it is also not pretty.</span><br><span></span><br><span>- Missing required O_RDONLY, O_WRONLY, O_RDWR in:</span><br><span>  ./tests/integration-tests/test_swapinterval.cpp</span><br><span>  ./tests/unit-tests/frontend/test_protobuf_sends_fds.cpp</span><br><span>  ./tests/unit-tests/client/test_client_mir_surface.cpp</span><br><span>  ./tests/unit-tests/client/input/test_android_input_receiver_thread.cpp</span><br><span>  ./tests/acceptance-tests/test_server_shutdown.cpp</span><br><span></span><br><span>- tests/mir-stress/src/threading.cpp run_mir_test() double-counts some</span><br><span>  tests, if (!p->create_surface()) is true, both false and true are added</span><br><span></span><br><span>- src/server/frontend/published_socket_connector.cpp</span><br><span>  mf::BasicConnector::client_socket_fd() creates a socketpair for</span><br><span>  communication between clients and Mir, but I don't see the corresponding</span><br><span>  bind(2) to give it a name in the filesystem, nor permissions setting,</span><br><span>  nor options to use abstract sockets (@foo in netstat output..)</span><br><span></span><br><span>- ./src/client/rpc/mir_socket_rpc_channel.cpp send_message() uses manual</span><br><span>  bit-fiddling rather than ntohs() and htons(), this might restrict client</span><br><span>  and server to running on same endianness architecture, may complicate</span><br><span>  emulator construction with qemu.</span><br><span></span><br><span>- Other methods use manual bit-fiddling for socket communications.</span><br><span></span><br><span></span><br><span>SUMMARY</span><br><span>=======</span><br><span></span><br><span>Please change "chmod 777" to "chmod 666" soon. I don't want "chmod 777" to</span><br><span>be seen as reasonable advice. :)</span><br><span></span><br><span>Please investigate better approaches to change the permissions on the</span><br><span>bound socket than chmod(2). Suggested replacements are fchmod(2) and</span><br><span>then umask(2). Since the socket is created in this package, I'd recommend</span><br><span>keeping permissions management of the socket in this package, rather than</span><br><span>in unity-system-compositor.</span><br><span></span><br><span>Please investigate lintian warnings and C++ compiler warnings.</span><br><span></span><br><span>None of the above blocks including Mir into Ubuntu Saucy.</span><br><span></span><br><span>Security team ACK for including Mir in main.</span><br><span></span><br><span>Thanks</span><br><span></span><br><span></span><br><span>** Changed in: mir (Ubuntu)</span><br><span>     Assignee: Seth Arnold (seth-arnold) => (unassigned)</span><br><span></span><br><span>-- </span><br><span>You received this bug notification because you are a member of Xubuntu</span><br><span>Bugs Team, which is subscribed to the bug report.</span><br><span><a href="https://bugs.launchpad.net/bugs/1203207">https://bugs.launchpad.net/bugs/1203207</a></span><br><span></span><br><span>Title:</span><br><span>  [MIR] mir</span><br><span></span><br><span>Status in “mir” package in Ubuntu:</span><br><span>  Triaged</span><br><span></span><br><span>Bug description:</span><br><span>  Availability: lp:mir, ppa:mir-team/system-compositor-testing</span><br><span>  Rationale: Required for Unity System Compositor (MIR bug 1203588)</span><br><span>  Security: No known security issues</span><br><span>  Quality assurance: no major bugs, one open for consideration of MIR - bug 1203070</span><br><span>  UI standards: N/A</span><br><span>  Dependencies: All in main except for libglm-dev (MIR bug 1176083), libgoogle-glog-dev (MIR bug 1151844), liblttng-ust-dev (MIR bug 1203589)</span><br><span>  Background:</span><br><span></span><br><span>  Mir is the new display server planned for introduction into 13.10</span><br><span>  unity-system-compositor is a component needed for the xmir configuration to work and leverage Mir for 13.10</span><br><span></span><br><span>  These components have been available and are currently being tested as part of the ppa:mir-team/system-compositor-testing</span><br><span>  there are no major bugs and its introduction is expected not to interfere with saucy.</span><br><span>  the XMir functionality being introduced will allow the X to continue in standalone mode if there is a failure.</span><br><span></span><br></div></blockquote></body></html>