All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
@ 2026-06-01  2:18 Hongling Zeng
  2026-06-01  5:46 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Hongling Zeng @ 2026-06-01  2:18 UTC (permalink / raw)
  To: agruenba, swhiteho, gregkh, rpeterso
  Cc: gfs2, linux-kernel, zhongling0719, Hongling Zeng

The function calls brelse(bh) but then continues to access
the buffer head through bh->b_private, clear_buffer_dirty(),
and clear_buffer_uptodate().

After brelse() decreases the reference count, the buffer head
may be freed, making the subsequent accesses use-after-free.

Fix by moving the brelse(bh) call to the end of the function,
after all accesses to bh have been completed.

Fixes: e93b100931a4 ("GFS2: Fix slab memory leak in gfs2_bufdata")
Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
 fs/gfs2/log.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 78bba8cc10b8..a92c84146de9 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -1038,7 +1038,6 @@ void gfs2_remove_from_journal(struct buffer_head *bh, int meta)
 			set_bit(TR_TOUCHED, &tr->tr_flags);
 		}
 		was_pinned = 1;
-		brelse(bh);
 	}
 	if (bd) {
 		if (bd->bd_tr) {
@@ -1056,6 +1055,8 @@ void gfs2_remove_from_journal(struct buffer_head *bh, int meta)
 	}
 	clear_buffer_dirty(bh);
 	clear_buffer_uptodate(bh);
+	if (was_pinned)
+		brelse(bh);
 }
 
 /**
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread
* [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
@ 2026-05-22  9:43 Hongling Zeng
  0 siblings, 0 replies; 3+ messages in thread
From: Hongling Zeng @ 2026-05-22  9:43 UTC (permalink / raw)
  To: agruenba, swhiteho, gregkh, rpeterso
  Cc: gfs2, linux-kernel, zhongling0719, Hongling Zeng

The function calls brelse(bh) but then continues to access
the buffer head through bh->b_private, clear_buffer_dirty(),
and clear_buffer_uptodate().

After brelse() decreases the reference count, the buffer head
may be freed, making the subsequent accesses use-after-free.

Fix by moving the brelse(bh) call to the end of the function,
after all accesses to bh have been completed.

Fixes: e93b100931a4 ("GFS2: Fix slab memory leak in gfs2_bufdata")
Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
 fs/gfs2/log.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 78bba8cc10b8..a92c84146de9 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -1038,7 +1038,6 @@ void gfs2_remove_from_journal(struct buffer_head *bh, int meta)
 			set_bit(TR_TOUCHED, &tr->tr_flags);
 		}
 		was_pinned = 1;
-		brelse(bh);
 	}
 	if (bd) {
 		if (bd->bd_tr) {
@@ -1056,6 +1055,8 @@ void gfs2_remove_from_journal(struct buffer_head *bh, int meta)
 	}
 	clear_buffer_dirty(bh);
 	clear_buffer_uptodate(bh);
+	if (was_pinned)
+		brelse(bh);
 }
 
 /**
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-01  5:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-01  2:18 [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal() Hongling Zeng
2026-06-01  5:46 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2026-05-22  9:43 Hongling Zeng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.