Skip to content

CrowdStrike Channel File 291

At 04:09 UTC on Friday 19 July 2024, CrowdStrike pushed a routine content update to its Falcon sensor, the endpoint security agent that runs inside the Windows kernel. Windows hosts that received it crashed, and crashed again on reboot. CrowdStrike reverted the update at 05:27 UTC, but the machines that had it stayed down until someone fixed each one, often by hand. Microsoft estimated that the update "affected 8.5 million Windows devices". Airlines, hospitals, banks and broadcasters went offline.

CrowdStrike's root cause analysis traces it to a count: a template that defined 21 input fields, fed by code that supplied 20.

This page is a literate Pia file, docs/cases/crowdstrike.pia.md. The pia blocks are the fixed program, which the test suite proves, and the other code blocks are the broken versions, each checked to fail exactly as shown.

The bug

The sensor's detection logic is partly data. Rapid Response Content, delivered in channel files, holds Template Instances: lists of matching criteria, one per input field, that the sensor's Content Interpreter checks against live system activity. Each instance belongs to a Template Type compiled into the sensor, which says how many fields there are.

In February 2024, sensor 7.11 added a Template Type for Windows interprocess communication (IPC), whose instances arrive in Channel File 291. From the RCA:

The new IPC Template Type defined 21 input parameter fields, but the integration code that invoked the Content Interpreter with Channel File 291's Template Instances supplied only 20 input values to match against.

For five months nothing went wrong, because every instance used a wildcard for the 21st field, and a wildcard matches without reading its input. The tests did too: "a regex wildcard matching criterion in the 21st field for all Template Instances". The Content Validator, which checks new content before it ships, "based its assessment on the expectation that the IPC Template Type would be provided with 21 inputs." Then, on 19 July, one new instance "introduced a non-wildcard matching criterion for the 21st input parameter", and:

The Content Interpreter expected only 20 values. Therefore, the attempt to access the 21st value produced an out-of-bounds memory read beyond the end of the input data array and resulted in a system crash.

In a kernel driver, an out-of-bounds read is a blue screen.

The same code in Pia

Here is the interpreter's core, reduced to integers. An instance is two slices of the same length, one entry per field: wild.[i] says whether field i is a wildcard, and want.[i] is the value it must equal otherwise. inputs holds the values the sensor supplies. The loop checks every field, and reads an input only for a field that is not a wildcard, just as the real interpreter did:

let matches (wild : [bool]) (want : [u32]) (inputs : [u32]) : bool
  requires len want = len wild
=
  let ok : mutable bool = true in
  for i in 0..len wild do
    if wild.[i] then () else if inputs.[i] <> want.[i] then ok <- false else ()
  done;
  ok

piac will not compile it:

$ piac --verify interpreter.pia
interpreter.pia:6:8: proved: the index is within bounds [smt]
interpreter.pia:6:33: failed: the index is within bounds
  counterexample: len wild = 9223372036854775936, len want = 9223372036854775936, len inputs = 0, index = 9223372036854775934, length = 0
interpreter.pia:6:47: proved: the index is within bounds [smt]
2 proved, 1 failed, 0 skipped

The read of inputs.[i] fails, and the counterexample has fewer inputs than fields (here none at all). The reads of wild and want prove, because the precondition ties their lengths together. This is the point testing could not reach: the read happens only when the criterion is not a wildcard, and every test used a wildcard there. The verifier does not sample criteria; it proves the read is safe for all of them, or shows one where it is not.

The count belongs in the contract

The RCA's first finding is that "the number of fields in the IPC Template Type was not validated at sensor compile time". In Pia, the place to say how many inputs the interpreter needs is its precondition. Now the interpreter proves, and the obligation moves to every caller. Here is the integration code for the IPC template, with the template's 21 fields and the sensor's 20 inputs written into the types:

let matches (wild : [bool]) (want : [u32]) (inputs : [u32]) : bool
  requires len want = len wild && len inputs = len wild
=
  let ok : mutable bool = true in
  for i in 0..len wild do
    if wild.[i] then () else if inputs.[i] <> want.[i] then ok <- false else ()
  done;
  ok

let check_ipc (wild : [bool; 21]) (want : [u32; 21]) (inputs : [u32; 20]) : bool =
  matches wild want inputs
$ piac --verify integration.pia
...
integration.pia:11:3: failed: the precondition of 'matches' holds
6 proved, 1 failed, 0 skipped

There is no counterexample, because none is needed: the lengths are fixed by the types, so the precondition fails whatever the inputs are. That is the bug, as a compile error in the sensor's own build, before any content was ever written for it. No channel file, wildcard or not, could then have reached the read.

The fix, proved

The rest of this page is the fixed program. The interpreter states its requirement, and its postcondition says what a match means: every field that is not a wildcard equals its input.

let matches (wild : [bool]) (want : [u32]) (inputs : [u32]) : bool
  requires len want = len wild && len inputs = len wild
  ensures result ==> forall (k in 0..len wild). wild.[k] || inputs.[k] = want.[k]
=
  let ok : mutable bool = true in
  for i in 0..len wild
    invariant ok ==> forall (k in 0..i). wild.[k] || inputs.[k] = want.[k]
  do
    if wild.[i] then () else if inputs.[i] <> want.[i] then ok <- false else ()
  done;
  ok

The integration code supplies all 21 inputs, which is CrowdStrike's own fix: "The sensor code defining the IPC Template Type was updated to provide the correct number of inputs (21)."

let check_ipc (wild : [bool; 21]) (want : [u32; 21]) (inputs : [u32; 21]) : bool =
  matches wild want inputs

Every goal on this page is proved:

$ piac --verify crowdstrike.pia.md
...
crowdstrike.pia.md:139:3: proved: the postcondition holds [smt]
...
crowdstrike.pia.md:156:3: proved: the precondition of 'matches' holds [smt]
10 proved, 0 failed, 0 skipped

CrowdStrike's other fix was a runtime bounds check in the interpreter, added on 25 July. In Pia that check is unnecessary, so the compiled code has none: the proof that every read is in bounds is the check, and it ran once, at compile time.

What Pia needs for the rest

The real interpreter matches strings against regular expressions, and the template's field count comes from a definitions file rather than the type of an array. Pia's verifier handles neither yet. The count can still be checked at compile time once modules export interfaces with contracts (M8): the Template Type would be an exported symbol whose field count is a constant, and the sensor would be proved against it.

Sources