gfs2: Fix NULL pointer dereference in gfs2_log_flush
authorAndreas Gruenbacher <agruenba@redhat.com>
Mon, 11 Mar 2024 14:51:59 +0000 (15:51 +0100)
committerAndreas Gruenbacher <agruenba@redhat.com>
Tue, 9 Apr 2024 16:35:57 +0000 (18:35 +0200)
In gfs2_jindex_free(), set sdp->sd_jdesc to NULL under the log flush
lock to provide exclusion against gfs2_log_flush().

In gfs2_log_flush(), check if sdp->sd_jdesc is non-NULL before
dereferencing it.  Otherwise, we could run into a NULL pointer
dereference when outstanding glock work races with an unmount
(glock_work_func -> run_queue -> do_xmote -> inode_go_sync ->
gfs2_log_flush).

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/log.c
fs/gfs2/super.c

index 8cddf955ebc0cca9d4de9e7577f081d8b947ac81..a6dd68b458cec89af6129dea9caa2ca44d8dc900 100644 (file)
@@ -1108,7 +1108,8 @@ repeat:
        lops_before_commit(sdp, tr);
        if (gfs2_withdrawing_or_withdrawn(sdp))
                goto out_withdraw;
-       gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE);
+       if (sdp->sd_jdesc)
+               gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE);
        if (gfs2_withdrawing_or_withdrawn(sdp))
                goto out_withdraw;
 
index e5f79466340d2aa3d5eb76262e0c04b1d8cfd9d5..9de789b78bc50077b8dd8ab2e190d7d1d4a8ca31 100644 (file)
@@ -67,9 +67,13 @@ void gfs2_jindex_free(struct gfs2_sbd *sdp)
        sdp->sd_journals = 0;
        spin_unlock(&sdp->sd_jindex_spin);
 
+       down_write(&sdp->sd_log_flush_lock);
        sdp->sd_jdesc = NULL;
+       up_write(&sdp->sd_log_flush_lock);
+
        while (!list_empty(&list)) {
                jd = list_first_entry(&list, struct gfs2_jdesc, jd_list);
+               BUG_ON(jd->jd_log_bio);
                gfs2_free_journal_extents(jd);
                list_del(&jd->jd_list);
                iput(jd->jd_inode);