linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] md: bcache: check the return value of kzalloc() in detached_dev_do_request()
@ 2022-02-25  8:20 Jia-Ju Bai
  2022-03-02 10:11 ` Coly Li
  0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2022-02-25  8:20 UTC (permalink / raw)
  To: colyli, kent.overstreet; +Cc: linux-bcache, linux-kernel, Jia-Ju Bai

The function kzalloc() in detached_dev_do_request() can fail, so its
return value should be checked.

Fixes: bc082a55d25c (bcache: fix inaccurate io state for detached bcache devices)
Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/md/bcache/request.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index d15aae6c51c1..1b5ccfa93b8c 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -1107,6 +1107,8 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
 	 * which would call closure_get(&dc->disk.cl)
 	 */
 	ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
+	if (!ddip)
+		return;
 	ddip->d = d;
 	/* Count on the bcache device */
 	ddip->orig_bdev = orig_bdev;
-- 
2.17.1


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

* Re: [PATCH] md: bcache: check the return value of kzalloc() in detached_dev_do_request()
  2022-02-25  8:20 [PATCH] md: bcache: check the return value of kzalloc() in detached_dev_do_request() Jia-Ju Bai
@ 2022-03-02 10:11 ` Coly Li
  2022-03-03  1:44   ` Jia-Ju Bai
  0 siblings, 1 reply; 3+ messages in thread
From: Coly Li @ 2022-03-02 10:11 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: linux-bcache, linux-kernel, kent.overstreet

On 2/25/22 4:20 PM, Jia-Ju Bai wrote:
> The function kzalloc() in detached_dev_do_request() can fail, so its
> return value should be checked.
>
> Fixes: bc082a55d25c (bcache: fix inaccurate io state for detached bcache devices)
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>   drivers/md/bcache/request.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
> index d15aae6c51c1..1b5ccfa93b8c 100644
> --- a/drivers/md/bcache/request.c
> +++ b/drivers/md/bcache/request.c
> @@ -1107,6 +1107,8 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
>   	 * which would call closure_get(&dc->disk.cl)
>   	 */
>   	ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);

Yes this is a potential problem, may result NULL pointer deference.


> +	if (!ddip)
> +		return;

The fix here is incorrect. A proper way to fix might be something like this,

     if (!ddip) {

         bio->bi_status = BLK_STS_RESOURCE;

         bio->bi_end_io(bio);

         return;

     }


The orignal patch will make I/O task be in sleep forever.

>   	ddip->d = d;
>   	/* Count on the bcache device */
>   	ddip->orig_bdev = orig_bdev;



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

* Re: [PATCH] md: bcache: check the return value of kzalloc() in detached_dev_do_request()
  2022-03-02 10:11 ` Coly Li
@ 2022-03-03  1:44   ` Jia-Ju Bai
  0 siblings, 0 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2022-03-03  1:44 UTC (permalink / raw)
  To: Coly Li; +Cc: linux-bcache, linux-kernel, kent.overstreet



On 2022/3/2 18:11, Coly Li wrote:
> On 2/25/22 4:20 PM, Jia-Ju Bai wrote:
>> The function kzalloc() in detached_dev_do_request() can fail, so its
>> return value should be checked.
>>
>> Fixes: bc082a55d25c (bcache: fix inaccurate io state for detached 
>> bcache devices)
>> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
>> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
>> ---
>>   drivers/md/bcache/request.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
>> index d15aae6c51c1..1b5ccfa93b8c 100644
>> --- a/drivers/md/bcache/request.c
>> +++ b/drivers/md/bcache/request.c
>> @@ -1107,6 +1107,8 @@ static void detached_dev_do_request(struct 
>> bcache_device *d, struct bio *bio,
>>        * which would call closure_get(&dc->disk.cl)
>>        */
>>       ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
>
> Yes this is a potential problem, may result NULL pointer deference.
>
>
>> +    if (!ddip)
>> +        return;
>
> The fix here is incorrect. A proper way to fix might be something like 
> this,
>
>     if (!ddip) {
>
>         bio->bi_status = BLK_STS_RESOURCE;
>
>         bio->bi_end_io(bio);
>
>         return;
>
>     }
>
>
> The orignal patch will make I/O task be in sleep forever.
>
>>       ddip->d = d;
>>       /* Count on the bcache device */
>>       ddip->orig_bdev = orig_bdev;
>

Hi Coly,

Thanks for the advice!
I will send a V2 patch.


Best wishes,
Jia-Ju Bai

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

end of thread, other threads:[~2022-03-03  1:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25  8:20 [PATCH] md: bcache: check the return value of kzalloc() in detached_dev_do_request() Jia-Ju Bai
2022-03-02 10:11 ` Coly Li
2022-03-03  1:44   ` Jia-Ju Bai

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).