Paper notes: Midas: Systematic Kernel TOCTTOU Protection
Sat 10 September 2022 — download

Yet another cool paper from the HexHive people (Mathias Payer ♥) with Uroš Tešić from Nvidia. The main idea is to mitigate TOCTTOU on Linux happening in kernel-land when accessing userland by making accessed userspace objects invariable through syscalls lifetime, by instrumenting functions like copy_from_user/copy_to_user/mm_populate/… and making use of page tables faults to detect writes.

  1. Snapshot page on first read.
  2. Read from snapshot on future reads.
  3. Duplicate page on concurrent writes.
  4. Discard snapshot when syscall finishes.
  5. Commit the last written to page.

The paper details some special edge-cases that have to be taken care of, like confused-deputy problems, weird drivers, double-mappings, execve, futex, rt_sigaction, …

The measured performance impact is around 3.4% on the Phoronix Test Suite, 3.7% on the NAS Parallel Benchmarks, albeit more worrying numbers like 13-14% impact on nginx have been observed in some particular configurations.

It's overall a simple'n'cool idea, albeit it'll wreak havoc in production by breaking vulnerable-but-working code, so it might be wise to run it on syzkaller for a while, before considering using it.

The code has of course been published, and the paper was part of the 31st USENIX Security Symposium.