distcheck: never make part of $(distdir) world-writable
authorStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 6 Jul 2012 20:43:04 +0000 (22:43 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 9 Jul 2012 14:50:58 +0000 (16:50 +0200)
commitbab7065f75bb9680df8c782da06a8312e5fa95a6
treee89b71adae855747fcb56db6d3cf42b250aa46af
parentfc21a888343751b9fbd2bc35fe1ffc96f4f310f2
distcheck: never make part of $(distdir) world-writable

This fixes a locally-exploitable security vulnerability (CVE-2012-3386).

In the 'distcheck' rule, we used to make the just-extracted (from
the distribution tarball) $(distdir) directory and all its files and
subdirectories read-only; then, in order to create the '_inst' and
'_build' subdirectories in there (used by the rest of the recipe) we
made the top-level $(distdir) *world-writable* for an instant (the
time to create those two directories) before making it read-only
again.

Making that directory world-writable (albeit only briefly) introduced a
locally exploitable race condition for those who run "make distcheck" with
a non-restrictive umask (e.g., 022) in a directory that is accessible by
others.  A successful exploit would result in arbitrary code execution
with the privileges of the user running "make distcheck" -- game over.
Jim Meyering wrote a proof-of-concept script showing that such exploit is
easily implemented.

This issue is similar to the CVE-2009-4029 vulnerability:
<http://lists.gnu.org/archive/html/automake/2009-12/msg00012.html>

* lib/am/distdir.am (distcheck): Don't make $(distdir) world-writable,
not even for an instant; make it user-writable instead, which is enough.

Helped-By: Jim Meyering <jim@meyering.net>
Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
NEWS
lib/am/distdir.am