lkml.org 
[lkml]   [2022]   [Mar]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] erofs: fix a potential NULL dereference of alloc_pages()
On Tue, Mar 22, 2022 at 04:08:12PM +0800, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> alloc_pages() returns the page on success or NULL if allocation fails,
> while set_page_private() will dereference `newpage`. So it is better to
> catch the memory error in case other errors happen.
>
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
> fs/erofs/zdata.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
> index 11c7a1a..36a5421 100644
> --- a/fs/erofs/zdata.c
> +++ b/fs/erofs/zdata.c
> @@ -735,11 +735,15 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
> struct page *const newpage =
> alloc_page(GFP_NOFS | __GFP_NOFAIL);
>

It's really a nofail allocation, am I missing something?

Thanks,
Gao Xiang

> - set_page_private(newpage, Z_EROFS_SHORTLIVED_PAGE);
> - err = z_erofs_attach_page(clt, newpage,
> - Z_EROFS_PAGE_TYPE_EXCLUSIVE);
> - if (!err)
> - goto retry;
> + if (!newpage) {
> + err = -ENOMEM;
> + } else {
> + set_page_private(newpage, Z_EROFS_SHORTLIVED_PAGE);
> + err = z_erofs_attach_page(clt, newpage,
> + Z_EROFS_PAGE_TYPE_EXCLUSIVE);
> + if (!err)
> + goto retry;
> + }
> }
>
> if (err)
> --

\
 
 \ /
  Last update: 2022-03-22 09:29    [W:0.170 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site