Linux kernel stale dentry lookup during mount detachment
Linux
Affected versions
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
Linux
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
≥ 8ed936b5671bfb33d89bc60bdcc7cf0470ba52fe · < d29cd99db3db74cf3447be74d25740981789d461| No fix yet |
| Linux Linux |
|
|
In the Linux kernel, the following vulnerability has been resolved:
namespace: unhash a dentry before detaching the mounts on it
unlink(), rmdir() and rename() remove the entry from the filesystem, call detach_mounts() on the entry with the inode locked and then call d_delete() once the inode is unlocked.
The thing is that between detach_mounts() and d_delete() the dentry is still hashed and positive. But after detach_mounts() nothing covers the dentry anymore. A lookup that finds this dentry in the dcache can uncover what the mounts hid.
That's a problem when unlinking files or directories that are mountpoints in other mount namespaces. Everybody who had the underlying entry covered can race the detach_mount() call until d_delete() has run.
The race window isn't all that small. It encompasses namespace_unlock() with a full synchronize_rcu_expedited() grace period and the inode_unlock() of the entry.
In my experiments three walkers that kept trying read an overmounted file in 11938 of the 16140 unlinks that removed its mountpoint from a bind mount of the filesystem within a minute.
Fun fact, d_invalidate() has the same ordering problem but gets it right. It unhashes the dentry first and detaches the mounts afterwards. Let's do the same in __detach_mounts():
From the CVE record · Linux
The Linux kernel can leave a dentry discoverable briefly after detaching mounts during unlink, rmdir, or rename. A lookup racing that operation may access an underlying entry that a mount had hidden, including reading an overmounted file. The input does not specify network access, authentication requirements, or user interaction.
Engineers running Linux kernels should check their versions against the vendor advisory; affected versions are not specified in the input.