linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: read page index before freeing
@ 2018-11-22 10:58 Pan Bian
  2018-11-22 11:21 ` Chao Yu
  2018-11-26  9:13 ` Chao Yu
  0 siblings, 2 replies; 9+ messages in thread
From: Pan Bian @ 2018-11-22 10:58 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel, linux-kernel, Pan Bian

The function truncate_node frees the page with f2fs_put_page. However,
the page index is read after that. So, the patch reads the index before
freeing the page.

Signed-off-by: Pan Bian <bianpan2016@163.com>
---
 fs/f2fs/node.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index d338740..88be946 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -826,6 +826,7 @@ static int truncate_node(struct dnode_of_data *dn)
 	struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
 	struct node_info ni;
 	int err;
+	pgoff_t index;
 
 	err = f2fs_get_node_info(sbi, dn->nid, &ni);
 	if (err)
@@ -845,10 +846,11 @@ static int truncate_node(struct dnode_of_data *dn)
 	clear_node_page_dirty(dn->node_page);
 	set_sbi_flag(sbi, SBI_IS_DIRTY);
 
+	index = dn->node_page->index;
 	f2fs_put_page(dn->node_page, 1);
 
 	invalidate_mapping_pages(NODE_MAPPING(sbi),
-			dn->node_page->index, dn->node_page->index);
+			index, index);
 
 	dn->node_page = NULL;
 	trace_f2fs_truncate_node(dn->inode, dn->nid, ni.blk_addr);
-- 
2.7.4



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

* Re: [PATCH] f2fs: read page index before freeing
  2018-11-22 10:58 [PATCH] f2fs: read page index before freeing Pan Bian
@ 2018-11-22 11:21 ` Chao Yu
  2018-11-22 12:02   ` Jaegeuk Kim
  2018-11-26  9:13 ` Chao Yu
  1 sibling, 1 reply; 9+ messages in thread
From: Chao Yu @ 2018-11-22 11:21 UTC (permalink / raw)
  To: Pan Bian, Jaegeuk Kim; +Cc: linux-f2fs-devel, linux-kernel

Hi Pan,

On 2018/11/22 18:58, Pan Bian wrote:
> The function truncate_node frees the page with f2fs_put_page. However,
> the page index is read after that. So, the patch reads the index before
> freeing the page.

Good catch!

It will be better to add:

Fixes: bf39c00a9a7f ("f2fs: drop obsolete node page when it is truncated")
Cc: <stable@vger.kernel.org>

> 
> Signed-off-by: Pan Bian <bianpan2016@163.com>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,


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

* Re: [PATCH] f2fs: read page index before freeing
  2018-11-22 11:21 ` Chao Yu
@ 2018-11-22 12:02   ` Jaegeuk Kim
  0 siblings, 0 replies; 9+ messages in thread
From: Jaegeuk Kim @ 2018-11-22 12:02 UTC (permalink / raw)
  To: Chao Yu; +Cc: Pan Bian, linux-f2fs-devel, linux-kernel

On 11/22, Chao Yu wrote:
> Hi Pan,
> 
> On 2018/11/22 18:58, Pan Bian wrote:
> > The function truncate_node frees the page with f2fs_put_page. However,
> > the page index is read after that. So, the patch reads the index before
> > freeing the page.
> 
> Good catch!

+1

> 
> It will be better to add:
> 
> Fixes: bf39c00a9a7f ("f2fs: drop obsolete node page when it is truncated")
> Cc: <stable@vger.kernel.org>
> 
> > 
> > Signed-off-by: Pan Bian <bianpan2016@163.com>
> 
> Reviewed-by: Chao Yu <yuchao0@huawei.com>

Done.

> 
> Thanks,

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

* Re: [PATCH] f2fs: read page index before freeing
  2018-11-22 10:58 [PATCH] f2fs: read page index before freeing Pan Bian
  2018-11-22 11:21 ` Chao Yu
@ 2018-11-26  9:13 ` Chao Yu
  2018-11-26 10:28   ` PanBian
  1 sibling, 1 reply; 9+ messages in thread
From: Chao Yu @ 2018-11-26  9:13 UTC (permalink / raw)
  To: Pan Bian, Jaegeuk Kim; +Cc: linux-f2fs-devel, linux-kernel

Hi Pan,

On 2018/11/22 18:58, Pan Bian wrote:
> The function truncate_node frees the page with f2fs_put_page. However,
> the page index is read after that. So, the patch reads the index before
> freeing the page.

I notice that you found another use-after-free bug in ext4, out of
curiosity, I'd like to ask how do you find those bugs? by tool or code review?

