]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
gfs2: No more self recovery
authorAndreas Gruenbacher <agruenba@redhat.com>
Wed, 16 Jul 2025 21:30:32 +0000 (23:30 +0200)
committerAndreas Gruenbacher <agruenba@redhat.com>
Wed, 16 Jul 2025 21:30:32 +0000 (23:30 +0200)
When a node withdraws and it turns out that it is the only node that has
the filesystem mounted, gfs2 currently tries to replay the local journal
to bring the filesystem back into a consistent state.  Not only is that
a very bad idea, it has also never worked because gfs2_recover_func()
will refuse to do anything during a withdraw.

However, before even getting to this point, gfs2_recover_func()
dereferences sdp->sd_jdesc->jd_inode.  This was a use-after-free before
commit 04133b607a78 ("gfs2: Prevent double iput for journal on error")
and is a NULL pointer dereference since then.

Simply get rid of self recovery to fix that.

Fixes: 601ef0d52e96 ("gfs2: Force withdraw to replay journals and wait for it to finish")
Reported-by: Chunjie Zhu <chunjie.zhu@cloud.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/util.c

index d5a1e63fa257e042234637eba7f10beef9ea1bff..24864a66074b2a92ecfb80384743fef0842a2485 100644 (file)
@@ -232,32 +232,23 @@ static void signal_our_withdraw(struct gfs2_sbd *sdp)
         */
        ret = gfs2_glock_nq(&sdp->sd_live_gh);
 
+       gfs2_glock_put(live_gl); /* drop extra reference we acquired */
+       clear_bit(SDF_WITHDRAW_RECOVERY, &sdp->sd_flags);
+
        /*
         * If we actually got the "live" lock in EX mode, there are no other
-        * nodes available to replay our journal. So we try to replay it
-        * ourselves. We hold the "live" glock to prevent other mounters
-        * during recovery, then just dequeue it and reacquire it in our
-        * normal SH mode. Just in case the problem that caused us to
-        * withdraw prevents us from recovering our journal (e.g. io errors
-        * and such) we still check if the journal is clean before proceeding
-        * but we may wait forever until another mounter does the recovery.
+        * nodes available to replay our journal.
         */
        if (ret == 0) {
-               fs_warn(sdp, "No other mounters found. Trying to recover our "
-                       "own journal jid %d.\n", sdp->sd_lockstruct.ls_jid);
-               if (gfs2_recover_journal(sdp->sd_jdesc, 1))
-                       fs_warn(sdp, "Unable to recover our journal jid %d.\n",
-                               sdp->sd_lockstruct.ls_jid);
-               gfs2_glock_dq_wait(&sdp->sd_live_gh);
-               gfs2_holder_reinit(LM_ST_SHARED,
-                                  LM_FLAG_NOEXP | GL_EXACT | GL_NOPID,
-                                  &sdp->sd_live_gh);
-               gfs2_glock_nq(&sdp->sd_live_gh);
+               fs_warn(sdp, "No other mounters found.\n");
+               /*
+                * We are about to release the lockspace.  By keeping live_gl
+                * locked here, we ensure that the next mounter coming along
+                * will be a "first" mounter which will perform recovery.
+                */
+               goto skip_recovery;
        }
 
-       gfs2_glock_put(live_gl); /* drop extra reference we acquired */
-       clear_bit(SDF_WITHDRAW_RECOVERY, &sdp->sd_flags);
-
        /*
         * At this point our journal is evicted, so we need to get a new inode
         * for it. Once done, we need to call gfs2_find_jhead which