]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
gfs2: Fix unlikely race in gdlm_put_lock
authorAndreas Gruenbacher <agruenba@redhat.com>
Wed, 6 Aug 2025 21:34:03 +0000 (23:34 +0200)
committerAndreas Gruenbacher <agruenba@redhat.com>
Fri, 12 Sep 2025 10:03:01 +0000 (12:03 +0200)
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>
fs/gfs2/lock_dlm.c

index 3c7db20ce5642902f9be38a289b330ef5fb9b98a..ae058b1f9435dc99b0b7ed0b52c39fb55608c459 100644 (file)
@@ -344,12 +344,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;
-       }
-
        /*
         * When the lockspace is released, all remaining glocks will be
         * unlocked automatically.  This is more efficient than unlocking them
@@ -379,6 +373,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,