vfs: Test for and handle paths that are unreachable from their mnt_root 53/154653/1
authorEric W. Biederman <ebiederm@xmission.com>
Sun, 16 Aug 2015 01:27:13 +0000 (20:27 -0500)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 11 Oct 2017 02:57:13 +0000 (11:57 +0900)
commit168c93a435cffebfaf119cdd16127ed70d38a0a8
tree64eba2911ffabaf53980e888941adc72c3f4fa91
parent71a59644c6e135efed6441974e133959e884feec
vfs: Test for and handle paths that are unreachable from their mnt_root

commit 397d425dc26da728396e66d392d5dcb8dac30c37 upstream.

In rare cases a directory can be renamed out from under a bind mount.
In those cases without special handling it becomes possible to walk up
the directory tree to the root dentry of the filesystem and down
from the root dentry to every other file or directory on the filesystem.

Like division by zero .. from an unconnected path can not be given
a useful semantic as there is no predicting at which path component
the code will realize it is unconnected.  We certainly can not match
the current behavior as the current behavior is a security hole.

Therefore when encounting .. when following an unconnected path
return -ENOENT.

- Add a function path_connected to verify path->dentry is reachable
  from path->mnt.mnt_root.  AKA to validate that rename did not do
  something nasty to the bind mount.

  To avoid races path_connected must be called after following a path
  component to it's next path component.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick from linux-3.10.y to fix CVE-2015-2925]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I93d42edb823ecd450eaf1f17b7399f388a163d5a
fs/namei.c