A race condition in FreeBSD’s mutex implementation

Summary

Felix von Leitner called a FreeBSD vulnerability published in 2024 a candidate for the shortest computer science joke: a race condition in the implementation of mutexes. Through a use-after-free in the userspace mutexes, umtx for short, local users could gain root privileges from FreeBSD 11.0 onwards. The joke behind it: mutexes are precisely the tool meant to prevent race conditions.

What a race condition is

A race condition occurs when two parts of a program running at the same time access the same resource and the result depends on which comes first. Synchronisation mechanisms exist against such errors, the most important being the mutex: it ensures that only one part of a program at a time enters a critical section.

A use-after-free means that a program continues to use memory that has already been freed. If an attacker manages to fill this memory with their own data in the meantime, this can lead to a takeover of the system. In the kernel, that means full privileges.

Why nobody is affected alone

An update to the post clarifies that Linux has also had similar bugs in its futex mechanisms. Synchronisation in the kernel is among the hardest things in systems programming, because errors only occur under rare timing conditions and are difficult to test. Tools such as sanitisers and fuzzers help but do not find everything.

Ideas

  • Mutexes are meant to prevent race conditions but can contain them themselves.
  • A use-after-free in the kernel can lead to full system privileges.
  • Synchronisation errors only occur under rare timing conditions.

Insights

  • Fundamental mechanisms in particular need especially thorough review.
  • No operating system is free of synchronisation bugs.

Facts

  • FreeBSD versions from 11.0 onwards were affected.
  • The vulnerability was in the userspace mutexes, umtx for short.
  • LPE stands for local privilege escalation.

References

Remarks

  • The update in the original refers to a comparable Linux vulnerability from 2014.

Recommendations

  • Install security updates for FreeBSD and Linux promptly, even for purely local vulnerabilities.
  • Treat systems with many users or insecure services as targets for local privilege escalation.

Read the original article

Search the Web Archive

Found a mistake or have something to add? Get in touch.