All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drbd:fix null pointer deref in _drbd_md_sync_page_io
@ 2017-04-26  9:49 Heloise
  2017-04-26 13:24 ` Lars Ellenberg
  0 siblings, 1 reply; 2+ messages in thread
From: Heloise @ 2017-04-26  9:49 UTC (permalink / raw)
  To: philipp.reisner, lars.ellenberg; +Cc: drbd-dev, linux-kernel, Heloise

The return value of bio_alloc_drbd can be NULL and is used without
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

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

* Re: [PATCH] drbd:fix null pointer deref in _drbd_md_sync_page_io
  2017-04-26  9:49 [PATCH] drbd:fix null pointer deref in _drbd_md_sync_page_io Heloise
@ 2017-04-26 13:24 ` Lars Ellenberg
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ellenberg @ 2017-04-26 13:24 UTC (permalink / raw)
  To: Heloise; +Cc: philipp.reisner, drbd-dev, linux-kernel

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

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

end of thread, other threads:[~2017-04-26 13:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-26  9:49 [PATCH] drbd:fix null pointer deref in _drbd_md_sync_page_io Heloise
2017-04-26 13:24 ` Lars Ellenberg

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.