Running the “Reflections on Trusting Trust” Compiler
Russ Cox · 2023年10月26日
AI 摘要 AI 生成,可能有误
为纪念肯·汤普森1983年图灵奖演讲《对信任的信任的反思》(Reflections on Trusting Trust)发表40周年,本文回顾了经典的三阶段编译器后门攻击:编写一个自我复制的quine程序,展示编译器如何“学习”仅保存于其二进制文件中的细节,并将两者结合以隐形地感染登录程序。随后,作者获得了汤普森真正的原始后门代码(nih.a)——这段代码此前从未被索取或发布过——并在V6 Unix模拟器中运行了它。整个演示展示了该代码如何修改C编译器,从而在登录程序中植入后门并将自身复制到新编译的编译器中,最终同时构建出一个“邪恶”编译器和一个干净的编译器。
Supply chain security is a hot topic today, but it is a very old problem.
In October 1983, 40 years ago this week,
Ken Thompson chose supply chain security as the topic for his Turing award lecture,
although the specific term wasn’t used back then.
(The field of computer science was still young and small enough that the ACM conference where Ken spoke was
the “Annual Conference on Computers.”)
Ken’s lecture was later published in Communications of the ACM
under the title “Reflections on Trusting Trust.”
It is a classic paper, and a short one (3 pages);
if you haven’t read it yet, you should. This post will still be here when you get back.
In the lecture, Ken explains in three steps how to modify a C compiler binary
to insert a backdoor when compiling the “login” program,
leaving no trace in the source code.
In this post, we will run the backdoored compiler using Ken’s actual code.
But first, a brief summary of the important parts of the lecture.
AI 摘要This post proves the correctness of uscale, a fast unrounded scaling algorithm based on a 64×128-bit multiplication and floating-point approximation, which underlies the author's floating-point printing and parsing algorithms (FixedWidth, Short, and Parse). The proof proceeds through a series of lemmas handling exact results, small positive and negative powers, and finally the large-power cases, which cannot be exhaustively tested directly. For those large-power cases, the author uses the Ivy calculator—an APL-inspired language with arbitrary-precision rationals and right-to-left precedence—to implement a two-step approach, loosely following work by Vern Paxson and Tim Peters, that solves a 'modular search' problem to find the first satisfying value and a 'modular minimum' problem to verify all relevant inputs.
AI 摘要This article presents fast floating-point printing and parsing algorithms built on a new primitive called fast unrounded scaling, which approximates scaling by powers of ten, often in a single 64-bit multiplication. These simple algorithms reportedly outperform all prior known methods, including Dragon4, Grisu3, Ryū, Schubfach, and Dragonbox, and the author plans to include a Go implementation in Go 1.27. The post walks through the necessary concepts (fixed-point and floating-point numbers, unrounded numbers) and outlines implementations for fixed-width and shortest-width printing as well as decimal parsing.
AI 摘要This article is a reply to Donald Knuth's 1989 paper on proving the correctness of a program that converts 16-bit fixed-point binary fractions to their shortest accurate decimal representations, written in honor of Knuth's 88th birthday. The author presents what they argue is a better proof of Knuth's program P2 by starting with a simpler program that has a trivial direct correctness proof—implemented in the APL-like Ivy language—and then transforming it into P2 step by step, proving each transformation correct. The post also explores alternative solutions and concludes with reflections on how language and notation shape programs and proofs.
AI 摘要The article introduces the 'Floating Point Formatting' blog series, which began in 2011 and continued with new posts in 2026. It lists four posts covering topics such as floating-point to decimal conversion, a proof inspired by Knuth's fixed-point printer, simple and fast floating-point printing and parsing, and a proof of fast unrounded scaling verified with Ivy.
AI 摘要The article describes 'differential coverage', a debugging technique that compares the code coverage profile of a failing test with those of passing tests to isolate code blocks unique to the failing case. Demonstrating in Go, the author diffs two coverage profiles and views the result with go tool cover -html, successfully narrowing an injected bug down to 10 lines among over 15,000. While not foolproof (e.g., data-dependent bugs or insensitive tests can evade it), the technique is cheap to compute and can save considerable debugging time.