]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ceph: fix potential mdsc use-after-free crash
authorXiubo Li <xiubli@redhat.com>
Wed, 1 Jul 2020 05:52:48 +0000 (01:52 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Sep 2020 09:19:25 +0000 (11:19 +0200)
[ Upstream commit fa9967734227b44acb1b6918033f9122dc7825b9 ]

Make sure the delayed work stopped before releasing the resources.

cancel_delayed_work_sync() will only guarantee that the work finishes
executing if the work is already in the ->worklist.  That means after
the cancel_delayed_work_sync() returns, it will leave the work requeued
if it was rearmed at the end. That can lead to a use after free once the
work struct is freed.

Fix it by flushing the delayed work instead of trying to cancel it, and
ensure that the work doesn't rearm if the mdsc is stopping.

URL: https://tracker.ceph.com/issues/46293
Signed-off-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ceph/mds_client.c

index a5de8e22629ba86071e15be8e3409c9fb3ebbe79..b7fd7d69be075cb2c6486b763f3a95f59a1d6b2f 100644 (file)
@@ -3428,6 +3428,9 @@ static void delayed_work(struct work_struct *work)
        dout("mdsc delayed_work\n");
        ceph_check_delayed_caps(mdsc);
 
+       if (mdsc->stopping)
+               return;
+
        mutex_lock(&mdsc->mutex);
        renew_interval = mdsc->mdsmap->m_session_timeout >> 2;
        renew_caps = time_after_eq(jiffies, HZ*renew_interval +
@@ -3752,7 +3755,16 @@ void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc)
 static void ceph_mdsc_stop(struct ceph_mds_client *mdsc)
 {
        dout("stop\n");
-       cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */
+       /*
+        * Make sure the delayed work stopped before releasing
+        * the resources.
+        *
+        * Because the cancel_delayed_work_sync() will only
+        * guarantee that the work finishes executing. But the
+        * delayed work will re-arm itself again after that.
+        */
+       flush_delayed_work(&mdsc->delayed_work);
+
        if (mdsc->mdsmap)
                ceph_mdsmap_destroy(mdsc->mdsmap);
        kfree(mdsc->sessions);