Offline educational model of CVE-2026-112936 (filelock SQLite symlink follow)
Local lab for CVE-2026-112936 (GHSA-j8f7-rjxc-mr56): filelock's
ReadWriteLock keyed its instances by Path(lock_file).resolve() and let
sqlite3.connect() open the lock path, so a symlink planted at that path
was followed: the process created or locked the file the link pointed to,
and repointing the link gave two processes "the" write lock on different
files. The fix, commit 4d45e83caf7e (filelock 4.0.9), opens the path with
O_NOFOLLOW | O_NONBLOCK, refuses anything that is not a regular file,
resolves only the parent for the key and connects SQLite through
/proc/self/fd/N. Educational, deterministic, C11 checked with ASan/UBSan.
No SQLite, no filelock, no network, no other user. Each case builds its
own names inside a fresh mkdtemp() sandbox, runs the two opens with real
syscalls and removes the sandbox; the output is labels and sandbox-relative
keys only.
Spanish: README.es.md. Exercises: PRACTICE.md.
src/filelock/_read_write.py)| Diff line | Code | Lab |
|---|---|---|
| old 212, old 309 | pathlib.Path(lock_file).resolve() | pre key: fl_resolve (non-strict, follows links) |
| new 224-225, new 322 | pathlib.Path(_canonical(lock_file)), "resolve only the parent" | post key: fl_canonical (parent resolved, name kept) |
| old 740-746 | sqlite3.connect(database, ...) | pre open: open(name, O_RDWR|O_CREAT|O_NONBLOCK) stand-in |
| new 54-55 | _DB_OPEN_FLAGS = O_RDWR|O_CREAT|O_NOFOLLOW|O_NONBLOCK | post open flags, mode 0600 (new 775) |
| new 776-779 | if not S_ISREG(os.fstat(fd).st_mode): close, "refusing a non-regular lock database" | REFUSED_NONREG |
| new 753-765, 59 | hold the fd; target = f"{_FD_DIR}/{fd}" (/proc/self/fd on Linux) | reopen action |
The GHSA says SQLite's VFS resolves the final symlink in user space, so
fs.protected_symlinks and the sticky bit do not stop it; the lab's pre
stand-in lets the kernel follow the link instead, which gives the same
result in a single-user sandbox. _canonical lives in _api.py, outside
the diff: only its comment ("resolve only the parent") is modelled.
results/)| At the lock path | pre | post |
|---|---|---|
symlink to private/pwned.flag (missing), also through a chain | FOLLOWED_CREATED, a new file outside the lock path | REFUSED_SYMLINK, nothing created |
| symlink to an existing file (absolute or relative) | FOLLOWED_EXISTING, key = the target | REFUSED_SYMLINK, key = the link |
| symlink to a FIFO / a directory / itself / a missing directory | OPENED_NONREG / ERR_EISDIR / ERR_ELOOP / ERR_ENOENT | REFUSED_SYMLINK |
| FIFO | OPENED_NONREG | REFUSED_NONREG |
| link repointed between two opens (GHSA PoC step 3) | EXCLUSION_BROKEN, keys S/a.db and S/b.db | REFUSED |
| link replaced after validation, then connect | REOPEN_FOLLOWED (the name is opened again) | REOPEN_SAME_INODE (/proc/self/fd/N) |
| regular file, missing name, directory, symlinked parent, hard link | same in both | same in both |
results/sweep.csv crosses 13 kinds of object at the lock path. On 400
random setups the tests check that post never creates a name outside the
lock path, always refuses a final symlink, and that without a final symlink
both versions agree except for non-regular files.
Two cases are observations of the lab, not findings: a hard link at the
path (c13) is opened by both versions (O_NOFOLLOW is about symlinks;
fs.protected_hardlinks is not modelled), and renaming the lock file away
and creating a new one between two opens (s04) splits the inode in both
versions; doing that to another user's file in a sticky directory needs
rights the lab does not model.
sh scripts/build.sh test # -Wall -Wextra -Werror, ASan + UBSan
python3 scripts/derive_expected.py | diff - fixtures/expected.tsv
sh scripts/build.sh results /tmp/r && diff -r results /tmp/r
./build/fllab case pre 'F:a.db;L:lock.db>a.db' 'open:lock.db'
fixtures/cases.tsv holds positive, negative, edge and out-of-domain cases
with labels derived by hand. fixtures/expected.tsv comes from
scripts/derive_expected.py, which runs the same scenarios with Python's
os module in its own sandbox and computes the pre key with pathlib's
real resolve(); the C tests compare labels and keys against both.
A model is not a finding: see LIMITATIONS.md and SOURCES.md. License: Apache-2.0.