Algorithm Search⌘K

Theoremcore

Undecidability of virus detection

Also called Cohen's theorem.

No program can decide for every program whether it is a virus, by reduction from the halting problem.

Cohen (1987) defined a computer virus as a program that can infect other programs by changing them to include a possibly evolved copy of itself, and proved that no program can decide, for every program, whether it is a virus. The proof is a diagonal argument in the style of Turing's halting problem: a detector that is always right can be used to build a program that does the opposite of what the detector says about it. The same result follows by a reduction from the halting problem, and in a model where "being a virus" is a property of the function a program computes, from Rice's theorem. Adleman (1988) put the problem in the arithmetical hierarchy. The theorem says that every practical malware detector must sometimes be wrong or never answer. The page treats copying as an abstract step in a formal model and gives no working code.

Statement

Model. Programs are texts for a fixed universal machine, such as a Turing machine. A program runs on a store: a finite list of slots, each holding a program text. Running a program can read the store and can write texts into slots. All runs start from a fixed initial store σ0\sigma_0. A program pp writes nothing if no run of pp from σ0\sigma_0 writes a slot. A program pp copies itself if its run from σ0\sigma_0 eventually writes its own text pp into a slot that held another program.

Theorem 1 (Cohen). Let VV be any set of programs such that every program that copies itself is in VV and no program that writes nothing and halts is in VV. Then no total computable function DD satisfies D(p)=1  ⟺  p∈VD(p) = 1 \iff p \in V for all programs pp.

Cohen's own definition of a virus, with infection by a possibly evolved copy, satisfies both conditions, so his set of viruses is undecidable. So is the narrower set of programs that copy themselves exactly.

Theorem 2 (reduction). Let VV contain every program that copies itself and no program that writes nothing, whether it halts or not. Then the halting problem many-one reduces to VV: there is a computable map (M,w)↦pM,w(M, w) \mapsto p_{M,w} with pM,w∈Vp_{M,w} \in V if and only if MM halts on ww.

In plain words

Suppose someone claims to have a perfect checker: you give it any program, and it always answers, and it is always right about whether the program spreads copies of itself.

Then you can write a tricky program that first asks the checker about itself. If the checker says "it spreads", the tricky program stops at once and spreads nothing. If the checker says "it does not spread", the tricky program spreads a copy of itself.

Either way the checker was wrong about the tricky program. So the perfect checker cannot exist.

This does not stop useful checkers. A checker can look for known patterns, or run a program for a limited time and watch. It only means that every checker makes mistakes on some programs, or never gives an answer on some programs.

Proof

Theorem 1. Suppose a total computable DD decides VV. Let CC be the copy step: "write the text ee into the first slot of σ0\sigma_0 that holds another program". Consider the computable map ff that takes a program text ee to the program

f(e)="compute D(e); if it is 1, halt; otherwise run C with the text e, then halt."f(e) = \text{"compute } D(e)\text{; if it is } 1 \text{, halt; otherwise run } C \text{ with the text } e\text{, then halt."}

Since DD is total and computable, ff is a total computable map on program texts. By the Kleene recursion theorem, in the form that allows a program to use its own text, there is a program e∗e^* that behaves exactly as f(e∗)f(e^*) does. So e∗e^* computes D(e∗)D(e^*), and then:

  • If D(e∗)=1D(e^*) = 1, then e∗e^* halts without writing, so e∗e^* writes nothing and halts, so e∗∉Ve^* \notin V. Then D(e∗)=1D(e^*) = 1 is wrong.
  • If D(e∗)=0D(e^*) = 0, then e∗e^* writes its own text e∗e^* into a slot that held another program, so e∗e^* copies itself, so e∗∈Ve^* \in V. Then D(e∗)=0D(e^*) = 0 is wrong.

Both cases contradict the assumption that DD decides VV. So no such DD exists. □\square

This is the argument of Cohen's paper, with the self-reference made exact by the recursion theorem. Cohen writes the program in pseudocode and lets it call the detector on itself by name.

