linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Chris Leech <cleech@redhat.com>, Ming Lei <tom.leiming@gmail.com>,
	Dave Chinner <david@fromorbit.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Lee Duncan <lduncan@suse.com>,
	open-iscsi@googlegroups.com,
	Linux SCSI List <linux-scsi@vger.kernel.org>,
	linux-block <linux-block@vger.kernel.org>,
	axboe@fb.com, mst@redhat.com
Subject: Re: [4.10, panic, regression] iscsi: null pointer deref at iscsi_tcp_segment_done+0x20d/0x2e0
Date: Fri, 23 Dec 2016 11:00:14 +0100	[thread overview]
Message-ID: <20161223100014.GA29467@lst.de> (raw)
In-Reply-To: <20161223000356.dxwkgsei32w7hc4f@straylight.hirudinean.org>

On Thu, Dec 22, 2016 at 04:03:56PM -0800, Chris Leech wrote:
> Of course, looks like I've screwed up my bisect run on this so I'm still
> taking a look.  It triggers for me with 'hdparm -B /dev/vda' but may
> also depend on kernel configuration.
> 
> I started with the fedora rawhide config with a lot of debug on and
> trimed it down with a localmodconfig run in the VM to speed up rebuilds.

I think the configuration dependency is CONFIG_HAVE_ARCH_VMAP_STACK,
I've just reproduce the issue with it, and the backtrace points to
__virtblk_add_req when setting up the sense buffer.   And it turns out
that blk_execute_rq tries to do I/O to the on-stack sense buffer.
At least SCSI always has a kmalloced sense buffer, so I guess we'll
need something similar for virtio_blk for now.  For 4.11 I plan to
rework how BLOCK_PC commands work entirely, so hopefull we can make
the sense buffer handling a lot less wasteful.

---
>From 0a77bc424ed907c1e99b4756bb498370b498183a Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Fri, 23 Dec 2016 10:57:06 +0100
Subject: virtio_blk: avoid DMA to stack for the sense buffer

Most users of BLOCK_PC requests allocate the sense buffer on the stack,
so to avoid DMA to the stack copy them to a field in the heap allocated
virtblk_req structure.  Without that any attempt at SCSI passthrough I/O,
including the SG_IO ioctl from userspace will crash the kernel.  Note that
this includes running tools like hdparm even when the host does not have
SCSI passthrough enabled.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/virtio_blk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 5545a67..3c3b8f6 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -56,6 +56,7 @@ struct virtblk_req {
 	struct virtio_blk_outhdr out_hdr;
 	struct virtio_scsi_inhdr in_hdr;
 	u8 status;
+	u8 sense[SCSI_SENSE_BUFFERSIZE];
 	struct scatterlist sg[];
 };
 
@@ -102,7 +103,8 @@ static int __virtblk_add_req(struct virtqueue *vq,
 	}
 
 	if (type == cpu_to_virtio32(vq->vdev, VIRTIO_BLK_T_SCSI_CMD)) {
-		sg_init_one(&sense, vbr->req->sense, SCSI_SENSE_BUFFERSIZE);
+		memcpy(vbr->sense, vbr->req->sense, SCSI_SENSE_BUFFERSIZE);
+		sg_init_one(&sense, vbr->sense, SCSI_SENSE_BUFFERSIZE);
 		sgs[num_out + num_in++] = &sense;
 		sg_init_one(&inhdr, &vbr->in_hdr, sizeof(vbr->in_hdr));
 		sgs[num_out + num_in++] = &inhdr;
-- 
2.1.4


  reply	other threads:[~2016-12-23 10:00 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20161214222411.GH4326@dastard>
     [not found] ` <20161214222953.GI4326@dastard>
     [not found]   ` <20161216185906.t2wmrr6wqjdsrduw@straylight.hirudinean.org>
2016-12-21 22:16     ` [4.10, panic, regression] iscsi: null pointer deref at iscsi_tcp_segment_done+0x20d/0x2e0 Dave Chinner
2016-12-21 23:19       ` Linus Torvalds
2016-12-22  0:13         ` Chris Leech
2016-12-22  5:13           ` Dave Chinner
2016-12-22  5:46             ` Linus Torvalds
2016-12-22  6:50               ` Dave Chinner
2016-12-22 18:50                 ` Chris Leech
2016-12-22 23:53                   ` Ming Lei
     [not found]                     ` <CACVXFVOGoh+AEGSSMsbxfdAjZQS5k_t+7uR-+qwusm0vfauHEA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-12-23  0:03                       ` Chris Leech
2016-12-23 10:00                         ` Christoph Hellwig [this message]
2016-12-23 19:42                           ` Linus Torvalds
2016-12-24  2:45                             ` Jens Axboe
     [not found]                               ` <fadbf3d2-23c1-f822-cf0f-50182227a2dc-b10kYP2dOMg@public.gmane.org>
2016-12-24  9:49                                 ` Christoph Hellwig
     [not found]                             ` <CA+55aFxA1LE+4jdR8YXZyRVJ-MpOCUVob=ESBsMPuW=Qb=px-A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-12-24 10:07                               ` Christoph Hellwig
     [not found]                                 ` <20161224100756.GA16741-jcswGhMUV9g@public.gmane.org>
2016-12-24 13:17                                   ` Hannes Reinecke
     [not found]                                     ` <a9fc4c0b-8521-84cc-66f6-48396c095539-l3A5Bk7waGM@public.gmane.org>
2016-12-24 13:19                                       ` Christoph Hellwig
2017-01-04 14:07                                       ` Christoph Hellwig
2016-12-22 20:22               ` Hugh Dickins
2016-12-23  7:32                 ` Johannes Weiner
2016-12-23  8:33                   ` Johannes Weiner
     [not found]                     ` <20161223083329.GA13952-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
2017-01-02 21:11                       ` Johannes Weiner
2017-01-03 12:28                         ` Jan Kara
2017-01-04 15:26                           ` Laurence Oberman
     [not found]                             ` <584380074.12440338.1483543569131.JavaMail.zimbra-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-01-04 17:38                               ` Laurence Oberman
     [not found]                           ` <20170103122825.GC3780-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2017-01-08  2:02                             ` Johannes Weiner
     [not found]                               ` <20170108020200.GA16312-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
2017-01-08  2:17                                 ` Linus Torvalds
2017-01-09 20:30                                 ` Jan Kara
2017-01-09 20:45                                   ` Johannes Weiner
2016-12-22  6:28             ` Dave Chinner
2016-12-22  6:18         ` Christoph Hellwig
2016-12-22  6:30           ` Dave Chinner
2016-12-22  6:36             ` Christoph Hellwig

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=20161223100014.GA29467@lst.de \
    --to=hch@lst.de \
    --cc=axboe@fb.com \
    --cc=cleech@redhat.com \
    --cc=david@fromorbit.com \
    --cc=hannes@cmpxchg.org \
    --cc=lduncan@suse.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=open-iscsi@googlegroups.com \
    --cc=tom.leiming@gmail.com \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).