linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars Ellenberg <lars@linbit.com>
To: Kent Overstreet <kmo@daterainc.com>
Cc: Neil Brown <neilb@suse.de>,
	linux-bcache@vger.kernel.org, linux-raid@vger.kernel.org,
	linux-kernel@vger.kernel.org, Lars Ellenberg <lars@linbit.com>
Subject: [PATCH] bcache: fix NULL pointer deref in blk_add_request_payload
Date: Wed, 19 Feb 2014 13:07:14 +0000	[thread overview]
Message-ID: <1392815234-27015-1-git-send-email-lars@linbit.com> (raw)

bch_generic_make_request_hack() tries to be smart,
and fake a bi_max_bvecs = bi_vcnt.

If those bios have been REQ_DISCARD, and get submitted to a driver
(md raid) that uses bio_clone, the clone will end up with bi_io_vec == NULL,
passed down the stack, end up in sd_prep_fn and blk_add_request_payload,
which then tries to use bio->bi_io_vec->page.

Fix: try to be even smarter in bch_generic_make_request_hack(),
and always pretend to have at least bi_max_vecs of 1,
unless the incoming bio was already created without a single bvec.

Signed-off-by: Lars Ellenberg <lars@linbit.com>
---
 drivers/md/bcache/io.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/bcache/io.c b/drivers/md/bcache/io.c
index 9056632..a638ac6 100644
--- a/drivers/md/bcache/io.c
+++ b/drivers/md/bcache/io.c
@@ -47,7 +47,7 @@ static void bch_generic_make_request_hack(struct bio *bio)
 	 *
 	 * To be taken out once immutable bvec stuff is in.
 	 */
-	bio->bi_max_vecs = bio->bi_vcnt;
+	bio->bi_max_vecs = bio->bi_vcnt ?: (bio->bi_io_vec ? 1 : 0);
 
 	generic_make_request(bio);
 }
-- 
1.7.10.4

             reply	other threads:[~2014-02-19 13:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-19 13:07 Lars Ellenberg [this message]
2014-02-19 13:18 ` [PATCH] bcache: fix NULL pointer deref in blk_add_request_payload Lars Ellenberg

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=1392815234-27015-1-git-send-email-lars@linbit.com \
    --to=lars@linbit.com \
    --cc=kmo@daterainc.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).