Android security tags, read closely by Lightrion

CVE-2024-31311 AI-generated analysis

platform/packages/modules/StatsD, lib/libstatssocket (AStatsEvent native API)

AI-generated: written from the bulletin and the fixing diffs by claude-fable-5-1, then checked against the code by claude-opus-5-5 (5 corrections). Verify against the commit before relying on it.

Adds a bounds check in libstatssocket's increment_annotation_count() so that an annotation added after the AStatsEvent buffer has reached its maximum capacity no longer reads and writes the byte at event->buf[lastFieldPos] when lastFieldPos is at or beyond event->bufSize.

Root cause

increment_annotation_count() in lib/libstatssocket/stats_event.c always read event->buf[event->lastFieldPos] to get the field type and the current annotation count, then wrote the updated count back to the same byte. It did not check that lastFieldPos was inside the buffer. The new check (lastFieldPos >= bufSize) shows that lastFieldPos could be at or beyond bufSize once the buffer had grown to its maximum size (50*1024 bytes per the new test) and a further write had been rejected with ERROR_OVERFLOW. A following AStatsEvent_addBoolAnnotation then reached increment_annotation_count and accessed buf[lastFieldPos] out of bounds. The new test TestHeapBufferOverflowError reproduces this sequence: it fills the buffer to the last byte, makes one rejected write that sets ERROR_OVERFLOW, then calls AStatsEvent_addBoolAnnotation.

How the fix works

Completeness

Behavior changes

Per major

Unknowns

Back to June 2024 · Findings