All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] erofs: fix kvcalloc() misuse with __GFP_NOFAIL
@ 2023-01-06  3:19 ` Gao Xiang
  0 siblings, 0 replies; 7+ messages in thread
From: Gao Xiang @ 2023-01-06  3:19 UTC (permalink / raw)
  To: linux-erofs, Chao Yu, Yue Hu, Jeffle Xu
  Cc: LKML, Gao Xiang, syzbot+c3729cda01706a04fb98

As reported by syzbot [1], kvcalloc() cannot work with  __GFP_NOFAIL.
Let's use kcalloc() instead.

[1] https://lore.kernel.org/r/0000000000007796bd05f1852ec2@google.com
Reported-by: syzbot+c3729cda01706a04fb98@syzkaller.appspotmail.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/zdata.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index ccf7c55d477f..08e982c77985 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -1032,12 +1032,12 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 
 	if (!be->decompressed_pages)
 		be->decompressed_pages =
-			kvcalloc(be->nr_pages, sizeof(struct page *),
-				 GFP_KERNEL | __GFP_NOFAIL);
+			kcalloc(be->nr_pages, sizeof(struct page *),
+				GFP_KERNEL | __GFP_NOFAIL);
 	if (!be->compressed_pages)
 		be->compressed_pages =
-			kvcalloc(pclusterpages, sizeof(struct page *),
-				 GFP_KERNEL | __GFP_NOFAIL);
+			kcalloc(pclusterpages, sizeof(struct page *),
+				GFP_KERNEL | __GFP_NOFAIL);
 
 	z_erofs_parse_out_bvecs(be);
 	err2 = z_erofs_parse_in_bvecs(be, &overlapped);
-- 
2.24.4


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

* [PATCH] erofs: fix kvcalloc() misuse with __GFP_NOFAIL
@ 2023-01-06  3:19 ` Gao Xiang
  0 siblings, 0 replies; 7+ messages in thread
From: Gao Xiang @ 2023-01-06  3:19 UTC (permalink / raw)
  To: linux-erofs, Chao Yu, Yue Hu, Jeffle Xu
  Cc: Gao Xiang, LKML, syzbot+c3729cda01706a04fb98

As reported by syzbot [1], kvcalloc() cannot work with  __GFP_NOFAIL.
Let's use kcalloc() instead.

[1] https://lore.kernel.org/r/0000000000007796bd05f1852ec2@google.com
Reported-by: syzbot+c3729cda01706a04fb98@syzkaller.appspotmail.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/zdata.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index ccf7c55d477f..08e982c77985 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -1032,12 +1032,12 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 
 	if (!be->decompressed_pages)
 		be->decompressed_pages =
-			kvcalloc(be->nr_pages, sizeof(struct page *),
-				 GFP_KERNEL | __GFP_NOFAIL);
+			kcalloc(be->nr_pages, sizeof(struct page *),
+				GFP_KERNEL | __GFP_NOFAIL);
 	if (!be->compressed_pages)
 		be->compressed_pages =
-			kvcalloc(pclusterpages, sizeof(struct page *),
-				 GFP_KERNEL | __GFP_NOFAIL);
+			kcalloc(pclusterpages, sizeof(struct page *),
+				GFP_KERNEL | __GFP_NOFAIL);
 
 	z_erofs_parse_out_bvecs(be);
 	err2 = z_erofs_parse_in_bvecs(be, &overlapped);
-- 
2.24.4


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

