- First, compile
compiler-clean.cnormally (cc compiler-clean.c -o compiler-clean) ./compiler-clean input_file out_filetakes in theinput_file, "compiles it", and gives the binaryout_file(actually just passes it togcc)- This is now our main compiler and is innocent.
- Now, compile
auth.c(./compiler-clean auth.c -o auth) ./authonly authorizes if you run as root- Compile
compiler-trojan.cusing the compiler (./compiler-clean compiler-trojan.c compiler-trojan) - Now if we use it to compile
auth.c(./compiler-trojan auth.c auth), it will give us access even if we are not root.
Now,
- Compile
compiler-clean.cusing the malicious compiler (compiler-trojan compiler-clean.c compiler-clean) - We can throw away
compiler-trojan.candcompiler-trojanand pretend like nothing ever happened. - Now, if we use our new
compiler-clean(which is actually not-so-clean) to compileauth.c(compiler-clean auth.c -o auth), we see that it gives us access even if we are not root.
Moral: We can't trust our compiler.