Re: [PATCH] fhandle: fix UAF due to unlocked ->mnt_ns read in may_decode_fh()
Jann Horn <[email protected]>
| Newsgroups | gmane.linux.kernel.stable,gmane.linux.file-systems,gmane.linux.nfs,gmane.linux.kernel |
|---|---|
| Message-ID | <CAG48ez0Jte3UE8wn9Ljs3o2uVDFB24Zbp9zBdaj+D5c4R0+TSQ@mail.gmail.com> |
On Wed, Jun 3, 2026 at 8:24 PM Al Viro <[email protected]> wrote: > On Wed, Jun 03, 2026 at 07:15:23PM +0100, Al Viro wrote: > > On Wed, Jun 03, 2026 at 07:38:06PM +0200, Jann Horn wrote: > > > > > Fix it by taking rcu_read_lock() around the mount::mnt_ns access, like > > > in __prepend_path(). > > > > > + /* > > > + * Containing namespace. > > > + * Normally protected by namespace_sem, but there are also lockless > > > + * readers (which must use RCU to guard against the namespace being > > > + * freed). > > > + */ > > > + struct mnt_namespace *mnt_ns; > > > > Umm... It's somewhat subtle - at the very least you need to explain why > > there will be an RCU delay between umount_tree() clearing that and > > having the sucker freed. > > Something along the lines of "removals from namespace are serialized on > namespace_sem and guaranteed to happen no later than the active > refcount on namespace reaches zero; freeing of namespace happens only > after the passive refcount hitting zero and there's an RCU delay between > dropping the last active ref and dropping the passive one that had been > implicitly held by the fact of having actives", perhaps? Only in > more readable form than that, please... Hm, like this? Containing namespace (active). Normally protected by namespace_sem. Can also be accessed locklessly under RCU. RCU readers can't rely on the namespace still being active, but implicitly hold a passive reference (because an RCU delay happens between a namespace no longer being active and the corresponding passive refcount drop).