ceph: hold extra reference to r_parent over life of request
authorJeff Layton <jlayton@kernel.org>
Wed, 3 Apr 2019 17:16:01 +0000 (13:16 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Jan 2020 15:45:24 +0000 (16:45 +0100)
commitfdd0f3b0e98badb7eb2428252f83c2acb494e176
tree2d9ab3d05247aaa6c6c68e94cb4a3abc3e7a54d0
parent19d0cd2127428aa755907aa05828f6698e48cf87
ceph: hold extra reference to r_parent over life of request

commit 9c1c2b35f1d94de8325344c2777d7ee67492db3b upstream.

Currently, we just assume that it will stick around by virtue of the
submitter's reference, but later patches will allow the syscall to
return early and we can't rely on that reference at that point.

While I'm not aware of any reports of it, Xiubo pointed out that this
may fix a use-after-free.  If the wait for a reply times out or is
canceled via signal, and then the reply comes in after the syscall
returns, the client can end up trying to access r_parent without a
reference.

Take an extra reference to the inode when setting r_parent and release
it when releasing the request.

Cc: stable@vger.kernel.org
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ceph/mds_client.c