Skip to content

Commit 3526490

Browse files
author
Andreas Gruenbacher
committed
gfs2: Fix NULL pointer dereference in gfs2_log_flush
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 <[email protected]>
1 parent b011893 commit 3526490

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

fs/gfs2/log.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,8 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
11081108
lops_before_commit(sdp, tr);
11091109
if (gfs2_withdrawing_or_withdrawn(sdp))
11101110
goto out_withdraw;
1111-
gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE);
1111+
if (sdp->sd_jdesc)
1112+
gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE);
11121113
if (gfs2_withdrawing_or_withdrawn(sdp))
11131114
goto out_withdraw;
11141115

fs/gfs2/super.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ void gfs2_jindex_free(struct gfs2_sbd *sdp)
6767
sdp->sd_journals = 0;
6868
spin_unlock(&sdp->sd_jindex_spin);
6969

70+
down_write(&sdp->sd_log_flush_lock);
7071
sdp->sd_jdesc = NULL;
72+
up_write(&sdp->sd_log_flush_lock);
73+
7174
while (!list_empty(&list)) {
7275
jd = list_first_entry(&list, struct gfs2_jdesc, jd_list);
76+
BUG_ON(jd->jd_log_bio);
7377
gfs2_free_journal_extents(jd);
7478
list_del(&jd->jd_list);
7579
iput(jd->jd_inode);

0 commit comments

Comments
 (0)