2013-05-28 07:31:38

by Kumar Amit Mehta

[permalink] [raw]
Subject: [PATCH] md: bcache: io.c: fix a potential NULL pointer dereference

bio_alloc_bioset returns NULL on failure. This fix adds a missing check
for potential NULL pointer dereferencing.

Signed-off-by: Kumar Amit Mehta <[email protected]>
---
drivers/md/bcache/io.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/md/bcache/io.c b/drivers/md/bcache/io.c
index 29f344b..4be2a07 100644
--- a/drivers/md/bcache/io.c
+++ b/drivers/md/bcache/io.c
@@ -98,6 +98,8 @@ struct bio *bch_bio_split(struct bio *bio, int sectors,

if (bio->bi_rw & REQ_DISCARD) {
ret = bio_alloc_bioset(gfp, 1, bs);
+ if (!ret)
+ return NULL;
idx = 0;
goto out;
}
--
1.7.10.4


2013-05-29 00:20:47

by Kent Overstreet

[permalink] [raw]
Subject: Re: [PATCH] md: bcache: io.c: fix a potential NULL pointer dereference

On Tue, May 28, 2013 at 12:31:15AM -0700, Kumar Amit Mehta wrote:
> bio_alloc_bioset returns NULL on failure. This fix adds a missing check
> for potential NULL pointer dereferencing.

Whoops, that's definitely a bug. Thanks, applied.

How'd you find it?

2013-05-29 05:36:43

by Kumar Amit Mehta

[permalink] [raw]
Subject: Re: [PATCH] md: bcache: io.c: fix a potential NULL pointer dereference

On Tue, May 28, 2013 at 05:20:41PM -0700, Kent Overstreet wrote:
> On Tue, May 28, 2013 at 12:31:15AM -0700, Kumar Amit Mehta wrote:
> > bio_alloc_bioset returns NULL on failure. This fix adds a missing check
> > for potential NULL pointer dereferencing.
>
> Whoops, that's definitely a bug. Thanks, applied.
>
> How'd you find it?

Using smatch[1]

[1] http://smatch.sourceforge.net/