Thanks,


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

* Re: [PATCH] f2fs: read page index before freeing
  2018-11-26  9:13 ` Chao Yu
@ 2018-11-26 10:28   ` PanBian
  2018-11-26 11:07     ` Chao Yu
  0 siblings, 1 reply; 9+ messages in thread
From: PanBian @ 2018-11-26 10:28 UTC (permalink / raw)
  To: Chao Yu; +Cc: Jaegeuk Kim, linux-f2fs-devel, linux-kernel

On Mon, Nov 26, 2018 at 05:13:53PM +0800, Chao Yu wrote:
> Hi Pan,
> 
> On 2018/11/22 18:58, Pan Bian wrote:
> > The function truncate_node frees the page with f2fs_put_page. However,
> > the page index is read after that. So, the patch reads the index before
> > freeing the page.
> 
> I notice that you found another use-after-free bug in ext4, out of
> curiosity, I'd like to ask how do you find those bugs? by tool or code review?

I found such bugs by the aid of a tool I wrote recently. I designed a method 
to automatically find paired alloc/free functions. With such functions, I
wrote two checkers, one to check mismatched alloc/free bugs, the other to
check use-after-free and double-free bugs.

Best regards,
Pan Bian


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

* Re: [PATCH] f2fs: read page index before freeing
  2018-11-26 10:28   ` PanBian
@ 2018-11-26 11:07     ` Chao Yu
  2018-11-27  0:22       ` PanBian
  0 siblings, 1 reply; 9+ messages in thread
From: Chao Yu @ 2018-11-26 11:07 UTC (permalink / raw)
  To: PanBian; +Cc: Jaegeuk Kim, linux-f2fs-devel, linux-kernel

On 2018/11/26 18:28, PanBian wrote:
> On Mon, Nov 26, 2018 at 05:13:53PM +0800, Chao Yu wrote:
>> Hi Pan,
>>
>> On 2018/11/22 18:58, Pan Bian wrote:
>>> The function truncate_node frees the page with f2fs_put_page. However,
>>> the page index is read after that. So, the patch reads the index before
>>> freeing the page.
>>
>> I notice that you found another use-after-free bug in ext4, out of
>> curiosity, I'd like to ask how do you find those bugs? by tool or code review?
> 
> I found such bugs by the aid of a tool I wrote recently. I designed a method 
> to automatically find paired alloc/free functions. With such functions, I
> wrote two checkers, one to check mismatched alloc/free bugs, the other to
> check use-after-free and double-free bugs.

Excellent! Do you have any plan to open its source or announce it w/ binary
to linux kernel developers, I think w/ it we can help to improve kernel's
code quality efficiently.

Thanks,

> 
> Best regards,
> Pan Bian
> 
> 
> .
> 


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

* Re: [PATCH] f2fs: read page index before freeing
  2018-11-26 11:07     ` Chao Yu
@ 2018-11-27  0:22       ` PanBian
  2018-11-27  3:12         ` Chao Yu
  0 siblings, 1 reply; 9+ messages in thread
From: PanBian @ 2018-11-27  0:22 UTC (permalink / raw)
  To: Chao Yu; +Cc: Jaegeuk Kim, linux-f2fs-devel, linux-kernel

On Mon, Nov 26, 2018 at 07:07:08PM +0800, Chao Yu wrote:
> On 2018/11/26 18:28, PanBian wrote:
> > On Mon, Nov 26, 2018 at 05:13:53PM +0800, Chao Yu wrote:
> >> Hi Pan,
> >>
> >> On 2018/11/22 18:58, Pan Bian wrote:
> >>> The function truncate_node frees the page with f2fs_put_page. However,
> >>> the page index is read after that. So, the patch reads the index before
> >>> freeing the page.
> >>
> >> I notice that you found another use-after-free bug in ext4, out of
> >> curiosity, I'd like to ask how do you find those bugs? by tool or code review?
> > 
> > I found such bugs by the aid of a tool I wrote recently. I designed a method 
> > to automatically find paired alloc/free functions. With such functions, I
> > wrote two checkers, one to check mismatched alloc/free bugs, the other to
> > check use-after-free and double-free bugs.
> 
> Excellent! Do you have any plan to open its source or announce it w/ binary
> to linux kernel developers, I think w/ it we can help to improve kernel's
> code quality efficiently.

Yes. I am now writing a paper about the method. I will open the source code
as soon as I complete the paper and some optimizations.

Best,
Pan


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

* Re: [PATCH] f2fs: read page index before freeing
  2018-11-27  0:22       ` PanBian
