Section 8.27

Version high-water mark

Definition

A version high-water mark is a number kept in persistent storage that records the highest version a device has committed to so far, meaning adopted as its new baseline, and that never decreases. The device compares the version of every candidate, such as a firmware image or a numbered command, with the mark and refuses a candidate that is older. The mark is stored apart from the version currently running, because the running version may legitimately go down after a failed update while the mark must not.

The idea

A device that refuses old software needs to remember what “old” means. The version it is running is the wrong reference. After a new version fails its trial, the device goes back to the previous one, and the running version falls; if old meant “older than what runs”, the meaning would fall with it. The device needs a separate record that only moves up.

The same need arises for messages. A receiver that must refuse a replay attack §1.26, in which a recorded genuine message is sent again, could store every nonce §5.18, a value meant to be used only once, that it has ever accepted, and refuse any nonce it has seen. That list grows without limit. If instead every message carries a number larger than the one before, the receiver needs to store one number: the highest it has accepted. Every earlier message carries a number no larger than that, so all of them are refused at once.

The name comes from the mark that a flood leaves on a wall at the highest level the water reached. The water falls again, but the mark stays and shows how high the water once rose. The picture stops at two points. A visitor cannot wipe off a flood mark, whereas a number in flash memory §6.6 can be rewritten by anyone who can write that flash. And the water decides its own level, whereas the device must decide which event counts as reaching a version: receiving it, installing it or confirming that it works.

How it works

The device keeps one number HH, the mark, in persistent storage. At manufacture HH is set to the version installed at the factory, or to 0. Each candidate carries a version vv inside the bytes that its digital signature §5.14 or message authentication code §5.7 (MAC) covers, so an attacker cannot change vv without the check failing.

Acceptance rules. Four rules are in use, and they give different guarantees.

Advancing the mark. When a candidate is committed, the device sets HH to the larger of HH and vv; under the exact-successor rule this is simply H+1H + 1. The order of this write relative to the candidate’s own effect decides what a crash does.

Storing the mark. A power failure can leave a single location in flash memory half-written, which is called a torn write §8.19. A common layout keeps two copies, each with a sequence number and a checksum §4.32; the writer overwrites the older copy, and the reader takes the newer copy whose checksum is correct. If neither copy is readable, the device must fail closed §1.13: refuse every candidate and wait for recovery, and never fall back to a default of 0, which would accept every version. Flash memory tolerates only a limited number of erase cycles, so a mark that changes with every message is written as new records appended to a region, not by erasing one location each time.

Protecting the mark. An attacker who can rewrite the storage can lower HH. Hardware that cannot count down, such as one-time programmable (OTP) fuses or a separate security chip, can hold the mark itself, or a reference copy against which the stored mark is checked at every start. The Monotonic counter §8.28 entry describes these options and what each resists. Systems use their own names for the mark: Android Verified Boot keeps a stored rollback index, and MCUboot, an open-source bootloader §6.30 for microcontrollers §6.1, compares a security counter carried in each signed image with a value kept in protected storage.

Worked example

Refusing an old image. The mark starts at H=7H = 7. Version 9 arrives with a valid signature and is committed, so HH becomes the larger of 7 and 9, which is 9. Later, version 8 arrives, also with a valid signature. Under the at-least-as-new rule it is refused, because 8<98 < 9. The signature on version 8 is genuine; only the mark stops it.

Resetting the mark. An attacker saved a copy of the whole flash memory while HH was 7 and now writes that copy back. The device reads H=7H = 7, and version 8 now passes, because 8≥78 \ge 7. Nothing about the image or its signature changed; only the stored mark did. The restored bytes are exactly bytes the device once wrote itself, so no check of their format or checksum can detect the change.

Corrupting the mark. Power fails while the only copy of HH is being rewritten, and its checksum no longer matches. Code that treats an unreadable mark as 0 then accepts version 1, the oldest of all. Code that fails closed accepts nothing until the mark is restored from a protected copy.

Comparing the rules. Let H=41H = 41, and let candidates numbered 41, 42 and 45 each be checked against it:

candidate v≥Hv \ge H v>Hv > H v=H+1v = H + 1
41 accepted refused refused
42 accepted accepted accepted
45 accepted accepted refused

Number 41 was already committed, so it is a replay, and only the at-least-as-new rule lets it through. Number 45 skips 42, 43 and 44, which only the exact-successor rule refuses.

