]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
gfs2: Fix unlikely race in gdlm_put_lock
authorAndreas Gruenbacher <agruenba@redhat.com>
Thu, 26 Mar 2026 06:34:27 +0000 (14:34 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 11 Apr 2026 12:16:38 +0000 (14:16 +0200)
[ Upstream commit 28c4d9bc0708956c1a736a9e49fee71b65deee81 ]

In gdlm_put_lock(), there is a small window of time in which the
DFL_UNMOUNT flag has been set but the lockspace hasn't been released,
yet.  In that window, dlm may still call gdlm_ast() and gdlm_bast().
To prevent it from dereferencing freed glock objects, only free the
glock if the lockspace has actually been released.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Andrew Price <anprice@redhat.com>
[ Minor context change fixed. ]
Signed-off-by: Robert Garcia <rob_garcia@163.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/gfs2/lock_dlm.c

index 588760c1a5da74c6d7ccf1fb481b6372f43b0233..4f44173e8a361fb4329a23a0d109f3f8e4f9a86b 100644 (file)
@@ -301,11 +301,6 @@ static void gdlm_put_lock(struct gfs2_glock *gl)
        gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
        gfs2_update_request_times(gl);
 
-       /* don't want to call dlm if we've unmounted the lock protocol */
-       if (test_bit(DFL_UNMOUNT, &ls->ls_recover_flags)) {
-               gfs2_glock_free(gl);
-               return;
-       }
        /* don't want to skip dlm_unlock writing the lvb when lock has one */
 
        if (test_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags) &&
@@ -322,6 +317,11 @@ again:
                goto again;
        }
 
+       if (error == -ENODEV) {
+               gfs2_glock_free(gl);
+               return;
+       }
+
        if (error) {
                fs_err(sdp, "gdlm_unlock %x,%llx err=%d\n",
                       gl->gl_name.ln_type,