@ 2018-11-27  3:12         ` Chao Yu
  2018-11-27  3:22           ` PanBian
  0 siblings, 1 reply; 9+ messages in thread
From: Chao Yu @ 2018-11-27  3:12 UTC (permalink / raw)
  To: PanBian; +Cc: Jaegeuk Kim, linux-f2fs-devel, linux-kernel

On 2018/11/27 8:22, PanBian wrote:
> On Mon, Nov 26, 2018 at 07:07:08PM +0800, Chao Yu wrote:
>> On 2018/11/26 18:28, PanBian wrote:
>>> On Mon, Nov 26, 2018 at 05:13:53PM +0800, Chao Yu wrote:
>>>> Hi Pan,
>>>>
>>>> On 2018/11/22 18:58, Pan Bian wrote:
>>>>> The function truncate_node frees the page with f2fs_put_page. However,
>>>>> the page index is read after that. So, the patch reads the index before
>>>>> freeing the page.
>>>>
>>>> I notice that you found another use-after-free bug in ext4, out of
>>>> curiosity, I'd like to ask how do you find those bugs? by tool or code review?
>>>
>>> I found such bugs by the aid of a tool I wrote recently. I designed a method 
>>> to automatically find paired alloc/free functions. With such functions, I
>>> wrote two checkers, one to check mismatched alloc/free bugs, the other to
>>> check use-after-free and double-free bugs.
>>
>> Excellent! Do you have any plan to open its source or announce it w/ binary
>> to linux kernel developers, I think w/ it we can help to improve kernel's
>> code quality efficiently.
> 
> Yes. I am now writing a paper about the method. I will open the source code
> as soon as I complete the paper and some optimizations.

Cool, if there is any progress, please let f2fs guys know, thank you in
advance. :)

Thanks,

> 
> Best,
> Pan
> 
> 
> .
> 


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

* Re: [PATCH] f2fs: read page index before freeing
  2018-11-27  3:12         ` Chao Yu
@ 2018-11-27  3:22           ` PanBian
  0 siblings, 0 replies; 9+ messages in thread
From: PanBian @ 2018-11-27  3:22 UTC (permalink / raw)
  To: Chao Yu; +Cc: Jaegeuk Kim, linux-f2fs-devel, linux-kernel

On Tue, Nov 27, 2018 at 11:12:40AM +0800, Chao Yu wrote:
> On 2018/11/27 8:22, PanBian wrote:
> > On Mon, Nov 26, 2018 at 07:07:08PM +0800, Chao Yu wrote:
> >> On 2018/11/26 18:28, PanBian wrote:
> >>> On Mon, Nov 26, 2018 at 05:13:53PM +0800, Chao Yu wrote:
> >>>> Hi Pan,
> >>>>
> >>>> On 2018/11/22 18:58, Pan Bian wrote:
> >>>>> The function truncate_node frees the page with f2fs_put_page. However,
> >>>>> the page index is read after that. So, the patch reads the index before
> >>>>> freeing the page.
> >>>>
> >>>> I notice that you found another use-after-free bug in ext4, out of
> >>>> curiosity, I'd like to ask how do you find those bugs? by tool or code review?
> >>>
> >>> I found such bugs by the aid of a tool I wrote recently. I designed a method 
> >>> to automatically find paired alloc/free functions. With such functions, I
> >>> wrote two checkers, one to check mismatched alloc/free bugs, the other to
> >>> check use-after-free and double-free bugs.
> >>
> >> Excellent! Do you have any plan to open its source or announce it w/ binary
> >> to linux kernel developers, I think w/ it we can help to improve kernel's
> >> code quality efficiently.
> > 
> > Yes. I am now writing a paper about the method. I will open the source code
> > as soon as I complete the paper and some optimizations.
> 
> Cool, if there is any progress, please let f2fs guys know, thank you in
> advance. :)

No problem. It's my honor to apply my tool to the Linux kernel.

> 
> Thanks,
> 


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

end of thread, other threads:[~2018-11-27  3:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-22 10:58 [PATCH] f2fs: read page index before freeing Pan Bian
2018-11-22 11:21 ` Chao Yu
2018-11-22 12:02   ` Jaegeuk Kim
2018-11-26  9:13 ` Chao Yu
2018-11-26 10:28   ` PanBian
2018-11-26 11:07     ` Chao Yu
2018-11-27  0:22       ` PanBian
2018-11-27  3:12         ` Chao Yu
2018-11-27  3:22           ` PanBian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).