Running out of numbers. Let HH be a 32-bit unsigned number, so its largest value is 232−1=4,294,967,2952^{32} - 1 = 4{,}294{,}967{,}295. Under the strictly newer rule, one authorized candidate with v=232−1v = 2^{32} - 1 sets HH to that value, and from then on no 32-bit vv is larger, so the device can never accept anything again. Under the exact-successor rule the mark rises by one per accepted candidate. At one candidate per second, reaching the top takes about 2322^{32} seconds, and 4,294,967,296/31,557,600≈1364{,}294{,}967{,}296 / 31{,}557{,}600 \approx 136 years, where 31,557,60031{,}557{,}600 is the number of seconds in a year of 365.25 days.

At the top, a careless check is dangerous. In unsigned modular arithmetic §4.16 on 32 bits, H+1H + 1 at H=232−1H = 2^{32} - 1 wraps around to 0, so a check written as “accept if v=H+1v = H + 1” accepts v=0v = 0, and every old candidate becomes acceptable again. Correct code first tests whether HH has reached its largest value and refuses if so, or computes H+1H + 1 in a wider type.

Stated precisely

Let the mark HH be an unsigned number of ww bits, so 0≤H≤2w−10 \le H \le 2^{w} - 1, and let vv be the version carried inside the authenticated bytes of a candidate. The three numeric rules accept a candidate when, respectively, v≥H,v>H,H<2w−1 and v=H+1.v \ge H, \qquad v > H, \qquad H < 2^{w} - 1 \text{ and } v = H + 1. When a candidate is committed, the new mark is H′=max(H,v)H' = \max(H, v), the larger of the old mark and the candidate’s version.

As arithmetic, the update never lowers the mark: max(H,v)≥H\max(H, v) \ge H for every vv. Under the strictly newer and exact-successor rules, no candidate whose version has ever been committed is accepted again, because each such version is at most the current HH. The stored value follows this arithmetic only under five assumptions.

  1. The version vv is authenticated together with the candidate.

  2. The commit is the only operation that writes HH.

  3. The write of HH is atomic with the commit of the candidate’s effect, or the effect is idempotent.

  4. Nothing in the threat model §1.2, the written account of what an attacker and the environment can do, can restore or reprogram HH to an older value.

  5. The comparison and the computation of H+1H + 1 do not wrap around.

Limits and common mistakes

A checksum or a cyclic redundancy check (CRC) detects accidental damage to the stored mark, not its replacement by an older record that has a correct checksum. A message authentication code computed with a key held only by the device detects a forged record, but not an older genuine record written back. Only a reference that itself cannot be set back, as described in the Monotonic counter entry, detects that.

The mark is not authentication §1.6. It refuses old candidates and does nothing against a new one that an attacker made; that is the job of the signature check, which must cover the version number.

Each kind of object that must not go backwards, such as firmware, configuration and key sets, needs its own mark. One shared mark lets a high version of one kind block every other kind. Two senders that number their messages independently also need separate marks.

Version formats need an exact comparison rule. Compared character by character as text, the version string 1.10 sorts before 1.9, because their third characters are 1 and 9, and 1 sorts first. Versions are compared as numbers of fixed width, or as tuples compared one component at a time from the most significant component.

If a new signing key restarts version numbering at 0, the mark refuses the new key’s first images. If the mark is reset for the new key, old images signed with the old key must be refused by key revocation §5.32 instead. A common approach compares a pair of numbers §19.3.3: the sequence number of the signing key first, then the version.

Exhaustion is a denial of service §1.28: once the mark is at its largest value, nothing more can be accepted. The exact-successor rule limits how fast the mark can be driven there; the strictly newer rule does not.

Questions answered

Can an attacker reset, corrupt, or replace the high-water state?

Yes. An attacker can reset, corrupt or replace a version high-water mark whenever the attacker can write the storage that holds it, and a location in ordinary flash memory gives no protection by itself. The high-water mark is the stored record of the highest version the device has committed to; the device refuses any candidate older than it, so lowering it reopens every old version.

The defenses match the three cases. Keep the mark, or a reference copy of it, in storage that cannot count down, such as one-time programmable (OTP) fuses or a separate security chip, and refuse to start when the stored mark is below that reference. Write the mark crash-safely, for example as two copies with sequence numbers and checksums, and fail closed when no copy is valid. Commit the mark together with the effect it records. Whatever the design, its threat model must say which of these attacks it covers: a device whose whole storage an attacker can restore cannot detect the restoration from the restored bytes alone.

Related entries: Rollback versus anti-rollback (§8.26), Monotonic counter (§8.28), Crash consistency (§8.4), Recovery key (§5.31), Replay attack (§1.26), Counter wraparound (§6.21), State transition guard (§8.34), Lexicographic version order versus componentwise order (§19.3.3), Idempotency (§8.31). Further reading: [21].