Home > Uncategorized > Compiler writing: The career path to World domination

Compiler writing: The career path to World domination

November 7, 2009

Compiler writing is not usually thought of as a career path that leads to becoming Ruler of the World. Perhaps this is because compiler writing is a relatively new profession and us compiler writers are still toiling in obscurity awaiting the new dawn.

What might be a workable plan for a compiler writer to become Ruler of the World? One possibility is to write a compiler for the language in which most of the World’s critical software is written (i.e., C) and for that compiler to become the one that the vendors of this critical software all use (i.e., gcc). This compiler needs to do more that just compile the source code it is feed, it also needs to generate code that creates a backdoor in important programs (e.g., the login program).

But, you say, this cannot happen with gcc because its source is available for everybody to read (and spot any backdoor generator). In his 1984 Turing acceptance lecture Ken Thompson showed how a compiler could contain a backdoor that was not visible in its source. The idea is for the compiler writer to modify a compiler to detect when it is being used to compile itself and to insert the backdoor generating code into its own executable. This modified compiler is then used to compile itself and the resulting executable made the default compiler; the backdoor modifications are then removed from the compiler source, they are no longer needed because the previously compiled compiler will spot when it is being used to compile its own source and generate the code necessary to propagate the backdoor code into the executable it creates.

How would the world counter the appearance of such a modified gcc? Obviously critical programs would need to be recompiled by a version of gcc that did not contain the backdoor. Today there are several companies and many amateur groups that distribute their own Linux distributions which they build from source. It should be relatively easy to obtain a usable executable of gcc from 10 years ago; remember what is needed is a version capable of compiling the latest gcc sources.

The ideal time to create a backdoor’ed version of gcc is while its development was under the control of one person, so early in the development history that all versions available anywhere are very likely to be derived from it. How can we prove that the original author of gcc did not do just this?

It could be argued that the very substantial changes to the gcc sources (most of the source has probably been rewritten several times) mean that the coding patterns searched for by the executable to detect that it is compiling itself have long gone and at some point the backdoor failed to propagate itself to the next executable.

Compilers other than gcc might also include backdoors that propagate themselves. However, the method of propagation is likely to be different. Compiling the gcc sources with a non-gcc compiler creates an executable that should exhibit the same behavior as a gcc-compiled executable. Differences in the behavior of these independently built executables is a cause for concern (one difference might be caused by differences in the conversion of floating-point literals, a recent PhD thesis provides more detail).

The problem with compiling the gcc sources is that they make use of language extensions that few, if any, other compilers support. I know IBM added modified one of their C compilers to support those gcc extensions needed to compile the Linux kernel, but I don’t know if this compiler is capable of compiling the gcc sources. The LLVM project intended to support many gcc extensions but I don’t know if they aim to be able to compile the gcc sources.

Another option is to compare the assembler generated when gcc compiles itself against the corresponding source code. A very expensive task for source code measured in hundreds of thousands of lines. Adding the necessary language extension support to another compiler would probably be cheaper and also create a tool that could be used to check future releases of gcc.

  1. November 17, 2009 21:27 | #1

    This thesis is relevant: Fully countering \Trusting Trust\ by diverse double-compiling.

    http://www.dwheeler.com/blog/2009/11/02/#trusting-trust-dissertation

  2. November 18, 2009 02:23 | #2

    David Wheeler’s thesis blog post is linked to through “a recent PhD thesis”. I was a bit disappointed that this thesis wasted so much space on mathematical proofs of little practical relevance and less space on realistic verification issues.

    I don’t think it is realistic to assume the existence of a trusted compiler. We should assume that all compilers contain backdoors.

    Analysing in more detail how actual implementations might function would provide data that could be used to estimate the probability that two independently developed compilers would use the same backdoor techniques and thus make it lot less likely that one could be used to verify the other (making the worse case scenario that all compilers contain backdoors). It could also provide useful insight into how source code evolution impacts backdoor propagation success rates.

  3. yugr
    December 25, 2009 21:38 | #3

    Well, CIA or NSA (or their equivalents in other countries) may invest a few man-years to build a very basic compiler just for a purpose of gcc validation.

  1. No trackbacks yet.
Comments are closed.