Theorem 2. Given a machine MM and an input ww, let gM,wg_{M,w} be the computable map that takes ee to the program "simulate MM on ww without touching the store; when the simulation halts, run CC with the text ee, then halt". The map (M,w,e)↦gM,w(e)(M, w, e) \mapsto g_{M,w}(e) is computable, so the recursion theorem with parameters gives a computable (M,w)↦pM,w(M, w) \mapsto p_{M,w} such that pM,wp_{M,w} behaves as gM,w(pM,w)g_{M,w}(p_{M,w}).

  • If MM halts on ww, then pM,wp_{M,w} writes its own text into a slot that held another program, so pM,wp_{M,w} copies itself and pM,w∈Vp_{M,w} \in V.
  • If MM does not halt on ww, then pM,wp_{M,w} never writes the store, so pM,w∉Vp_{M,w} \notin V.

Cohen's definition satisfies the condition on VV, because a program that never writes cannot infect anything. So pM,w∈Vp_{M,w} \in V if and only if MM halts on ww, which is the many-one reduction. Because the halting problem is undecidable, so is VV. □\square

From Rice's theorem. Suppose the store is part of the input and the output, so that each program computes a partial function from stores to stores. If the definition of a virus depends only on this function, and some program is a virus and some is not, then the set of viruses is a nontrivial semantic property, and it is undecidable by Rice's theorem. Self-copying as defined above mentions the text of the program, so it is not of this form, and the direct proofs above are needed.

Consequences

  • Every detector errs (theorem). For every total computable detector DD there is a program on which DD gives the wrong answer. Running the same argument on versions of ff that carry different unused instructions gives infinitely many such programs. A detector that is never wrong must fail to answer on some programs.
  • No perfect detector, but always a better one (theorem). Given a detector DD and the program e∗e^* that defeats it, the detector that answers correctly on e∗e^* and as DD elsewhere is again computable. So no detector is best, in the same sense as the full employment theorem for compilers.
  • Evolutions (theorem). Cohen used the same kind of argument to show that no program decides, for every pair of programs, whether one is an evolution of the other. So detection by comparison with a known virus is also undecidable once the copies may change.
  • What remains decidable (theorem). Decidable questions are those about the text or about bounded runs: whether a file contains a given string, or whether a program writes its own text within tt steps, which a simulation of tt steps answers. Practical detectors decide such questions and accept errors on the real question.

Tightness

  • Semi-decidable in the one-run model (theorem). With a fixed initial store, the set of programs that copy themselves is computably enumerable: simulate the program and accept when it writes its own text into a slot. Theorem 2 shows that the halting problem reduces to it, so it is complete for the computably enumerable sets under many-one reductions. So undecidability is the exact answer in this model: a detector can confirm every program that copies itself, but it cannot reject every program that does not.
  • Higher in the general model (theorem). Adleman (1988) defined a virus abstractly, as a total recursive function that maps each program to an infected form of it, with conditions over all inputs. He showed that the set of viruses under this definition lies at the second level of the arithmetical hierarchy, above the halting problem. In this model a detector cannot even confirm every virus.
  • Restricted programs. If programs have a finite number of states, or are known to halt within a bound, every run can be simulated, and the question is decidable. The theorem needs programs that can run without bound.

History

Cohen named and studied computer viruses in the 1980s, and his 1987 paper in Computers and Security gives the formal definition on a Turing machine model, the undecidability results, and reports of controlled experiments. Adleman gave the abstract recursion-theoretic treatment at CRYPTO 1988. Both proofs follow the diagonal argument of Turing (1936) and, for semantic properties, Rice (1953). Later work on malware detection treats the theorem as the reason why detectors must be heuristic.

References

  1. Fred Cohen, Computer viruses, theory and experiments, Computers and Security 6(1), 1987, pages 22 to 35, the definition of a virus as a program that infects other programs with a possibly evolved copy of itself, the contradiction argument that no program decides whether a program is a virus, and the same argument for the detection of evolutions
  2. Leonard M. Adleman, An abstract theory of computer viruses, Advances in Cryptology, CRYPTO 1988, LNCS 403, Springer, 1990, pages 354 to 374, the definition of viruses as total recursive functions on programs and the classification of the set of viruses in the arithmetical hierarchy
  3. Alan M. Turing, On computable numbers, with an application to the Entscheidungsproblem, Proceedings of the London Mathematical Society (2) 42, 1936, pages 230 to 265, Section 8, the diagonal argument that no machine decides whether a machine is circle-free
  4. Henry Gordon Rice, Classes of recursively enumerable sets and their decision problems, Transactions of the American Mathematical Society 74(2), 1953, pages 358 to 366, the theorem that every nontrivial class of recursively enumerable sets has an undecidable index set

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/HJMJKK/text.yaml