* Re: [PATCH] erofs: fix kvcalloc() misuse with __GFP_NOFAIL
  2023-01-06  3:19 ` Gao Xiang
  (?)
@ 2023-01-06  5:06 ` Gao Xiang
  2023-01-09 10:34   ` Chao Yu
  -1 siblings, 1 reply; 7+ messages in thread
From: Gao Xiang @ 2023-01-06  5:06 UTC (permalink / raw)
  To: linux-erofs, Chao Yu, Yue Hu, Jeffle Xu; +Cc: LKML, syzbot+c3729cda01706a04fb98



On 2023/1/6 11:19, Gao Xiang wrote:
> As reported by syzbot [1], kvcalloc() cannot work with  __GFP_NOFAIL.
> Let's use kcalloc() instead.
> 
> [1] https://lore.kernel.org/r/0000000000007796bd05f1852ec2@google.com
> Reported-by: syzbot+c3729cda01706a04fb98@syzkaller.appspotmail.com

Fixes: fe3e5914e6dc ("erofs: try to leave (de)compressed_pages on stack if possible")
Fixes: 4f05687fd703 ("erofs: introduce struct z_erofs_decompress_backend")

> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
> ---
>   fs/erofs/zdata.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
> index ccf7c55d477f..08e982c77985 100644
> --- a/fs/erofs/zdata.c
> +++ b/fs/erofs/zdata.c
> @@ -1032,12 +1032,12 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
>   
>   	if (!be->decompressed_pages)
>   		be->decompressed_pages =
> -			kvcalloc(be->nr_pages, sizeof(struct page *),
> -				 GFP_KERNEL | __GFP_NOFAIL);
> +			kcalloc(be->nr_pages, sizeof(struct page *),
> +				GFP_KERNEL | __GFP_NOFAIL);
>   	if (!be->compressed_pages)
>   		be->compressed_pages =
> -			kvcalloc(pclusterpages, sizeof(struct page *),
> -				 GFP_KERNEL | __GFP_NOFAIL);
> +			kcalloc(pclusterpages, sizeof(struct page *),
> +				GFP_KERNEL | __GFP_NOFAIL);
>   
>   	z_erofs_parse_out_bvecs(be);
>   	err2 = z_erofs_parse_in_bvecs(be, &overlapped);

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

* Re: [PATCH] erofs: fix kvcalloc() misuse with __GFP_NOFAIL
  2023-01-06  5:06 ` Gao Xiang
@ 2023-01-09 10:34   ` Chao Yu
  2023-01-09 12:55     ` Gao Xiang
  0 siblings, 1 reply; 7+ messages in thread
From: Chao Yu @ 2023-01-09 10:34 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs, Yue Hu, Jeffle Xu
  Cc: LKML, syzbot+c3729cda01706a04fb98

On 2023/1/6 13:06, Gao Xiang wrote:
> 
> 
> On 2023/1/6 11:19, Gao Xiang wrote:
>> As reported by syzbot [1], kvcalloc() cannot work with  __GFP_NOFAIL.
>> Let's use kcalloc() instead.
>>
>> [1] https://lore.kernel.org/r/0000000000007796bd05f1852ec2@google.com
>> Reported-by: syzbot+c3729cda01706a04fb98@syzkaller.appspotmail.com
> 
> Fixes: fe3e5914e6dc ("erofs: try to leave (de)compressed_pages on stack if possible")
> Fixes: 4f05687fd703 ("erofs: introduce struct z_erofs_decompress_backend")
> 
>> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>> ---
>>   fs/erofs/zdata.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
>> index ccf7c55d477f..08e982c77985 100644
>> --- a/fs/erofs/zdata.c
>> +++ b/fs/erofs/zdata.c
>> @@ -1032,12 +1032,12 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
>>       if (!be->decompressed_pages)
>>           be->decompressed_pages =
>> -            kvcalloc(be->nr_pages, sizeof(struct page *),
>> -                 GFP_KERNEL | __GFP_NOFAIL);
>> +            kcalloc(be->nr_pages, sizeof(struct page *),
>> +                GFP_KERNEL | __GFP_NOFAIL);
>>       if (!be->compressed_pages)
>>           be->compressed_pages =
>> -            kvcalloc(pclusterpages, sizeof(struct page *),
>> -                 GFP_KERNEL | __GFP_NOFAIL);
>> +            kcalloc(pclusterpages, sizeof(struct page *),
>> +                GFP_KERNEL | __GFP_NOFAIL);

How about using kfree instead of kvfree for .decompressed_pages and
.compressed_pages memory release? It's trivial though.

Anyway, feel free to add:

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

>>       z_erofs_parse_out_bvecs(be);
>>       err2 = z_erofs_parse_in_bvecs(be, &overlapped);

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

* Re: [PATCH] erofs: fix kvcalloc() misuse with __GFP_NOFAIL
  2023-01-09 10:34   ` Chao Yu
@ 2023-01-09 12:55     ` Gao Xiang
  0 siblings, 0 replies; 7+ messages in thread
From: Gao Xiang @ 2023-01-09 12:55 UTC (permalink / raw)
  To: Chao Yu, linux-erofs, Yue Hu, Jeffle Xu; +Cc: LKML, syzbot+c3729cda01706a04fb98

