Definition
A reduced product is a combination of two abstract domains §3.6 in abstract interpretation §3.4, the method that proves facts about a program by computing with descriptions of sets of values instead of with the values. An abstract domain is one kind of description, such as an interval or a pattern of known bits. The product describes a set by one description from each domain and means the values that satisfy both. The reduction passes facts between the two descriptions, tightening each without excluding any value that both allow.
The idea
A verifier must decide whether a 4-byte read at offset of a 16-byte buffer stays inside the buffer. The read covers bytes to , so it is safe when , that is when . The program first clears the two lowest bits of an unknown value with a bitwise AND, which makes a multiple of 4, and then rejects any greater than 15.
Two analyses run side by side. A known-bits analysis tracks, for each bit, whether it is known to be 0, known to be 1, or unknown; from the AND it knows that the two lowest bits of are 0 and nothing about the others. Interval analysis §3.9 tracks a lowest and a highest possible value; from the comparison it knows that . Alone, each fails. The interval allows , and . The bit pattern allows every multiple of 4 that fits in the register, including huge ones.
Together they settle the question: the values that both allow are 0, 4, 8 and 12, and all of them pass. Running the analyses side by side is not enough, because each keeps only its own kind of fact. The reduced product adds the step that tells each analysis what the other’s facts imply, so that the interval tightens to .
How it works
The parts, for values read as unsigned numbers of a fixed width:
Interval component : the value lies between and , both included.
Known-bits component : where a bit of the mask is 1, that bit of the value is unknown; where it is 0, that bit is known and equals the same bit of . The bits of at unknown positions are 0. The verifier for eBPF §2.1 (extended Berkeley Packet Filter) programs in the Linux kernel calls such a pair a tnum §3.10, keeps one next to signed and unsigned intervals for each register, and exchanges facts among them after each instruction: a partial reduction of the kind described here.
Meaning of a pair of components: the set of values that satisfy both.
The reduction runs after each operation of the analysis, or before a safety check:
Bits to interval. The smallest value the bits allow is , with every unknown bit 0. The largest is , with every unknown bit 1; adding works because and have no 1 bits in common. Raise to if it is smaller, and lower to if it is larger.
Interval to bits. All values from to share the leading bits on which and agree, down to the first bit where they differ. Mark those leading bits as known.
Empty check. If , or a known bit contradicts the interval, no value satisfies both components. The program point is then unreachable, and the analysis records the empty description, called bottom.
Repeat steps 1 and 2 until neither component changes. Each step removes only values that one component already excludes, so the meaning of the pair never changes.
These simple rules do not always find the tightest interval. With the interval and the two lowest bits known to be 0, step 1 leaves , although the smallest allowed value is 4. A stronger rule for known low zero bits rounds up and down to the nearest multiples of the matching power of two. Both rules are sound; the stronger one is more precise.
Worked example
To keep the bit patterns short, the example uses 8-bit unsigned values; a verifier for 64-bit registers applies the same rules to 64 bits. In a bit pattern, ? marks an unknown bit. The starting facts are the interval and the pattern ??????00, that is and .
Round 1, step 1. The bits allow at least and at most . The interval becomes : no change.
Round 1, step 2. In binary, and . They agree on the four leading bits, all 0, and first differ at the fifth. So the four leading bits are known to be 0, and the pattern becomes 0000??00: .
Round 2, step 1. Now , so drops to and the interval becomes . Round 2, step 2. and agree on the same four leading bits, so nothing new is learned. Round 3 changes nothing, and the reduction stops.
Result. The interval with the pattern 0000??00 allows exactly 0, 4, 8 and 12, four values. The interval alone allowed 16 values, and the pattern ??????00 alone allowed values on 8 bits. The bounds check now passes, because .
Alignment §4.22. Suppose the buffer starts at address 0x2000, which is 8192, a multiple of 4. The read address has its two lowest bits 0 for every allowed , because both terms have; the largest, , is a multiple of 4. So the 4-byte read is aligned at every allowed offset. The alignment fact comes from the bits, and the bounds fact from the interval tightened by the bits.
Stated precisely
Let and be the concretization §19.2.7 functions of the two domains: is the set of concrete values that the description allows, and likewise for . The product domain consists of pairs with the meaning . A reduction is a function on pairs such that, for every pair , , so no value is lost or added, and each component of allows no more values than the matching component of .
The best reduction maps a pair to the most precise pair with the same meaning: with , where , the abstraction function of domain , gives the most precise description of the set in that domain. Patrick and Radhia Cousot defined the reduced product in 1979 [382] as the product domain in which pairs with the same meaning are treated as one, which is what applying achieves.
Low zero bits and intervals. For unsigned -bit values, if the lowest bits are known to be 0, every allowed value is a multiple of , and the interval can be replaced by where rounds up and rounds it down to a whole number. For and this gives ; for it gives . If a base address is a multiple of , then is a multiple of for every allowed , even if the addition wraps around modulo , because is itself a multiple of .
Soundness §3.7. A reduction step is sound when every value allowed by the pair before the step is still allowed after it. The steps above are sound because each removes only values that one component already excludes.
Limits and common mistakes
Reduction changes precision, not meaning. A rule that removes a value that both components allow is unsound, and a verifier that uses it can accept a program that reads outside its buffer.
Both components must describe the same bit width and the same reading of the bits. In two’s complement, the signed value has the 64-bit pattern 0xfffffffffffffffc, which read as unsigned is . Rules written for unsigned intervals must not be applied to signed ones without conversion; the eBPF verifier §3.3, for example, keeps signed and unsigned intervals separately and reduces among all of them.
A reduced product of domains that each describe one variable still describes each variable separately. It cannot record a relation such as between two variables; that needs a relational abstract domain §15.12.
Reduction costs time and can interfere with termination. An implementation can bound the number of rounds, or exchange facts only once. Reducing right after a widening operator §3.23, the step that forces a loop analysis to finish by giving up precision, can undo the widening and keep the analysis from finishing, so analyses avoid reducing at that point or use a widening designed for the product.
The best reduction can be expensive, or impossible to compute, for rich domains. Practical tools use partial reductions such as the simple rules above.
Questions answered
How can known low zero bits refine an interval’s alignment facts?
Known low zero bits refine an interval by ruling out every value in it that is not a multiple of the matching power of two, so the interval’s ends move inward to the nearest such multiples, and the bits themselves prove alignment. If the lowest bits of an unsigned value are known to be 0, then is a multiple of . An interval for can then be tightened to , where the brackets round up and down to whole numbers, without losing any possible value. With in and its two lowest bits 0, the interval becomes , and the possible values are 0, 4, 8 and 12.
The refinement matters in two ways. The tighter upper end can prove a bounds check that the interval alone fails: a 4-byte read at offset of a 16-byte buffer is safe because , while would run past the end. The bit fact, not the interval, carries the alignment: added to a base address that is a multiple of 4, every possible gives a multiple of 4, so the read is aligned. Combining an interval with a known-bits description, together with a step that passes such consequences between them, is a reduced product of the two abstract domains. The refinement is sound only if it removes no value that both descriptions allow, and only if both describe the same bit width and the same unsigned reading of the bits.
Related entries: Abstract interpretation (§3.4), Interval analysis (§3.9), Bitmask abstract value (tnum) (§3.10), Widening and narrowing (§3.23), Alignment (§4.22), Abstract domain (§3.6), Relational abstract domain (§15.12), Abstraction, concretization, and Galois connection (§19.2.7). Further reading: [2, 68, 69, 382].