Skip to contentSkip to conversation

gfs2: fix double destroy_workqueue error

PATCH In review Julian Sun 2 participants 2 messages Aug 20, 2024 – Aug 21, 2024

Subsystems (2)
lore
Share & tools
lore

Julian Sun

author
#0 lore raw

PATCH v2 1/1 gfs2: fix double destroy_workqueue error

When gfs2_fill_super() fails, destroy_workqueue() is called within gfs2_gl_hash_clear(), and the subsequent code path calls destroy_workqueue() on the same work queue again.

This issue can be fixed by setting the work queue pointer to NULL after the first destroy_workqueue() call and checking for a NULL pointer before attempting to destroy the work queue again.

Reported-by [email protected]
Fixes 30e388d57367 ("gfs2: Switch to a per-filesystem glock workqueue")
---
 fs/gfs2/glock.c      | 1 +
 fs/gfs2/ops_fstype.c | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
fs/gfs2/glock.c +1 -0
index 32991cb22023..5838039d78e3 100644
@@ -2273,6 +2273,7 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp)
 	gfs2_free_dead_glocks(sdp);
 	glock_hash_walk(dump_glock_func, sdp);
 	destroy_workqueue(sdp->sd_glock_wq);
+	sdp->sd_glock_wq = NULL;
 }
 
 static const char *state2str(unsigned state)
fs/gfs2/ops_fstype.c +2 -1
index 0561edd6cc86..5c0e1b24d6ec 100644
@@ -1308,7 +1308,8 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
 fail_delete_wq:
 	destroy_workqueue(sdp->sd_delete_wq);
 fail_glock_wq:
-	destroy_workqueue(sdp->sd_glock_wq);
+	if (sdp->sd_glock_wq)
+		destroy_workqueue(sdp->sd_glock_wq);
 fail_free:
 	free_sbd(sdp);
 	sb->s_fs_info = NULL;
Signature · 1 line
2.39.2
#1 lore raw
Quoted 10 lines · Julian Sun

When gfs2_fill_super() fails, destroy_workqueue() is called within gfs2_gl_hash_clear(), and the subsequent code path calls destroy_workqueue() on the same work queue again.

This issue can be fixed by setting the work queue pointer to NULL after the first destroy_workqueue() call and checking for a NULL pointer before attempting to destroy the work queue again.

Applied now.

Thanks,
Andreas

Quoted 39 lines
Reported-by [email protected]
Fixes 30e388d57367 ("gfs2: Switch to a per-filesystem glock workqueue")
---
 fs/gfs2/glock.c      | 1 +
 fs/gfs2/ops_fstype.c | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
fs/gfs2/glock.c +1 -0
index 32991cb22023..5838039d78e3 100644
@@ -2273,6 +2273,7 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp)
        gfs2_free_dead_glocks(sdp);
        glock_hash_walk(dump_glock_func, sdp);
        destroy_workqueue(sdp->sd_glock_wq);
+       sdp->sd_glock_wq = NULL;
 }
 
 static const char *state2str(unsigned state)
fs/gfs2/ops_fstype.c +2 -2
index 0561edd6cc86..5c0e1b24d6ec 100644
@@ -1308,7 +1308,8 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
 fail_delete_wq:
        destroy_workqueue(sdp->sd_delete_wq);
 fail_glock_wq:
-       destroy_workqueue(sdp->sd_glock_wq);
+       if (sdp->sd_glock_wq)
+               destroy_workqueue(sdp->sd_glock_wq);
 fail_free:
        free_sbd(sdp);
        sb->s_fs_info = NULL;
--

2.39.2