Hi Chao,

On 2023/1/9 18:34, Chao Yu wrote:
> On 2023/1/6 13:06, Gao Xiang wrote:
>>
>>
>> On 2023/1/6 11:19, Gao Xiang wrote:
>>> As reported by syzbot [1], kvcalloc() cannot work with  __GFP_NOFAIL.
>>> Let's use kcalloc() instead.
>>>
>>> [1] https://lore.kernel.org/r/0000000000007796bd05f1852ec2@google.com
>>> Reported-by: syzbot+c3729cda01706a04fb98@syzkaller.appspotmail.com
>>
>> Fixes: fe3e5914e6dc ("erofs: try to leave (de)compressed_pages on stack if possible")
>> Fixes: 4f05687fd703 ("erofs: introduce struct z_erofs_decompress_backend")
>>
>>> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>>> ---
>>>   fs/erofs/zdata.c | 8 ++++----
>>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
>>> index ccf7c55d477f..08e982c77985 100644
>>> --- a/fs/erofs/zdata.c
>>> +++ b/fs/erofs/zdata.c
>>> @@ -1032,12 +1032,12 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
>>>       if (!be->decompressed_pages)
>>>           be->decompressed_pages =
>>> -            kvcalloc(be->nr_pages, sizeof(struct page *),
>>> -                 GFP_KERNEL | __GFP_NOFAIL);
>>> +            kcalloc(be->nr_pages, sizeof(struct page *),
>>> +                GFP_KERNEL | __GFP_NOFAIL);
>>>       if (!be->compressed_pages)
>>>           be->compressed_pages =
>>> -            kvcalloc(pclusterpages, sizeof(struct page *),
>>> -                 GFP_KERNEL | __GFP_NOFAIL);
>>> +            kcalloc(pclusterpages, sizeof(struct page *),
>>> +                GFP_KERNEL | __GFP_NOFAIL);
> 
> How about using kfree instead of kvfree for .decompressed_pages and
> .compressed_pages memory release? It's trivial though.

Yeah, thanks for catching! I will send v2 to fix these.

Thanks,
Gao Xiang

> 
> Anyway, feel free to add:
> 
> Reviewed-by: Chao Yu <chao@kernel.org>
> 
> Thanks,
> 
>>>       z_erofs_parse_out_bvecs(be);
>>>       err2 = z_erofs_parse_in_bvecs(be, &overlapped);

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

* [PATCH v2] erofs: fix kvcalloc() misuse with __GFP_NOFAIL
  2023-01-06  3:19 ` Gao Xiang
@ 2023-01-10  7:49   ` Gao Xiang
  -1 siblings, 0 replies; 7+ messages in thread
From: Gao Xiang @ 2023-01-10  7:49 UTC (permalink / raw)
  To: linux-erofs, Chao Yu, Yue Hu, Jeffle Xu
  Cc: LKML, Gao Xiang, syzbot+c3729cda01706a04fb98

As reported by syzbot [1], kvcalloc() cannot work with  __GFP_NOFAIL.
Let's use kcalloc() instead.

[1] https://lore.kernel.org/r/0000000000007796bd05f1852ec2@google.com
Reported-by: syzbot+c3729cda01706a04fb98@syzkaller.appspotmail.com
Fixes: fe3e5914e6dc ("erofs: try to leave (de)compressed_pages on stack if possible")
Fixes: 4f05687fd703 ("erofs: introduce struct z_erofs_decompress_backend")
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
changes since v1:
 - should use kfree() instead of kvfree() as well (Chao);
 - add Chao's r-v-b.

 fs/erofs/zdata.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index ccf7c55d477f..5200bb86e264 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -1032,12 +1032,12 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 
 	if (!be->decompressed_pages)
 		be->decompressed_pages =
-			kvcalloc(be->nr_pages, sizeof(struct page *),
-				 GFP_KERNEL | __GFP_NOFAIL);
+			kcalloc(be->nr_pages, sizeof(struct page *),
+				GFP_KERNEL | __GFP_NOFAIL);
 	if (!be->compressed_pages)
 		be->compressed_pages =
