Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1707367 > unrolled thread
| Started by | Benjamin Block <bblock@linux.vnet.ibm.com> |
|---|---|
| First post | 2017-08-09 16:20 +0200 |
| Last post | 2017-08-10 11:40 +0200 |
| Articles | 7 — 3 participants |
Back to article view | Back to linux.kernel
[RFC PATCH 0/6] bsg: fix regression resulting in panics when sending commands via BSG and some sanity cleanups Benjamin Block <bblock@linux.vnet.ibm.com> - 2017-08-09 16:20 +0200
[RFC PATCH 5/6] bsg: reduce unnecessary arguments for bsg_map_hdr() Benjamin Block <bblock@linux.vnet.ibm.com> - 2017-08-09 16:20 +0200
Re: [RFC PATCH 5/6] bsg: reduce unnecessary arguments for bsg_map_hdr() Johannes Thumshirn <jthumshirn@suse.de> - 2017-08-10 10:30 +0200
Re: [RFC PATCH 5/6] bsg: reduce unnecessary arguments for bsg_map_hdr() Christoph Hellwig <hch@lst.de> - 2017-08-10 11:40 +0200
Re: [RFC PATCH 5/6] bsg: reduce unnecessary arguments for bsg_map_hdr() Benjamin Block <bblock@linux.vnet.ibm.com> - 2017-08-11 00:30 +0200
[RFC PATCH 3/6] bsg: scsi-transport: add compile-tests to prevent reply-buffer overflows Benjamin Block <bblock@linux.vnet.ibm.com> - 2017-08-09 16:20 +0200
Re: [RFC PATCH 3/6] bsg: scsi-transport: add compile-tests to prevent reply-buffer overflows Christoph Hellwig <hch@lst.de> - 2017-08-10 11:40 +0200
| From | Benjamin Block <bblock@linux.vnet.ibm.com> |
|---|---|
| Date | 2017-08-09 16:20 +0200 |
| Subject | [RFC PATCH 0/6] bsg: fix regression resulting in panics when sending commands via BSG and some sanity cleanups |
| Message-ID | <ucA01-8w8-5@gated-at.bofh.it> |
Hello all,
Steffen noticed recently that we have a regression in the BSG code that
prevents us from sending any traffic over this interface. After I
researched this a bit, it turned out that this affects not only zFCP, but
likely all LLDs that implements the BSG API. This was introduced in 4.11
(details in Patch 1 of this series).
I imagine the regression happened because of some very "unfortunate"
variable- namings. I can not fix them, as they involve the base struct
request, but I tried to add some cleanups that should make the
relationships between stuff more visible in the future I hope.
Patch 1 - Regression Fix; Also tagged for stable
Patch 2-6 - Cleanups
I tagged this as RFC. Patches 2-6 are a 'nice to have' IMO, Patch 1 is
obviously necessary, and if it is OK, I can re-send it separately if
necessary. If you don't like the changes in the other patches, I don't mind
dropping them.
I am not sure about Patch 4. It certainly works, but it changes
user-visible behavior, in what I believe is within the behavior described
by the SG interface. It makes the different methods of how BSG passes
commands down to the LLDs more conform with each other - even though I
can't make them the exact same. More details in the patch description.
I rebased the series on Jens' for-next and I have function-tested the
series on s390x's zFCP with the tools provided in the zfcp HBA API library
(https://www.ibm.com/developerworks/linux/linux390/zfcp-hbaapi.html) and
some custom code to test the read/write interface of BSG.
Reviews are more than welcome :)
Beste Grüße / Best regards,
- Benjamin Block
Benjamin Block (6):
bsg: fix kernel panic resulting from missing allocation of a
reply-buffer
bsg: assign sense_len instead of fixed SCSI_SENSE_BUFFERSIZE
bsg: scsi-transport: add compile-tests to prevent reply-buffer
overflows
bsg: refactor ioctl to use regular BSG-command infrastructure for
SG_IO
bsg: reduce unecessary arguments for bsg_map_hdr()
bsg: reduce unecessary arguments for blk_complete_sgv4_hdr_rq()
block/bsg-lib.c | 4 +-
block/bsg.c | 90 ++++++++++++++++++++++---------------
drivers/scsi/scsi_transport_fc.c | 3 ++
drivers/scsi/scsi_transport_iscsi.c | 3 ++
include/linux/bsg-lib.h | 2 +
5 files changed, 65 insertions(+), 37 deletions(-)
--
2.12.2
[toc] | [next] | [standalone]
| From | Benjamin Block <bblock@linux.vnet.ibm.com> |
|---|---|
| Date | 2017-08-09 16:20 +0200 |
| Subject | [RFC PATCH 5/6] bsg: reduce unnecessary arguments for bsg_map_hdr() |
| Message-ID | <ucA02-8w8-17@gated-at.bofh.it> |
| In reply to | #1707367 |
Since struct bsg_command is now used in every calling case, we don't
need separation of arguments anymore that are contained in the same
bsg_command.
Signed-off-by: Benjamin Block <bblock@linux.vnet.ibm.com>
---
block/bsg.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/block/bsg.c b/block/bsg.c
index 8517361a9b3f..6ee2ffca808a 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -212,11 +212,12 @@ bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *op)
* map sg_io_v4 to a request.
*/
static struct request *
-bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
- u8 *reply_buffer)
+bsg_map_hdr(struct bsg_device *bd, struct bsg_command *bc,
+ fmode_t has_write_perm)
{
struct request_queue *q = bd->queue;
struct request *rq, *next_rq = NULL;
+ struct sg_io_v4 *hdr = &bc->hdr;
int ret;
unsigned int op, dxfer_len;
void __user *dxferp = NULL;
@@ -244,7 +245,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
if (IS_ERR(rq))
return rq;
- ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd, reply_buffer,
+ ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd, bc->reply_buffer,
has_write_perm);
if (ret)
goto out;
@@ -633,8 +634,7 @@ static int __bsg_write(struct bsg_device *bd, const char __user *buf,
/*
* get a request, fill in the blanks, and add to request queue
*/
- rq = bsg_map_hdr(bd, &bc->hdr, has_write_perm,
- bc->reply_buffer);
+ rq = bsg_map_hdr(bd, bc, has_write_perm);
if (IS_ERR(rq)) {
ret = PTR_ERR(rq);
rq = NULL;
@@ -934,8 +934,7 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
goto sg_io_out;
}
- bc->rq = bsg_map_hdr(bd, &bc->hdr, file->f_mode & FMODE_WRITE,
- bc->reply_buffer);
+ bc->rq = bsg_map_hdr(bd, bc, file->f_mode & FMODE_WRITE);
if (IS_ERR(bc->rq)) {
ret = PTR_ERR(bc->rq);
goto sg_io_out;
--
2.12.2
[toc] | [prev] | [next] | [standalone]
| From | Johannes Thumshirn <jthumshirn@suse.de> |
|---|---|
| Date | 2017-08-10 10:30 +0200 |
| Subject | Re: [RFC PATCH 5/6] bsg: reduce unnecessary arguments for bsg_map_hdr() |
| Message-ID | <ucR0R-2S8-9@gated-at.bofh.it> |
| In reply to | #1707368 |
Looks good, Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> -- Johannes Thumshirn Storage jthumshirn@suse.de +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
[toc] | [prev] | [next] | [standalone]
| From | Christoph Hellwig <hch@lst.de> |
|---|---|
| Date | 2017-08-10 11:40 +0200 |
| Subject | Re: [RFC PATCH 5/6] bsg: reduce unnecessary arguments for bsg_map_hdr() |
| Message-ID | <ucS6C-3LT-19@gated-at.bofh.it> |
| In reply to | #1707368 |
On Wed, Aug 09, 2017 at 04:11:19PM +0200, Benjamin Block wrote: > Since struct bsg_command is now used in every calling case, we don't > need separation of arguments anymore that are contained in the same > bsg_command. > > Signed-off-by: Benjamin Block <bblock@linux.vnet.ibm.com> > --- > block/bsg.c | 13 ++++++------- > 1 file changed, 6 insertions(+), 7 deletions(-) > > diff --git a/block/bsg.c b/block/bsg.c > index 8517361a9b3f..6ee2ffca808a 100644 > --- a/block/bsg.c > +++ b/block/bsg.c > @@ -212,11 +212,12 @@ bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *op) > * map sg_io_v4 to a request. > */ > static struct request * > -bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm, > - u8 *reply_buffer) > +bsg_map_hdr(struct bsg_device *bd, struct bsg_command *bc, > + fmode_t has_write_perm) I wish we could just rename the argument to mode and pass on the whole file->f_mode while you are cleaning up this code. That should be a separate patch, though. Reviewed-by: Christoph Hellwig <hch@lst.de>
[toc] | [prev] | [next] | [standalone]
| From | Benjamin Block <bblock@linux.vnet.ibm.com> |
|---|---|
| Date | 2017-08-11 00:30 +0200 |
| Subject | Re: [RFC PATCH 5/6] bsg: reduce unnecessary arguments for bsg_map_hdr() |
| Message-ID | <ud47M-3wS-5@gated-at.bofh.it> |
| In reply to | #1708372 |
On Thu, Aug 10, 2017 at 11:35:31AM +0200, Christoph Hellwig wrote:
> On Wed, Aug 09, 2017 at 04:11:19PM +0200, Benjamin Block wrote:
> > Since struct bsg_command is now used in every calling case, we don't
> > need separation of arguments anymore that are contained in the same
> > bsg_command.
> >
> > Signed-off-by: Benjamin Block <bblock@linux.vnet.ibm.com>
> > ---
> > block/bsg.c | 13 ++++++-------
> > 1 file changed, 6 insertions(+), 7 deletions(-)
> >
> > diff --git a/block/bsg.c b/block/bsg.c
> > index 8517361a9b3f..6ee2ffca808a 100644
> > --- a/block/bsg.c
> > +++ b/block/bsg.c
> > @@ -212,11 +212,12 @@ bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *op)
> > * map sg_io_v4 to a request.
> > */
> > static struct request *
> > -bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
> > - u8 *reply_buffer)
> > +bsg_map_hdr(struct bsg_device *bd, struct bsg_command *bc,
> > + fmode_t has_write_perm)
>
> I wish we could just rename the argument to mode and pass on the
> whole file->f_mode while you are cleaning up this code. That should
> be a separate patch, though.
>
Hmm, I did a quick pass through the code and the only place this seems
to be used, is to pass it to blk_verify_command() if the subcommand used
in the BSG request is a SCSI Command. And this has the same semantics.
So I guess this would require adjustments to the whole stack, as this is
also used from the 'normal' SG side of the world.
Beste Grüße / Best regards,
- Benjamin Block
--
Linux on z Systems Development / IBM Systems & Technology Group
IBM Deutschland Research & Development GmbH
Vorsitz. AufsR.: Martina Koederitz / Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: AmtsG Stuttgart, HRB 243294
[toc] | [prev] | [next] | [standalone]
| From | Benjamin Block <bblock@linux.vnet.ibm.com> |
|---|---|
| Date | 2017-08-09 16:20 +0200 |
| Subject | [RFC PATCH 3/6] bsg: scsi-transport: add compile-tests to prevent reply-buffer overflows |
| Message-ID | <ucA02-8w8-15@gated-at.bofh.it> |
| In reply to | #1707367 |
The BSG implementations use the bsg_job's reply buffer as storage for their
own custom reply structures (e.g.: struct fc_bsg_reply or
struct iscsi_bsg_reply). The size of bsg_job's reply buffer and those of
the implementations is not dependent in any way the compiler can currently
check.
To make it easier to notice accidental violations add an explicit compile-
time check that tests whether the implementations' reply buffer is at most
as large as bsg_job's.
To do so, we have to move the size-define from bsg.c to a common header.
Signed-off-by: Benjamin Block <bblock@linux.vnet.ibm.com>
---
block/bsg.c | 3 +--
drivers/scsi/scsi_transport_fc.c | 3 +++
drivers/scsi/scsi_transport_iscsi.c | 3 +++
include/linux/bsg-lib.h | 2 ++
4 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/block/bsg.c b/block/bsg.c
index 285b1b8126c3..b924f1c23c58 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -20,6 +20,7 @@
#include <linux/uio.h>
#include <linux/idr.h>
#include <linux/bsg.h>
+#include <linux/bsg-lib.h>
#include <linux/slab.h>
#include <scsi/scsi.h>
@@ -74,8 +75,6 @@ static int bsg_major;
static struct kmem_cache *bsg_cmd_cachep;
-#define BSG_COMMAND_REPLY_BUFFERSIZE SCSI_SENSE_BUFFERSIZE
-
/*
* our internal command type
*/
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 892fbd9800d9..ce6654b5d329 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3736,6 +3736,9 @@ static int fc_bsg_dispatch(struct bsg_job *job)
{
struct Scsi_Host *shost = fc_bsg_to_shost(job);
+ BUILD_BUG_ON(sizeof(struct fc_bsg_reply) >
+ BSG_COMMAND_REPLY_BUFFERSIZE);
+
if (scsi_is_fc_rport(job->dev))
return fc_bsg_rport_dispatch(shost, job);
else
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index a424eaeafeb0..4e021c949ad7 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -1483,6 +1483,9 @@ static int iscsi_bsg_host_dispatch(struct bsg_job *job)
int cmdlen = sizeof(uint32_t); /* start with length of msgcode */
int ret;
+ BUILD_BUG_ON(sizeof(struct iscsi_bsg_reply) >
+ BSG_COMMAND_REPLY_BUFFERSIZE);
+
/* check if we have the msgcode value at least */
if (job->request_len < sizeof(uint32_t)) {
ret = -ENOMSG;
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index e34dde2da0ef..85d7c7678cc6 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -25,6 +25,8 @@
#include <linux/blkdev.h>
+#define BSG_COMMAND_REPLY_BUFFERSIZE SCSI_SENSE_BUFFERSIZE
+
struct request;
struct device;
struct scatterlist;
--
2.12.2
[toc] | [prev] | [next] | [standalone]
| From | Christoph Hellwig <hch@lst.de> |
|---|---|
| Date | 2017-08-10 11:40 +0200 |
| Subject | Re: [RFC PATCH 3/6] bsg: scsi-transport: add compile-tests to prevent reply-buffer overflows |
| Message-ID | <ucS6C-3LT-27@gated-at.bofh.it> |
| In reply to | #1707369 |
Looks fine, Reviewed-by: Christoph Hellwig <hch@lst.de>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web