f2fs: fix page leak in redirty_blocks
PATCH 1/1 f2fs: fix page leak in redirty_blocks
When find_lock_page return error, page in [i, page_len) will leak.
--- fs/f2fs/file.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
fs/f2fs/file.c +13 -0
@@ -3954,6 +3954,12 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)struct page *page;pgoff_t redirty_idx = page_idx;int i, page_len =0 , ret =0 ; +struct page **pages; + + pages =f2fs_kvzalloc (F2FS_I_SB (inode), +sizeof (struct page *) * len,GFP_NOFS ); +if (!pages) +return -ENOMEM ;page_cache_ra_unbounded (&ractl, len,0 );
@@ -3964,6 +3970,7 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)break ; } page_len++; + pages[i] = page; }for (i =0 ; i < page_len; i++, redirty_idx++) {
@@ -3975,8 +3982,14 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)set_page_dirty (page);f2fs_put_page (page,1 );f2fs_put_page (page,0 ); + pages[i] =NULL ; } +/* put pages[i, page_len) when error happens */ +for (; ret <0 && i < page_len; i++) +f2fs_put_page (pages[i],0 ); +kvfree (pages); +return ret; }
--
2.31.1
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 1 line · On 2022/5/28 17:35, Jack Qiu via Linux-f2fs-devel wrote:
When
find_lock_pagereturn error, page in [i,page_len) will leak.
I doubt it is impossible to fail in find_lock_page due to one extra reference count was added in previous read_cache_page().
Thanks,
Quoted 51 lines
Signed-off-by Jack Qiu <[email protected]>--- fs/f2fs/file.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)fs/f2fs/file.c +13
-1@@ -3954,6 +3954,12 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)struct page *page;pgoff_t redirty_idx = page_idx;int i, page_len =0 , ret =0 ; +struct page **pages; + + pages =f2fs_kvzalloc (F2FS_I_SB (inode), +sizeof (struct page *) * len,GFP_NOFS ); +if (!pages) +return -ENOMEM ;page_cache_ra_unbounded (&ractl, len,0 );@@ -3964,6 +3970,7 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)break ; } page_len++; + pages[i] = page; }for (i =0 ; i < page_len; i++, redirty_idx++) {@@ -3975,8 +3982,14 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)set_page_dirty (page);f2fs_put_page (page,1 );f2fs_put_page (page,0 ); + pages[i] =NULL ; } +/* put pages[i, page_len) when error happens */ +for (; ret <0 && i < page_len; i++) +f2fs_put_page (pages[i],0 ); +kvfree (pages); +return ret; } --2.31.1
Quoted 4 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 5 lines · Chao Yu
Quoted 1 line · On 2022/5/28 17:35, Jack Qiu via Linux-f2fs-devel wrote:
When
find_lock_pagereturn error, page in [i,page_len) will leak.I doubt it is impossible to fail in
find_lock_pagedue to one extra reference count was added in previousread_cache_page().
Thanks for review.
I'm not sure about it with limited knowledge. If it is true, maybe use f2fs_bug_on(sbi, !page) is better?
Quoted 54 lines
Thanks,
Quoted 51 lines
Signed-off-by Jack Qiu <[email protected]>---
fs/f2fs/file.c| 13 +++++++++++++1 file changed, 13 insertions(+)fs/f2fs/file.c +13
-0@@ -3954,6 +3954,12 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len) struct page *page; pgoff_t redirty_idx = page_idx; int i, page_len = 0, ret = 0; + struct page **pages; + + pages = f2fs_kvzalloc(F2FS_I_SB(inode), + sizeof(struct page *) * len, GFP_NOFS); + if (!pages) + return -ENOMEM; page_cache_ra_unbounded(&ractl, len, 0);@@ -3964,6 +3970,7 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len) break; } page_len++; + pages[i] = page; } for (i = 0; i < page_len; i++, redirty_idx++) {@@ -3975,8 +3982,14 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len) set_page_dirty(page); f2fs_put_page(page, 1); f2fs_put_page(page, 0); + pages[i] = NULL; } + /* put pages[i, page_len) when error happens */ + for (; ret < 0 && i < page_len; i++) + f2fs_put_page(pages[i], 0); + kvfree(pages); + return ret; }Signature · 1 line
2.31.1
Quoted 5 lines
Quoted 4 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel.
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 9 lines · Jack Qiu
Quoted 5 lines · Chao Yu
Quoted 1 line · On 2022/5/28 17:35, Jack Qiu via Linux-f2fs-devel wrote:
When
find_lock_pagereturn error, page in [i,page_len) will leak.I doubt it is impossible to fail in
find_lock_pagedue to one extra reference count was added in previousread_cache_page().Thanks for review.
I'm not sure about it with limited knowledge.
I guess something like those pages were pinned by adding extra reference, and find_lock_page() should never miss them...
Quoted 1 line
If it is true, maybe use
f2fs_bug_on(sbi, !page)is better?
I think so.
Thanks,
Quoted 55 lines
Quoted 55 lines
Thanks,
Quoted 51 lines
Signed-off-by Jack Qiu <[email protected]>--- fs/f2fs/file.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)fs/f2fs/file.c +13
-0@@ -3954,6 +3954,12 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len) struct page *page; pgoff_t redirty_idx = page_idx; int i, page_len = 0, ret = 0; + struct page **pages; + + pages = f2fs_kvzalloc(F2FS_I_SB(inode), + sizeof(struct page *) * len, GFP_NOFS); + if (!pages) + return -ENOMEM; page_cache_ra_unbounded(&ractl, len, 0);@@ -3964,6 +3970,7 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len) break; } page_len++; + pages[i] = page; } for (i = 0; i < page_len; i++, redirty_idx++) {@@ -3975,8 +3982,14 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len) set_page_dirty(page); f2fs_put_page(page, 1); f2fs_put_page(page, 0); + pages[i] = NULL; } + /* put pages[i, page_len) when error happens */ + for (; ret < 0 && i < page_len; i++) + f2fs_put_page(pages[i], 0); + kvfree(pages); + return ret; }Signature · 1 line
2.31.1
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel.
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel