mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Coly Li <colyli@suse.de>
To: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org,
	kent.overstreet@gmail.com
Subject: Re: [PATCH] md: bcache: check the return value of kzalloc() in detached_dev_do_request()
Date: Wed, 2 Mar 2022 18:11:29 +0800	[thread overview]
Message-ID: <f9a07f10-9d9d-de94-64b9-acf722cea8cd@suse.de> (raw)
In-Reply-To: <20220225082048.19524-1-baijiaju1990@gmail.com>

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;



  reply	other threads:[~2022-03-02 10:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25  8:20 Jia-Ju Bai
2022-03-02 10:11 ` Coly Li [this message]
2022-03-03  1:44   ` Jia-Ju Bai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f9a07f10-9d9d-de94-64b9-acf722cea8cd@suse.de \
    --to=colyli@suse.de \
    --cc=baijiaju1990@gmail.com \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®