* [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
@ 2026-06-17 9:01 Hongling Zeng
2026-06-17 10:51 ` Andrew Price
2026-08-24 15:45 ` Andreas Gruenbacher
0 siblings, 2 replies; 12+ messages in thread
From: Hongling Zeng @ 2026-06-17 9:01 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 [flat|nested] 12+ messages in thread
* Re: [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
2026-06-17 9:01 [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal() Hongling Zeng
@ 2026-06-17 10:51 ` Andrew Price
2026-06-18 1:50 ` Hongling Zeng
2026-08-24 14:20 ` Andreas Gruenbacher
2026-08-24 15:45 ` Andreas Gruenbacher
1 sibling, 2 replies; 12+ messages in thread
From: Andrew Price @ 2026-06-17 10:51 UTC (permalink / raw)
To: Hongling Zeng, agruenba, swhiteho, gregkh
Cc: gfs2, linux-kernel, zhongling0719
On 17/06/2026 10:01, Hongling Zeng wrote:
> 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.
When buffers are pinned their refcount is incremented and the brelse() here is only called for pinned buffers so I'm not convinced that there's a bug.
Callers of gfs2_remove_from_journal() also use the bh afterwards so if there was a use-after-free this patch wouldn't fix it.
Did you see a use-after-free in testing?
Andy
> 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);
> }
>
> /**
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
2026-06-17 10:51 ` Andrew Price
@ 2026-06-18 1:50 ` Hongling Zeng
2026-08-24 15:35 ` Andreas Gruenbacher
2026-08-24 14:20 ` Andreas Gruenbacher
1 sibling, 1 reply; 12+ messages in thread
From: Hongling Zeng @ 2026-06-18 1:50 UTC (permalink / raw)
To: Andrew Price, Hongling Zeng, agruenba, swhiteho, gregkh
Cc: gfs2, linux-kernel
在 2026年06月17日 18:51, Andrew Price 写道:
> On 17/06/2026 10:01, Hongling Zeng wrote:
>> 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.
> When buffers are pinned their refcount is incremented and the brelse() here is only called for pinned buffers so I'm not convinced that there's a bug.
>
> Callers of gfs2_remove_from_journal() also use the bh afterwards so if there was a use-after-free this patch wouldn't fix it.
>
> Did you see a use-after-free in testing?
>
> Andy
>
Thanks for your detailed explanation! this is not a real bug in
practice, the reference counting protects against real UAF.
I'm seeing smatch warnings :
fs/gfs2/log.c:1044 error: dereferencing freed memory 'bh'
fs/gfs2/log.c:1051 warn: passing freed memory 'bh'
And there are potential concerns:
1. Future maintainers might not understand the ref counting semantics
2. The code pattern (brelse then access) is error-prone
3. smatch warnings clutter output for real issues
>> 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);
>> }
>>
>> /**
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
2026-06-17 10:51 ` Andrew Price
2026-06-18 1:50 ` Hongling Zeng
@ 2026-08-24 14:20 ` Andreas Gruenbacher
2026-08-24 14:44 ` Andrew Price
1 sibling, 1 reply; 12+ messages in thread
From: Andreas Gruenbacher @ 2026-08-24 14:20 UTC (permalink / raw)
To: Andrew Price
Cc: Hongling Zeng, swhiteho, gregkh, gfs2, linux-kernel, zhongling0719
Andy,
On Wed, Jun 17, 2026 at 12:52 PM Andrew Price <anprice@redhat.com> wrote:
> On 17/06/2026 10:01, Hongling Zeng wrote:
> > 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.
>
> When buffers are pinned their refcount is incremented and the brelse() here is only called for pinned buffers so I'm not convinced that there's a bug.
Not sure what you mean by that. The patch still only calls brelse() on
buffers it unpins, it only changes when it does it.
> Callers of gfs2_remove_from_journal() also use the bh afterwards so if there was a use-after-free this patch wouldn't fix it.
Do we have any callers that do that when they don't clearly still hold
a reference? I don't think so.
In any case, if there are any callers that don't certainly hold an
extra reference, we need to be careful in gfs2_remove_from_journal().
This patch achieves that, so I'm inclined to merge it.
Thanks,
Andreas
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
2026-08-24 14:20 ` Andreas Gruenbacher
@ 2026-08-24 14:44 ` Andrew Price
0 siblings, 0 replies; 12+ messages in thread
From: Andrew Price @ 2026-08-24 14:44 UTC (permalink / raw)
To: Andreas Gruenbacher
Cc: Hongling Zeng, swhiteho, gregkh, gfs2, linux-kernel, zhongling0719
On 24/08/2026 15:20, Andreas Gruenbacher wrote:
> Andy,
>
> On Wed, Jun 17, 2026 at 12:52 PM Andrew Price <anprice@redhat.com> wrote:
>> On 17/06/2026 10:01, Hongling Zeng wrote:
>>> 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.
>>
>> When buffers are pinned their refcount is incremented and the brelse() here is only called for pinned buffers so I'm not convinced that there's a bug.
>
> Not sure what you mean by that. The patch still only calls brelse() on
> buffers it unpins, it only changes when it does it.
The context is not fresh in my mind but I suppose was trying to locate the UAF that the patch reportedly fixed and I couldn't find one.
>> Callers of gfs2_remove_from_journal() also use the bh afterwards so if there was a use-after-free this patch wouldn't fix it.
>
> Do we have any callers that do that when they don't clearly still hold
> a reference? I don't think so.
>
> In any case, if there are any callers that don't certainly hold an
> extra reference, we need to be careful in gfs2_remove_from_journal().
> This patch achieves that, so I'm inclined to merge it.
No objections here. I'd like the commit description to be clear about whether it's fixing a bug or just cleaning up a static analysis warning.
Andy
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
2026-06-18 1:50 ` Hongling Zeng
@ 2026-08-24 15:35 ` Andreas Gruenbacher
2026-08-25 1:35 ` Hongling Zeng
0 siblings, 1 reply; 12+ messages in thread
From: Andreas Gruenbacher @ 2026-08-24 15:35 UTC (permalink / raw)
To: Hongling Zeng
Cc: Andrew Price, Hongling Zeng, swhiteho, gregkh, gfs2, linux-kernel
Hi Hongling Zeng,
On Thu, Jun 18, 2026 at 3:58 AM Hongling Zeng <zhongling0719@126.com> wrote:
> 在 2026年06月17日 18:51, Andrew Price 写道:
> > On 17/06/2026 10:01, Hongling Zeng wrote:
> >> 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.
> > When buffers are pinned their refcount is incremented and the brelse() here is only called for pinned buffers so I'm not convinced that there's a bug.
> >
> > Callers of gfs2_remove_from_journal() also use the bh afterwards so if there was a use-after-free this patch wouldn't fix it.
> >
> > Did you see a use-after-free in testing?
> >
> > Andy
> >
> Thanks for your detailed explanation! this is not a real bug in
> practice, the reference counting protects against real UAF.
> I'm seeing smatch warnings :
>
> fs/gfs2/log.c:1044 error: dereferencing freed memory 'bh'
> fs/gfs2/log.c:1051 warn: passing freed memory 'bh'
a "make C=2 CHECK="smatch" fs/gfs2/" doesn't result in those messages.
How can I reproduce?
Thanks,
Andreas
> And there are potential concerns:
> 1. Future maintainers might not understand the ref counting semantics
> 2. The code pattern (brelse then access) is error-prone
> 3. smatch warnings clutter output for real issues
> >> 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);
> >> }
> >>
> >> /**
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
2026-06-17 9:01 [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal() Hongling Zeng
2026-06-17 10:51 ` Andrew Price
@ 2026-08-24 15:45 ` Andreas Gruenbacher
1 sibling, 0 replies; 12+ messages in thread
From: Andreas Gruenbacher @ 2026-08-24 15:45 UTC (permalink / raw)
To: Hongling Zeng
Cc: swhiteho, gregkh, rpeterso, gfs2, linux-kernel, zhongling0719
On Wed, Jun 17, 2026 at 11:02 AM Hongling Zeng <zenghongling@kylinos.cn> wrote:
> 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")
That commit by Bob looks suspicious: bh->b_private data is usually
freed by the ->release_folio address space operation, so there should
be no need for freeing bufdata objects here. (That has little to do
with your commit, of course.)
> 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 [flat|nested] 12+ messages in thread
* Re: [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
2026-08-24 15:35 ` Andreas Gruenbacher
@ 2026-08-25 1:35 ` Hongling Zeng
2026-08-25 12:27 ` Andreas Gruenbacher
0 siblings, 1 reply; 12+ messages in thread
From: Hongling Zeng @ 2026-08-25 1:35 UTC (permalink / raw)
To: Andreas Gruenbacher
Cc: Andrew Price, Hongling Zeng, swhiteho, gregkh, gfs2, linux-kernel
在 2026年08月24日 23:35, Andreas Gruenbacher 写道:
> Hi Hongling Zeng,
>
> On Thu, Jun 18, 2026 at 3:58 AM Hongling Zeng <zhongling0719@126.com> wrote:
>> 在 2026年06月17日 18:51, Andrew Price 写道:
>>> On 17/06/2026 10:01, Hongling Zeng wrote:
>>>> 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.
>>> When buffers are pinned their refcount is incremented and the brelse() here is only called for pinned buffers so I'm not convinced that there's a bug.
>>>
>>> Callers of gfs2_remove_from_journal() also use the bh afterwards so if there was a use-after-free this patch wouldn't fix it.
>>>
>>> Did you see a use-after-free in testing?
>>>
>>> Andy
>>>
>> Thanks for your detailed explanation! this is not a real bug in
>> practice, the reference counting protects against real UAF.
>> I'm seeing smatch warnings :
>>
>> fs/gfs2/log.c:1044 error: dereferencing freed memory 'bh'
>> fs/gfs2/log.c:1051 warn: passing freed memory 'bh'
> a "make C=2 CHECK="smatch" fs/gfs2/" doesn't result in those messages.
> How can I reproduce?
>
> Thanks,
> Andreas
>
Hi Andreas and Andy,
Thank you for the review. The smatch warnings were reported by the Intel
LKP test robot:
https://lore.kernel.org/all/202607110908.l7Owhul4-lkp@intel.com/
I will update the patch with a better commit message based on your
feedback,
clarifying that this is a defensive improvement to address the pattern
flagged by static analysis, rather than fixing a real-world
use-after-free
bug.
I'll send a v2 version .
>> And there are potential concerns:
>> 1. Future maintainers might not understand the ref counting semantics
>> 2. The code pattern (brelse then access) is error-prone
>> 3. smatch warnings clutter output for real issues
>>>> 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);
>>>> }
>>>>
>>>> /**
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal()
2026-08-25 1:35 ` Hongling Zeng
@ 2026-08-25 12:27 ` Andreas Gruenbacher
0 siblings, 0 replies; 12+ messages in thread
From: Andreas Gruenbacher @ 2026-08-25 12:27 UTC (permalink / raw)
To: Hongling Zeng
Cc: Andrew Price, Hongling Zeng, swhiteho, gregkh, gfs2, linux-kernel
On Tue, Aug 25, 2026 at 3:36 AM Hongling Zeng <zhongling0719@126.com> wrote:
> 在 2026年08月24日 23:35, Andreas Gruenbacher 写道:
> > Hi Hongling Zeng,
> >
> > On Thu, Jun 18, 2026 at 3:58 AM Hongling Zeng <zhongling0719@126.com> wrote:
> >> 在 2026年06月17日 18:51, Andrew Price 写道:
> >>> On 17/06/2026 10:01, Hongling Zeng wrote:
> >>>> 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.
> >>> When buffers are pinned their refcount is incremented and the brelse() here is only called for pinned buffers so I'm not convinced that there's a bug.
> >>>
> >>> Callers of gfs2_remove_from_journal() also use the bh afterwards so if there was a use-after-free this patch wouldn't fix it.
> >>>
> >>> Did you see a use-after-free in testing?
> >>>
> >>> Andy
> >>>
> >> Thanks for your detailed explanation! this is not a real bug in
> >> practice, the reference counting protects against real UAF.
> >> I'm seeing smatch warnings :
> >>
> >> fs/gfs2/log.c:1044 error: dereferencing freed memory 'bh'
> >> fs/gfs2/log.c:1051 warn: passing freed memory 'bh'
> > a "make C=2 CHECK="smatch" fs/gfs2/" doesn't result in those messages.
> > How can I reproduce?
> >
> > Thanks,
> > Andreas
> >
> Hi Andreas and Andy,
>
> Thank you for the review. The smatch warnings were reported by the Intel
> LKP test robot:
>
> https://lore.kernel.org/all/202607110908.l7Owhul4-lkp@intel.com/
>
> I will update the patch with a better commit message based on your feedback,
> clarifying that this is a defensive improvement to address the pattern
> flagged by static analysis, rather than fixing a real-world use-after-free
> bug.
>
> I'll send a v2 version.
I still cannot reproduce that result with smatch 0.6.4 (up from
v0.5.0-9185-gbcc58b9c) on Fedora 44, but I can live with this patch.
Thanks!
Andreas
> >> And there are potential concerns:
> >> 1. Future maintainers might not understand the ref counting semantics
> >> 2. The code pattern (brelse then access) is error-prone
> >> 3. smatch warnings clutter output for real issues
> >>>> 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);
> >>>> }
> >>>>
> >>>> /**
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [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, 0 replies; 12+ messages in thread
From: Greg KH @ 2026-06-01 5:46 UTC (permalink / raw)
To: Hongling Zeng
Cc: agruenba, swhiteho, rpeterso, gfs2, linux-kernel, zhongling0719
On Mon, Jun 01, 2026 at 10:18:12AM +0800, Hongling Zeng wrote:
> 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
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- You have marked a patch with a "Fixes:" tag for a commit that is in an
older released kernel, yet you do not have a cc: stable line in the
signed-off-by area at all, which means that the patch will not be
applied to any older kernel releases. To properly fix this, please
follow the documented rules in the
Documentation/process/stable-kernel-rules.rst file for how to resolve
this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 12+ messages in thread
* [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; 12+ 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 [flat|nested] 12+ 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; 12+ 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 [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-08-25 12:27 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-17 9:01 [PATCH] gfs2: Fix use-after-free in gfs2_remove_from_journal() Hongling Zeng
2026-06-17 10:51 ` Andrew Price
2026-06-18 1:50 ` Hongling Zeng
2026-08-24 15:35 ` Andreas Gruenbacher
2026-08-25 1:35 ` Hongling Zeng
2026-08-25 12:27 ` Andreas Gruenbacher
2026-08-24 14:20 ` Andreas Gruenbacher
2026-08-24 14:44 ` Andrew Price
2026-08-24 15:45 ` Andreas Gruenbacher
-- strict thread matches above, loose matches on Subject: below --
2026-06-01 2:18 Hongling Zeng
2026-06-01 5:46 ` Greg KH
2026-05-22 9:43 Hongling Zeng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®