Skip to content

Aristotle found and fixed memory safety bugs in widely used C projects

Aristotle analyzed widely deployed C projects and found memory safety bugs in every one of them by proving what the code must never do. It then suggested fixes, and proved that they close the bugs. We worked with the maintainers to get each patch upstream.

What testing doesn’t reach

Each of these bugs needs a particular kind of input before it shows itself. That is what makes testing an unreliable way to find them: a test only covers the inputs someone thought to supply, and each of the usual tools stops short in its own way. A proof does not have that limit.

The projects below show what that looks like in practice. Fuzzers find what they stumble into, and these bugs sit behind inputs that are hard to stumble into: a sysstat performance data file listing the same activity 44 times, or two well-formed telegrams from an M-Bus utility meter arriving in a particular order. Sanitizers only report on code a test actually runs, and cracklib’s password checker overflows its buffer only when an account carries a 512-character word in its gecos field and a password is checked against that same account.

A proof covers every input in scope, so none of these preconditions have to be guessed in advance. When the proof fails, what comes back is a compiling C program that reproduces the bug.

Try Aristotle for C

The findings

sysstat

Affected versions: 12.8.0, and master at time of reporting

sysstat is the Linux performance-monitoring suite: sadc collects system activity into binary data files and sar reports on them. It is very widely installed on servers, particularly RHEL-family systems, and its data files are routinely copied between machines for analysis after an incident. Aristotle found and fixed an out-of-bounds write reachable from the ordinary sar -f path. A crafted data file can write past a global array into the globals next to it in the reading process.

StageCommitAristotle run
Bug present02167224Initial run
Patch acceptedea7744beFix check
FunctionBug classStatus
check_file_actlst()Out-of-bounds write (CWE-787)Fixed

libmbus

Affected versions: 0.10.4 and earlier, and master at time of reporting

libmbus implements the Meter-Bus protocol (M-Bus, EN 13757) for reading utility meters over serial lines or TCP. It is standard within metering, used in smart-metering gateways and building automation. Aristotle found and fixed a double free, preceded by a use-after-free read, in the public function the shipped multi-reply tools call. A meter or TCP-to-M-Bus gateway can corrupt the heap of the application reading it.

StageCommitAristotle run
Bug present057ab631Initial run
Patch accepted13a6f844Fix check
FunctionBug classStatus
mbus_sendrecv_request()Double free (CWE-415), with a use-after-free read (CWE-416)Fixed

dtc / libfdt

Affected versions: 1.7.1 through 1.8.1, and main at time of reporting

libfdt is the C library for reading and editing flattened device tree blobs, the hardware descriptions that ARM, RISC-V and PowerPC systems boot with. It is vendored into most boot and virtualisation stacks, including the Linux kernel, U-Boot, QEMU, Xen and OpenSBI. Aristotle found and fixed an out-of-bounds read and write when applying a device tree overlay. A crafted overlay gets a four-byte read-modify-write at an offset it chooses, and the overlay still passes libfdt’s own fdt_check_full() validation.

StageCommitAristotle run
Bug presentce51dcbdInitial run
Patch accepted42980898Fix check
FunctionBug classStatus
overlay_update_local_node_references()Out-of-bounds write (CWE-787) and read (CWE-125)Fixed
overlay_update_node_conflicting_references()Out-of-bounds write (CWE-787) and read (CWE-125)Fixed

The accepted commit also adds a regression test, tests/overlay_bad_fixup_local_fixups_offset.dts.

cracklib

Affected versions: 2.10.0 through 2.10.3, and main at time of reporting

cracklib checks password strength against dictionaries of weak passwords and against the user’s own account details, such as their name and gecos field. It is a default dependency on RHEL and Fedora, reached through the PAM password-change stack behind tools like passwd and chpasswd. Aristotle found and fixed a stack buffer overflow in the word-mangling code, along with three further undefined-behaviour sites in the same functions. A long enough word in an account’s gecos field overflows a 1024-byte stack buffer whenever a password is checked for that account.

StageCommitAristotle run
Bug present34a5d20bInitial run
Patch accepted#129, #130, #131, #132Fix check
FunctionBug classStatus
Mangle()Stack out-of-bounds write (CWE-787)Fixed
Reverse()Out-of-bounds pointer arithmeticFixed
Pluralise()Out-of-bounds read (string[-1], CWE-125)Fixed
MatchClass(), Char2Int(), CRACK_TOLOWER/CRACK_TOUPPERInvalid argument to <ctype.h> function (negative char)Fixed

Prove your own code

  1. 01

    Give Aristotle your C code and the behavior it should satisfy.

  2. 02

    Aristotle finds bugs and gives you a compiling C program that reproduces each one.

  3. 03

    Aristotle suggests fixes and proves that they close the bugs.

Try Aristotle for C