From: Lars Ellenberg <lars.ellenberg@linbit.com>
To: Heloise <os@iscas.ac.cn>
Cc: linux-kernel@vger.kernel.org, philipp.reisner@linbit.com,
drbd-dev@lists.linbit.com
Subject: Re: [Drbd-dev] [PATCH] drbd:fix null pointer deref in _drbd_md_sync_page_io
Date: Wed, 26 Apr 2017 15:24:36 +0200 [thread overview]
Message-ID: <20170426132436.GA15697@soda.linbit> (raw)
In-Reply-To: <1493200177-10699-1-git-send-email-os@iscas.ac.cn>
On Wed, Apr 26, 2017 at 02:49:37AM -0700, Heloise wrote:
> The return value of bio_alloc_drbd can be NULL and is used without
No, apparently it cannot, because it is basically a mempool_alloc()
with GFP_NOIO, it may sleep, but it will loop "forever" and not return NULL.
So rather fix that nonsense in bio_alloc_drbd, see below:
Thanks,
Lars
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index 92c60cb..9ffd940 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -150,15 +150,10 @@ static const struct block_device_operations drbd_ops = {
struct bio *bio_alloc_drbd(gfp_t gfp_mask)
{
- struct bio *bio;
-
if (!drbd_md_io_bio_set)
return bio_alloc(gfp_mask, 1);
- bio = bio_alloc_bioset(gfp_mask, 1, drbd_md_io_bio_set);
- if (!bio)
- return NULL;
- return bio;
+ return bio_alloc_bioset(gfp_mask, 1, drbd_md_io_bio_set);
}
#ifdef __CHECKER__
> validation, which may cause null-pointer dereference, fix it.
>
> Signed-off-by: Heloise <os@iscas.ac.cn>
> ---
> drivers/block/drbd/drbd_actlog.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/block/drbd/drbd_actlog.c b/drivers/block/drbd/drbd_actlog.c
> index 8d7bcfa..d6bb30e 100644
> --- a/drivers/block/drbd/drbd_actlog.c
> +++ b/drivers/block/drbd/drbd_actlog.c
> @@ -151,6 +151,10 @@ static int _drbd_md_sync_page_io(struct drbd_device *device,
> op_flags |= REQ_SYNC;
>
> bio = bio_alloc_drbd(GFP_NOIO);
> + if (!bio) {
> + err = -ENOMEM;
> + return err;
> + }
> bio->bi_bdev = bdev->md_bdev;
> bio->bi_iter.bi_sector = sector;
> err = -EIO;
> --
> 2.1.0
parent reply other threads:[~2017-04-26 13:24 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <1493200177-10699-1-git-send-email-os@iscas.ac.cn>]
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=20170426132436.GA15697@soda.linbit \
--to=lars.ellenberg@linbit.com \
--cc=drbd-dev@lists.linbit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=os@iscas.ac.cn \
--cc=philipp.reisner@linbit.com \
/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