Re: dcache: remove trylock loops (was Re: [BUG] lock_parent() breakage when used from shrink_dentry_list())
From: Eric W. Biederman
Date: Mon Mar 12 2018 - 19:29:29 EST
Al Viro <viro@xxxxxxxxxxxxxxxxxx> writes:
> On Mon, Mar 12, 2018 at 03:23:44PM -0500, Eric W. Biederman wrote:
>
>> Of the two code paths you are concert about:
>>
>> For path path_connected looking at s_root is a heuristic to avoid
>> calling is_subdir every time we need to do that check. If the heuristic
>> fails we still have is_subdir which should remain accurate. If
>> is_subdir fails the path is genuinely not connected at that moment
>> and failing is the correct thing to do.
>
> Umm... That might be not good enough - the logics is "everything's
> reachable from ->s_root anyway, so we might as well not bother checking".
> For NFS it's simply not true.
If I am parsing the code correctly path_connected is broken for nfsv2
and nfsv3 when NFS_MOUNT_UNSHARED is not set. nfsv4 appears to make
a kernel mount of the real root of the filesystem properly setting
s_root and then finds the child it is mounting.
> We can mount server:/foo/bar/baz on /tmp/a, then server:/foo on /tmp/b
> and we'll have ->s_root pointing to a subtree of what's reachable at
> /tmp/b. Play with renames under /tmp/b and you just might end up with
> a problem. And mount on /tmp/a will be (mistakenly) considered to
> be safe, since it satisfies the heuristics in path_connected().
Agreed.
Which means that if you mount server:/foo/bar/baz first and then
mount server:/foo with an appropriate rename you might be able
to see all of server:/foo or possibly server:/
Hmm..
Given that nfs_kill_super calls generic_shutdown_super and
generic_shutdown_super calls shrink_dcache_for_umount
I would argue that nfsv2 and nfsv3 are buggy in the same
case, as shrink_dcache_for_umount is called on something
that is not the root of the filesystem's dentry tree.
Eric