Lab 03 — Triage at scale, and the report¶
Objective: take a pile of crash artefacts rather than one, reduce it to a defensible list of distinct defects, discover by measurement that the deduplicator is wrong in both directions, and then write the disclosure document that a vendor's response team could actually act on — including deciding where to send it.
Difficulty: intermediate to advanced Time: 2–3 hours Prerequisites: Lab 02 completed. 70 §3.6, §3.7, §5.8 and §5.9.
What you need
| The chapter's examples, built | ../examples/build.sh |
python3 |
For generating inputs and running the triage tool |
../scripts/triage-asan.py |
The deduplicator |
| No device | Nothing here touches a phone |
0. Why deduplication is a research skill and not a chore¶
A campaign gives you artefacts. A vendor wants defects. The mapping between them is many-to-many in both directions, and getting it wrong costs you in two different ways:
- Under-merging — reporting 40 "findings" that are one bug — makes you look like someone who cannot read a stack trace, and it is the fastest way to get your future reports triaged slowly.
- Over-merging — collapsing three bugs into one because they share a call site — means two real defects never get fixed.
And there is a third case people do not expect at all: one defect that produces several completely different reports, one of which points at innocent code and two of which do not produce a report at all. This lab measures that one, because reading about it does not stick.
Part 1 — Manufacture a realistic pile¶
Step 1.1 Build¶
# host, from 70-VulnerabilityResearch/examples/
./build.sh
OUT=${TMPDIR:-/tmp}/acfg-build
Step 1.2 Generate a spread of inputs¶
Real campaigns produce hundreds of artefacts clustered around a handful of code sites. Manufacture that shape deliberately:
# host -- python3 -B make_pile.py <outdir>
import os, struct, sys, random
d = sys.argv[1]
os.makedirs(d, exist_ok=True)
random.seed(7) # reproducible pile
def blob(recs, version=1, count=None):
n = len(recs) if count is None else count
b = b'ACFG' + struct.pack('<HH', version, n)
for t, name, val in recs:
b += struct.pack('<BBH', t, len(name), len(val)) + name + val
return b
n = 0
# Cluster A: count=1, name longer than 32. The loud case. Many variants.
for klen in range(33, 120):
for pad in (0, 3, 7):
open('%s/a-%03d.bin' % (d, n), 'wb').write(
blob([(1, bytes([random.randrange(65, 91)]) * klen, b'x' * pad)]))
n += 1
# Cluster B: count=1, name exactly 32. Only the terminator is out of bounds.
for pad in range(0, 12):
open('%s/b-%03d.bin' % (d, n), 'wb').write(
blob([(1, b'B' * 32, b'y' * pad)]))
n += 1
# Cluster C: count>=2, overflow lands INSIDE the allocation.
for cnt in (2, 3, 4, 8):
for klen in (34, 40, 48):
open('%s/c-%03d.bin' % (d, n), 'wb').write(
blob([(1, b'C' * klen, b'')] + [(1, b'z', b'')] * (cnt - 1)))
n += 1
# Cluster D: perfectly valid inputs. A real findings directory always has some,
# because a corpus and a crash directory get mixed up sooner or later.
for i in range(10):
open('%s/d-%03d.bin' % (d, n), 'wb').write(
blob([(1, b'ok', b'v' * i)]))
n += 1
print('generated', n, 'inputs in', d)
# host
python3 -B make_pile.py /tmp/pile
Step 1.3 Run them all and keep the reports¶
# host
mkdir -p /tmp/reports
export UBSAN_OPTIONS=print_stacktrace=1
for f in /tmp/pile/*.bin; do
n=$(basename "$f" .bin)
"$OUT/fuzz_vulnerable_standalone" "$f" > "/tmp/reports/$n.txt" 2>&1
echo "$n exit=$?" >> /tmp/reports/exitcodes.txt
done
wc -l < /tmp/reports/exitcodes.txt
Step 1.4 Grade it the wrong way first, deliberately¶
# host -- the way most people grade a campaign
grep -c 'exit=1' /tmp/reports/exitcodes.txt # "crashes"
grep -c 'exit=0' /tmp/reports/exitcodes.txt # "clean"
Write both numbers down.
Now grade it the right way:
# host -- the way you should grade a campaign
grep -rl 'ERROR: AddressSanitizer' /tmp/reports/ | wc -l
grep -rl 'runtime error:' /tmp/reports/ | wc -l
grep -rl 'runtime error:' /tmp/reports/ | xargs grep -l 'exit\|^' 2>/dev/null | wc -l
The gap between the two gradings is the lesson. Every cluster-B and cluster-C input is a genuine out-of-bounds write in the target and every one of them exits 0. A campaign graded on exit codes records them as clean runs.
Warning — this is not a contrived setup. UBSan is non-fatal by default. Unless you set
UBSAN_OPTIONS=halt_on_error=1, a UBSan-only defect prints one line and the process continues to normal termination. There is no artefact, no non-zero exit and nothing for a script to notice.grep -c "runtime error" campaign.logis a thirty-second habit that changes what your campaigns find.
Success criterion for Part 1: both gradings recorded, with the discrepancy quantified.
Part 2 — Deduplicate¶
Step 2.1 Run the tool¶
# host
python3 -B ../scripts/triage-asan.py --dir /tmp/reports | head -40
Step 2.2 Vary the hash depth¶
# host
for n in 1 2 3 5 8; do
printf 'frames=%s buckets=%s\n' "$n" \
"$(python3 -B ../scripts/triage-asan.py --frames $n --json --dir /tmp/reports \
| python3 -c 'import json,sys; print(len(json.load(sys.stdin)["buckets"]))')"
done
Record the curve. It tells you something real about the trade-off:
| Frames | Effect |
|---|---|
| Too few | Distinct bugs sharing a common callee merge. Everything that overflows through memcpy becomes one bucket |
| Too many | One bug reached by three call paths becomes three bugs |
| 3–5 meaningful | The usual compromise |
The word meaningful is load-bearing. The tool drops the sanitizer's own interceptor frames, libc,
_start, and — this one is measured — the string_fortified.h wrapper that _FORTIFY_SOURCE inlines
memcpy through. Without that last exclusion, every overflowing copy in the program reports the
same top frame, a libc header, and the bucket table points at code the target does not own.
Step 2.3 Verify the exclusion matters¶
# host -- what does the raw top frame look like?
grep -h -A3 'WRITE of size' /tmp/reports/a-000.txt | head -5
You should see __interceptor_memcpy, then memcpy in string_fortified.h, then the real site in
acfg-vulnerable.c. Two of those three frames are noise, and the tool's whole usefulness depends on
knowing that.
Success criterion for Part 2: the bucket count at five hash depths, and an explanation of the curve's shape.
Part 3 — Discover that the tool is wrong, in both directions¶
Step 3.1 Count what it says¶
At the default depth the tool reports a small number of buckets over your pile. Write it down.
Step 3.2 Count the ground truth¶
Open ../examples/acfg-vulnerable.c and find the PLANTED BUG
banner. Count the defects.
There is one.
Step 3.3 Reconcile¶
Run the small, precise experiment the chapter used:
# host
python3 -B - /tmp/four <<'PY'
import os, struct, sys
d = sys.argv[1]; os.makedirs(d, exist_ok=True)
def blob(recs, version=1):
b = b'ACFG' + struct.pack('<HH', version, len(recs))
for t, name, val in recs:
b += struct.pack('<BBH', t, len(name), len(val)) + name + val
return b
open(d+'/A-count1-nlen58.bin','wb').write(blob([(1, b'A'*58, b'')]))
open(d+'/B-count1-nlen32.bin','wb').write(blob([(1, b'A'*32, b'')]))
open(d+'/C-count2-nlen200.bin','wb').write(blob([(1, b'B'*200, b''), (2, b'x', b'')]))
open(d+'/D-count4-nlen40.bin','wb').write(blob([(1, b'C'*40, b''),(1,b'a',b''),
(1,b'b',b''),(1,b'c',b'')]))
print('4 inputs written')
PY
mkdir -p /tmp/four-reports
for f in /tmp/four/*.bin; do
n=$(basename "$f" .bin)
"$OUT/fuzz_vulnerable_standalone" "$f" > "/tmp/four-reports/$n.txt" 2>&1
echo "$n exit=$?"
done
python3 -B ../scripts/triage-asan.py --dir /tmp/four-reports
Measured result from the chapter, which you should be able to reproduce:
reports parsed : 5
distinct buckets: 2 (stack hash over 3 meaningful frames)
BUCKET COUNT CLASS TOP FRAME
cf09c9723d6d 3 heap-buffer-overflow WRITE acfg_parse acfg-vulnerable.c:258
e38adc13ef0f 2 ubsan-array-bounds (unnamed) acfg-vulnerable.c:259
Five artefacts. Two buckets. One defect.
The tool split the defect because the memcpy is on line 236 and the terminator store is on line
237, and a line-sensitive stack hash cannot know they are the same missing check. That is not a
bug in the tool — it is the documented limit of the heuristic, and it is exactly why the bucket count
is a first approximation a human corrects.
Step 3.4 Notice what the tool found that you would not have¶
Read the per-bucket detail:
size varies : 58, 200 across this bucket -- the access length is a VARIABLE
the input controls, not a constant.
region varies : 56, 112 -- the allocation being overflowed is also
input-influenced, so the attacker chooses the size class.
Neither line is derivable from a single report. 56 and 112 are one and two records of 56 bytes,
which is the count field showing up in the allocation size — evidence that the attacker chooses
which size class they overflow out of. That is a materially stronger claim than "there is an
overflow", and it exists only because three reports landed in one bucket and could be compared.
Deduplication is not only noise reduction. Comparing the members of a bucket is a source of evidence in its own right.
Step 3.5 Write the reconciliation¶
Produce a short table mapping every bucket to a defect:
| Bucket | Artefacts | Tool's class | Actual defect | Why they differ |
|---|---|---|---|---|
cf09c972… |
3 | heap-buffer-overflow WRITE @258 | The missing destination check | The memcpy face of it |
e38adc13… |
2 | ubsan-array-bounds @259 | The same missing destination check | The terminator-store face, which stays inside the allocation |
Warning — your bucket hashes will not match these. The hash is computed over function names, file basenames and line numbers, so it changes whenever anyone edits the file above the bug — including adding a comment. These two values were measured against the shipped
acfg-vulnerable.c; if yours differ, check the line numbers rather than assuming you did something wrong. That instability is exactly why the tool records the build alongside the hash instead of pretending the hash spans releases.
Success criterion for Part 3: the reconciliation table, and a sentence explaining why the same defect produces a report on two different lines.
Part 4 — Classify without the tool¶
Take five reports from your pile at random and, for each, answer from the report alone:
- Target or harness? (Which frames are which?)
- Read or write, and of what size?
- How far out of bounds, and is the distance controlled?
- What was the allocation, and where was it made?
- Which of §3.8's questions can the report not answer?
Then run the tool and compare. Where you disagree, work out which of you is right.
Question 5 is the one to spend time on. Every real triage bottoms out in a question the crash cannot answer — usually "how much of this is attacker-controlled?", which needs the source, and "what is next door?", which needs the hosting process. Knowing which question you are stuck on is what tells you what to do next.
Success criterion for Part 4: five hand triages, compared against the tool, with disagreements resolved and written down.
Part 5 — Route the disclosure¶
Before writing anything, decide where it goes. Getting this wrong wastes months.
Step 5.1 The routing exercise¶
For each of the following hypothetical findings, name the destination and the fix pipeline:
| Finding | Where does it go? | How does the fix reach users? |
|---|---|---|
| Heap overflow in an AOSP media extractor | ||
| The same bug, but the component ships as a Mainline module | ||
| Overflow in a vendor HAL, only on one OEM's devices | ||
| Confused deputy in a preinstalled OEM system app | ||
Overflow in libpng as used by Android |
||
| Auth bypass in a banking app from Google Play | ||
| Overflow in Play Services |
Check yourself against §5.8's table. The two that catch people are the Mainline row (same code, much
faster pipeline, and worth saying in the report) and the libpng row (upstream first — you cannot
fix it and they can).
Step 5.2 The test that decides AOSP versus OEM¶
# host -- does it reproduce on a Pixel or an AOSP emulator image?
If it reproduces on AOSP, it is probably Google's. If it reproduces only on the OEM device, it is probably theirs. State which you tested in the report — that one sentence saves a triage round-trip, and its absence is a common reason a report bounces between two vendors for a month.
Success criterion for Part 5: the routing table filled in, and the AOSP-versus-OEM test described.
Part 6 — Write the report¶
Step 6.1 Write it for the ACFG defect, honestly¶
Use §5.9's structure. The interesting constraint is that the honest verdict is not a vulnerability — so this is an exercise in writing a bug report with a full technical analysis and a severity of none, which is a document you will write far more often than the other kind.
SUMMARY
An out-of-bounds heap write in acfg_parse() allows a caller supplying a
malformed ACFG blob to write up to 223 attacker-chosen bytes past the end
of a heap allocation whose size class the caller also influences.
REACHABILITY: none. No shipping software parses this format. This is a
defect in a teaching artefact and is reported here as a bug, not a
vulnerability.
AFFECTED
examples/acfg-vulnerable.c as of <commit>
Built with gcc 11.4.0, -fsanitize=address,undefined -O1, x86_64 Linux.
TECHNICAL DETAIL
The parser validates that the name bytes are PRESENT in the input:
if (off + (size_t)nlen + (size_t)vlen > len) { ... return ACFG_E_TRUNC; }
and then copies them into a fixed 32-byte destination without validating
that they FIT:
memcpy(rec->name, buf + off, nlen); /* nlen is 0..255 */
rec->name[nlen] = '\0';
The source check is correct. The destination check is absent. Both the
length (nlen, a byte from the input) and the contents (copied verbatim from
the input) are fully attacker-controlled.
OBSERVED BEHAVIOUR
count=1, nlen=58 : ASan heap-buffer-overflow, WRITE of size 58, 0 bytes to
the right of a 56-byte region. Exit code 1.
count=1, nlen=32 : ASan silent. UBSan reports
"index 32 out of bounds for type 'char [32]'".
Exit code 0.
count=4, nlen=40 : ASan silent. UBSan reports the same class. Exit code 0.
The second and third cases are the identical defect. The write lands inside
the same calloc allocation, where ASan places no redzone between structs,
so only UBSan's array-bounds check -- which has the static type information
-- observes it.
IMPACT ASSESSMENT
Strong linear heap-overflow primitive: full control of the write length,
full control of the written bytes, and influence over the size class of the
overflowed chunk via the count field.
NOT SHOWN: no control-flow hijack was demonstrated and none is claimed. No
exploit was developed. There is no hosting process in which to assess heap
state, because the format is not parsed by any shipping software.
REPRODUCTION
1. cd examples && ./build.sh
2. printf ... > repro.bin (76 bytes; attached)
3. ${TMPDIR}/acfg-build/fuzz_vulnerable_standalone repro.bin
Expected: AddressSanitizer heap-buffer-overflow at acfg-vulnerable.c:258
SUGGESTED FIX
if (nlen >= ACFG_NAME_MAX) { acfg_free(out); return ACFG_E_NAME; }
Note >= rather than >: one byte of the destination is reserved for the
terminator, and > would leave a one-byte NUL overflow behind. Reject rather
than clamp: clamping accepts a malformed blob and produces a truncated name
the rest of the system treats as legitimate, converting a memory-safety bug
into a parser differential.
FIX VERIFICATION PERFORMED
- the campaign reproducer: no fault
- all four hand-built inputs above: no fault, zero sanitizer lines
- a full 200,000-execution campaign from the identical PRNG seed and seed
file: completed, zero sanitizer lines
This does not establish that the parser is correct. It establishes that
this defect class no longer fires under this corpus and this detector set.
DISCLOSURE
Not applicable; this is a documentation artefact.
Step 6.2 Audit your own report¶
Check it against the failure column of §5.9's table:
| Requirement | Did you? |
|---|---|
| Lead with the verdict, not the stack trace | |
| Exact build and flags, not "latest" | |
| Reachability stated explicitly, with an evidence level | |
| Reproduction steps from a clean state, from an app if the claim is about an app | |
| Minimised reproducer, not a corpus | |
| Sanitizer output as text, not a screenshot | |
| Analysis names the wrong line | |
| Impact includes a "not shown" line | |
| A suggested fix, as code | |
| Disclosure intent stated |
The "not shown" line is what separates a professional report from an amateur one. Stating what you did not establish is what makes the rest believable.
Step 6.3 Minimise the reproducer¶
# host -- with libFuzzer
./fuzz_acfg -minimize_crash=1 -runs=100000 findings/crash-<hash>
Without libFuzzer, do it by hand: halve the input, does it still crash? Repeat. Then trim fields one at a time. A 12-byte reproducer lets the engineer see the cause by looking at it; a 4 KB one does not.
Success criterion for Part 6: a complete report, self-audited against the ten-row table, with a minimised reproducer attached.
Part 7 — The severity conversation¶
Step 7.1 Rate the same defect five ways¶
The same code, five different homes. Assign a severity band to each and justify it in one sentence:
| Where the code lives | Severity | Your justification |
|---|---|---|
| Parsing only data the same process just generated | ||
| In an app, parsing files it downloads over TLS from its own server | ||
In an app, parsing files any other app can supply via a ContentProvider |
||
| In a system service, parsing data any app can send | ||
| In a component parsing data from a web page, no user interaction |
Nothing about the code changes across those rows. §5.7.
Step 7.2 Now apply the mitigations¶
Take row four — system service, any app — and adjust for each mitigation in turn. Which of these changes the severity band, and which only changes the difficulty?
- CFI enabled in the shipped build
_FORTIFY_SOURCEcatching the copy and aborting- The process confined to an SELinux domain that can do almost nothing
- MTE enabled on the device
- ASLR with no infoleak available
§3.11 has the answers. The one people get wrong is SELinux: it does nothing whatsoever to the corruption, and it may be the largest single factor in what the corruption is worth.
Success criterion for Part 7: both tables filled in with justifications.
Success criteria¶
- A pile of at least 100 artefacts spanning at least three behaviours.
- Both gradings recorded — exit codes versus log contents — with the discrepancy quantified.
- A bucket-count curve across five hash depths, with the shape explained.
- The reconciliation table: buckets versus actual defects, with the reason they differ.
- The measured demonstration that one defect produced two buckets and five artefacts.
- Five hand triages compared against the tool, with disagreements resolved.
- The routing table completed for seven hypothetical findings.
- A complete report, self-audited against the ten-row checklist.
- A minimised reproducer.
- Both severity tables, with justifications.
Extension exercises¶
- Fix the deduplicator. Add an option that merges buckets whose top frames are within N source lines of each other in the same function. Then find a case where that merge is wrong. Both halves are the exercise.
- Add bug shadowing to the pile. Plant a second defect a few lines after the first, and confirm that inputs triggering the first never reveal the second. Then fix the first and re-run the whole corpus. This is why "replay the corpus after every fix" is not busywork.
- Write the report for a bug you have not analysed. Take a report from your pile at random, without looking at the source, and write the disclosure. Then read the source and see how much of what you wrote was inference presented as fact.
- Read three real Android Security Bulletin entries and, for each, work out from the description alone what the bug class probably was and what the reachability argument must have been. The bulletin is deliberately terse; reconstructing the shape from it is a skill in its own right, and the linked fix usually confirms or refutes you within a minute.
Where to go next¶
Lab 04 — CTF: The Reachability Verdict, where you are given the artefacts and must produce the verdicts — including for the two that are not vulnerabilities.