-			kvcalloc(pclusterpages, sizeof(struct page *),
-				 GFP_KERNEL | __GFP_NOFAIL);
+			kcalloc(pclusterpages, sizeof(struct page *),
+				GFP_KERNEL | __GFP_NOFAIL);
 
 	z_erofs_parse_out_bvecs(be);
 	err2 = z_erofs_parse_in_bvecs(be, &overlapped);
@@ -1085,7 +1085,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 	}
 	if (be->compressed_pages < be->onstack_pages ||
 	    be->compressed_pages >= be->onstack_pages + Z_EROFS_ONSTACK_PAGES)
-		kvfree(be->compressed_pages);
+		kfree(be->compressed_pages);
 	z_erofs_fill_other_copies(be, err);
 
 	for (i = 0; i < be->nr_pages; ++i) {
@@ -1104,7 +1104,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 	}
 
 	if (be->decompressed_pages != be->onstack_pages)
-		kvfree(be->decompressed_pages);
+		kfree(be->decompressed_pages);
 
 	pcl->length = 0;
 	pcl->partial = true;
-- 
2.24.4


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

* [PATCH v2] erofs: fix kvcalloc() misuse with __GFP_NOFAIL
@ 2023-01-10  7:49   ` Gao Xiang
  0 siblings, 0 replies; 7+ messages in thread
From: Gao Xiang @ 2023-01-10  7:49 UTC (permalink / raw)
  To: linux-erofs, Chao Yu, Yue Hu, Jeffle Xu
  Cc: Gao Xiang, LKML, syzbot+c3729cda01706a04fb98

As reported by syzbot [1], kvcalloc() cannot work with  __GFP_NOFAIL.
Let's use kcalloc() instead.

[1] https://lore.kernel.org/r/0000000000007796bd05f1852ec2@google.com
Reported-by: syzbot+c3729cda01706a04fb98@syzkaller.appspotmail.com
Fixes: fe3e5914e6dc ("erofs: try to leave (de)compressed_pages on stack if possible")
Fixes: 4f05687fd703 ("erofs: introduce struct z_erofs_decompress_backend")
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
changes since v1:
 - should use kfree() instead of kvfree() as well (Chao);
 - add Chao's r-v-b.

 fs/erofs/zdata.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index ccf7c55d477f..5200bb86e264 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -1032,12 +1032,12 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 
 	if (!be->decompressed_pages)
 		be->decompressed_pages =
-			kvcalloc(be->nr_pages, sizeof(struct page *),
-				 GFP_KERNEL | __GFP_NOFAIL);
+			kcalloc(be->nr_pages, sizeof(struct page *),
+				GFP_KERNEL | __GFP_NOFAIL);
 	if (!be->compressed_pages)
 		be->compressed_pages =
-			kvcalloc(pclusterpages, sizeof(struct page *),
-				 GFP_KERNEL | __GFP_NOFAIL);
+			kcalloc(pclusterpages, sizeof(struct page *),
+				GFP_KERNEL | __GFP_NOFAIL);
 
 	z_erofs_parse_out_bvecs(be);
 	err2 = z_erofs_parse_in_bvecs(be, &overlapped);
@@ -1085,7 +1085,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 	}
 	if (be->compressed_pages < be->onstack_pages ||
 	    be->compressed_pages >= be->onstack_pages + Z_EROFS_ONSTACK_PAGES)
-		kvfree(be->compressed_pages);
+		kfree(be->compressed_pages);
 	z_erofs_fill_other_copies(be, err);
 
 	for (i = 0; i < be->nr_pages; ++i) {
@@ -1104,7 +1104,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 	}
 
 	if (be->decompressed_pages != be->onstack_pages)
-		kvfree(be->decompressed_pages);
+		kfree(be->decompressed_pages);
 
 	pcl->length = 0;
 	pcl->partial = true;
-- 
2.24.4


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

end of thread, other threads:[~2023-01-10  7:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06  3:19 [PATCH] erofs: fix kvcalloc() misuse with __GFP_NOFAIL Gao Xiang
2023-01-06  3:19 ` Gao Xiang
2023-01-06  5:06 ` Gao Xiang
2023-01-09 10:34   ` Chao Yu
2023-01-09 12:55     ` Gao Xiang
2023-01-10  7:49 ` [PATCH v2] " Gao Xiang
2023-01-10  7:49   ` Gao Xiang

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.