TExcelTAD

Crash Deduplication and Exploitability Classes

A weekend of fuzzing can leave thousands of crash files. Almost all of them are the same few bugs reached by different inputs. Before anyone fixes anything, the crashes have to be grouped into unique bugs and each group rated, so the scarce human time goes to the most serious one first. Both steps are mostly automatic, both are heuristics, and both have failure modes a researcher must know.

Deduplication by stack hash

A sanitizer report contains a stack trace: the function where the bad access happened (frame #0 or #1, after the libc interceptor), its caller, and so on up to main. Two crashes with the same bug kind and the same top frames are very likely the same bug. So the usual bucketing key is:

text
key = sanitizer kind | access (READ/WRITE) | top N frames of your own code

hashed into a short identifier. ClusterFuzz calls the top three frames the crash state. Function names are better than line numbers in the key, because lines shift with every unrelated edit and the same bug would get a new bucket after each commit.

Choosing N is a trade-off:

N Risk
too small (1) two different bugs in one helper, such as memcpy called from two parsers, end up in one bucket: one of them is never looked at
too large (8+) the same bug reached from many callers splits into many buckets: duplicated work, inflated numbers
3 (common default) good balance for most code; tune per project

Exploitability as a classification

The second question is how bad each bucket is. The answer here is a classification from the report, not an attempt to exploit anything. Tools of this kind include Microsoft's !exploitable extension for WinDbg, CERT's exploitable plugin for gdb and the Rust tool CASR: they read the crash type, access kind and context and assign a class. A simple version of their rules:

Report Class Reasoning
out-of-bounds write (stack or heap), use-after-free, double free likely exploitable an attacker may control what is written where; treat as code execution until shown otherwise
out-of-bounds read possible information leak may disclose memory (keys, pointers that defeat ASLR); Heartbleed was a read
null or near-null dereference usually denial of service still a bug; becomes worse if the offset is attacker-controlled
assertion, timeout, out-of-memory denial of service matters for servers and shared services

The classes are a queue order, not a verdict. A read can be critical; a "likely exploitable" write in dead code can be minor. The final rating uses reachability and impact, and in an advisory, CVSS (Writing an Advisory).

Triage of six crashes

The session plays the role of a fuzzing campaign's output: six crash inputs for the toy parser tlv.c (both seeded bugs still in it), saved in crashes/. It runs each one under ASan, then a Python script extracts kind, access and the top three frames, buckets them by a short SHA-1 of that key and applies the classification rules. It runs in your sandbox:

bash · try it yourself
cat > tlv.c <<'SRC'
#include <stddef.h>
#include <stdint.h>
#include <string.h>

/* Toy format "TLV1": magic, then records of type (1 byte), length (1 byte), value. */
static int rec_name(const uint8_t *v, size_t len) {
    char name[16];
    memcpy(name, v, len);                 /* seeded bug 1: len is never checked against 16 */
    return name[0];
}

static int rec_sum(const uint8_t *v, size_t len) {
    unsigned sum = 0;
    for (size_t i = 0; i <= len; i++)     /* seeded bug 2: <= reads one byte too many */
        sum += v[i];
    return (int)(sum & 0xff);
}

int tlv_parse(const uint8_t *data, size_t size) {
    if (size < 4 || memcmp(data, "TLV1", 4) != 0) return -1;
    size_t pos = 4;
    int acc = 0;
    while (pos + 2 <= size) {
        uint8_t type = data[pos], len = data[pos + 1];
        pos += 2;
        if (len > size - pos) return -1;  /* the input-length check is correct */
        if (type == 1) acc += rec_name(data + pos, len);
        else if (type == 2) acc += rec_sum(data + pos, len);
        pos += len;
    }
    return acc;
}
SRC
cat > run_tlv.c <<'SRC'
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int tlv_parse(const uint8_t *data, size_t size);
int main(int argc, char **argv) {
    FILE *f = fopen(argv[1], "rb");
    if (!f) return 2;
    uint8_t *buf = malloc(4096);
    size_t n = fread(buf, 1, 4096, f);
    fclose(f);
    uint8_t *data = malloc(n);                  /* exact-size copy, so over-reads hit a redzone */
    for (size_t i = 0; i < n; i++) data[i] = buf[i];
    free(buf);
    printf("%s: tlv_parse = %d\n", argv[1], tlv_parse(data, n));
    free(data);
    return 0;
}
SRC
gcc -g -O0 -fsanitize=address,undefined tlv.c run_tlv.c -o run_tlv
mkdir crashes && python3 - <<'PY'
import os
rec = lambda t, v: bytes([t, len(v)]) + v
cases = {
    "c1": rec(1, b"N" * 24),
    "c2": rec(1, b"Q" * 40),
    "c3": rec(2, b"ab") + rec(1, b"x" * 30),
    "c4": rec(1, b"bob") + rec(2, b"\x01\x02"),
    "c5": rec(2, b""),
    "c6": rec(1, b"ok") + rec(2, b"12345"),
}
for name, body in cases.items():
    open(os.path.join("crashes", name), "wb").write(b"TLV1" + body)
PY
for f in crashes/*; do ./run_tlv "$f" > "$f.asan" 2>&1; done
python3 - <<'PY'
import glob, hashlib, re
RULES = [   # (kind, access) -> class; first match wins. A heuristic, like !exploitable or CASR.
    (("stack-buffer-overflow", "WRITE"), "EXPLOITABLE?  out-of-bounds write on the stack"),
    (("heap-buffer-overflow", "WRITE"),  "EXPLOITABLE?  out-of-bounds write on the heap"),
    (("heap-use-after-free", None),      "EXPLOITABLE?  use after free"),
    (("heap-buffer-overflow", "READ"),   "INFO LEAK?    out-of-bounds read"),
    (("SEGV", None),                     "DOS?          wild or null access, check the address"),
]
buckets = {}
for path in sorted(glob.glob("crashes/*.asan")):
    rep = open(path).read()
    kind = re.search(r"AddressSanitizer: ([\w-]+)", rep).group(1)
    acc = re.search(r"^(READ|WRITE) of size (\d+)", rep, re.M)
    frames = re.findall(r"#\d+ 0x[0-9a-f]+ in (\w+) /home/learner/", rep)[:3]
    key = "|".join([kind, acc.group(1) if acc else "-"] + frames)
    h = hashlib.sha1(key.encode()).hexdigest()[:8]
    buckets.setdefault(h, []).append((path.split("/")[1][:2], acc.group(2) if acc else "?", kind, acc and acc.group(1), frames))
print(f"{sum(len(v) for v in buckets.values())} crashes -> {len(buckets)} unique bugs\n")
for h, items in buckets.items():
    _, _, kind, access, frames = items[0]
    cls = next(c for (k, a), c in RULES if k == kind and a in (None, access))
    print(f"bucket {h}: {kind} {access}, frames {' > '.join(frames)}")
    print(f"  class: {cls}")
    print(f"  inputs: {', '.join(f'{n} (size {s})' for n, s, *_ in items)}")
PY
6 crashes -> 2 unique bugs

bucket 9e319f8b: stack-buffer-overflow WRITE, frames rec_name > tlv_parse > main
  class: EXPLOITABLE?  out-of-bounds write on the stack
  inputs: c1 (size 24), c2 (size 40), c3 (size 30)
bucket f9094c36: heap-buffer-overflow READ, frames rec_sum > tlv_parse > main
  class: INFO LEAK?    out-of-bounds read
  inputs: c4 (size 1), c5 (size 1), c6 (size 1)

Six files, two bugs:

  • Bucket 1 holds three inputs with name lengths 24, 40 and 30. c3 reaches the bug through a second record, after a sum record, but the stack is the same (rec_name > tlv_parse > main), so it lands in the same bucket. The class says: out-of-bounds write on the stack, look at it first.
  • Bucket 2 holds three one-byte reads past a sum record that ends the file, with value lengths 2, 0 and 5. The size of each bad read is 1 byte, a strong hint of an off-by-one. Class: possible information leak.

The fix order follows: bucket 1, then bucket 2. In a real campaign you would also minimise one input per bucket (next lesson) and attach it to the bug.

How triage goes wrong, and how it is checked

  • One bucket, two bugs. If both seeded bugs had been in one helper (say, a shared copy_value()), N = 3 frames could still separate them by caller, but N = 1 would not. After fixing a bucket, re-run all its inputs: any that still crash belong to another bug.
  • One bug, many buckets. Inlining, different optimisation levels and recursion change stacks. Compare builds with the same flags, and merge buckets whose root cause turns out to be the same.
  • Wrong class. A WRITE of size 1 could be a harmless store into padding; a READ of 8 bytes could leak a pointer. Look at the report, not just the label.

In ClusterFuzz and similar services the same checks are automated: when a fix lands, every input in the bucket is replayed, and the bug closes only when all of them pass.

How the bugs behind the buckets are fixed

The fixes are the two from the libFuzzer lesson: the length check in rec_name and < instead of <= in rec_sum. Triage changes what you do around the fix: one regression test per bucket (the minimised input), a note in the bug of which inputs were checked, and a severity that later goes into the advisory.

Pitfalls

  • Counting files as bugs in reports and metrics.
  • Line numbers in the key, which split buckets after every edit.
  • Treating "probably not exploitable" as "won't fix". Classes order the queue; every bucket gets a fix.
  • Proving exploitability by writing an exploit. It is rarely needed for a fix, it is not what triage is for, and it is outside this course.

Practice

1. Change the script to use only the top frame. Does the result change here?

No: the two bugs are in different functions (rec_name, rec_sum), so N = 1 still gives two buckets. It would merge them only if both bugs crashed in the same function.

2. Why does the key include READ/WRITE as well as the sanitizer kind?

A heap overflow read and a heap overflow write in the same function are usually different bugs with very different severity; the kind heap-buffer-overflow alone would merge them.

3. A bucket's top frame is memcpy in libc. What should the key use?

The first frames in your code (the caller of memcpy and its callers), as the script does by keeping only frames in /home/learner/. Library frames say where the bytes were moved, not which code chose the wrong length.

Test yourself

What is a typical deduplication key for fuzzer crashes?

  1. The input's hash
  2. Sanitizer kind, access type and the top few stack frames of your code
  3. The time of the crash
  4. The file size

Why are function names better than line numbers in the key?

  1. They are shorter
  2. Lines shift with unrelated edits, so the same bug would get new buckets
  3. Line numbers are secret
  4. ASan has no line numbers

Which crash class is usually looked at first?

  1. Null dereference
  2. Out-of-bounds write or use-after-free
  3. Timeout
  4. Out-of-memory

Input c3 reached the stack overflow through a second record. Why is it in the same bucket?

  1. Same file size
  2. Same kind, access and top three frames (rec_name > tlv_parse > main)
  3. The script is wrong
  4. It is the first input