Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1584072 > unrolled thread

Re: scsi: BUG in scsi_init_io

Started byAl Viro <viro@ZenIV.linux.org.uk>
First post2017-02-19 08:20 +0100
Last post2017-02-19 19:00 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: scsi: BUG in scsi_init_io Al Viro <viro@ZenIV.linux.org.uk> - 2017-02-19 08:20 +0100
    Re: scsi: BUG in scsi_init_io Christoph Hellwig <hch@infradead.org> - 2017-02-19 18:30 +0100
    Re: scsi: BUG in scsi_init_io Linus Torvalds <torvalds@linux-foundation.org> - 2017-02-19 19:00 +0100

#1584072 — Re: scsi: BUG in scsi_init_io

FromAl Viro <viro@ZenIV.linux.org.uk>
Date2017-02-19 08:20 +0100
SubjectRe: scsi: BUG in scsi_init_io
Message-ID<tctWN-4r9-3@gated-at.bofh.it>
On Tue, Jan 31, 2017 at 07:41:51AM -0800, James Bottomley wrote:

> > Please-please-please, let's not use WARN for something that is not a
> > kernel bug and is user-triggerable.
> 
> It is a kernel bug and it should not be user triggerable, so it should
> have a warn_on or bug_on.  It means something called a data setup
> function with no data.  There's actually a root cause that patches like
> this won't fix, can we find it?

The root cause is unfixable without access to TARDIS and dose of
antipsychotics sufficient to prevent /dev/sg API creation.

What happens is that write to /dev/sg is given a request with non-zero
->iovec_count combined with zero ->dxfer_len.  Or with ->dxferp pointing
to an array full of empty iovecs.

AFAICS, the minimal fix would be something like this:

YAMissingSanityCheck in /dev/sg

write permission to /dev/sg shouldn't be equivalent to the ability to trigger
BUG_ON() while holding spinlocks...

Cc: stable@vger.kernel.org
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index dbe5b4b95df0..121de0aaa6ad 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1753,6 +1753,10 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)
 			return res;
 
 		iov_iter_truncate(&i, hp->dxfer_len);
+		if (!iov_iter_count(&i)) {
+			kfree(iov);
+			return -EINVAL;
+		}
 
 		res = blk_rq_map_user_iov(q, rq, md, &i, GFP_ATOMIC);
 		kfree(iov);

[toc] | [next] | [standalone]


#1584195

FromChristoph Hellwig <hch@infradead.org>
Date2017-02-19 18:30 +0100
Message-ID<tcDt7-1Jy-15@gated-at.bofh.it>
In reply to#1584072
On Sun, Feb 19, 2017 at 07:15:27AM +0000, Al Viro wrote:
> The root cause is unfixable without access to TARDIS and dose of
> antipsychotics sufficient to prevent /dev/sg API creation.
> 
> What happens is that write to /dev/sg is given a request with non-zero
> ->iovec_count combined with zero ->dxfer_len.  Or with ->dxferp pointing
> to an array full of empty iovecs.
> 
> AFAICS, the minimal fix would be something like this:
> 
> YAMissingSanityCheck in /dev/sg
> 
> write permission to /dev/sg shouldn't be equivalent to the ability to trigger
> BUG_ON() while holding spinlocks...

Looks fine to me:

Reviewed-by: Christoph Hellwig <hch@lst.de>

The other thing we really need to consider is to finally merge the
SG_IO implementations for /dev/sg with the common block layer one.

[toc] | [prev] | [next] | [standalone]


#1584214

FromLinus Torvalds <torvalds@linux-foundation.org>
Date2017-02-19 19:00 +0100
Message-ID<tcDW9-1Tw-7@gated-at.bofh.it>
In reply to#1584072
On Sat, Feb 18, 2017 at 11:15 PM, Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> AFAICS, the minimal fix would be something like this:

Applied, along with getting rid of the BUG_ON() that made this bug
much worse than it would have been without it.

                    Linus

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web