All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
@ 2017-07-05 13:49 Johannes Thumshirn
  2017-07-06 11:44 ` Hannes Reinecke
  2017-07-06 18:47 ` Douglas Gilbert
  0 siblings, 2 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2017-07-05 13:49 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: Linux SCSI Mailinglist, Linux Kernel Mailinglist, Chris Clayton,
	Johannes Thumshirn, Doug Gilbert

SG_DXFER_FROM_DEV transfers do not have a dxferp as we set it to NULL,
but must have a length bigger than 0. This fixes a regression introduced
by commit 28676d869bbb ("scsi: sg: check for valid direction before
starting the request")

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Fixes: 28676d869bbb ("scsi: sg: check for valid direction before starting the request")
Reported-by: Chris Clayton <chris2553@googlemail.com>
Tested-by: Chris Clayton <chris2553@googlemail.com>
Cc: Doug Gilbert <dgilbert@interlog.com>
---
 drivers/scsi/sg.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 21225d62b0c1..3c91593260aa 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -758,8 +758,11 @@ static bool sg_is_valid_dxfer(sg_io_hdr_t *hp)
 		if (hp->dxferp || hp->dxfer_len > 0)
 			return false;
 		return true;
-	case SG_DXFER_TO_DEV:
 	case SG_DXFER_FROM_DEV:
+		if (hp->dxferp || hp->dxfer_len < 0)
+			return false;
+		return true;
+	case SG_DXFER_TO_DEV:
 	case SG_DXFER_TO_FROM_DEV:
 		if (!hp->dxferp || hp->dxfer_len == 0)
 			return false;
-- 
2.12.3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
  2017-07-05 13:49 [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers Johannes Thumshirn
@ 2017-07-06 11:44 ` Hannes Reinecke
  2017-07-06 18:47 ` Douglas Gilbert
  1 sibling, 0 replies; 11+ messages in thread
From: Hannes Reinecke @ 2017-07-06 11:44 UTC (permalink / raw)
  To: Johannes Thumshirn, Martin K . Petersen
  Cc: Linux SCSI Mailinglist, Linux Kernel Mailinglist, Chris Clayton,
	Doug Gilbert

On 07/05/2017 03:49 PM, Johannes Thumshirn wrote:
> SG_DXFER_FROM_DEV transfers do not have a dxferp as we set it to NULL,
> but must have a length bigger than 0. This fixes a regression introduced
> by commit 28676d869bbb ("scsi: sg: check for valid direction before
> starting the request")
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> Fixes: 28676d869bbb ("scsi: sg: check for valid direction before starting the request")
> Reported-by: Chris Clayton <chris2553@googlemail.com>
> Tested-by: Chris Clayton <chris2553@googlemail.com>
> Cc: Doug Gilbert <dgilbert@interlog.com>
> ---
>  drivers/scsi/sg.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 21225d62b0c1..3c91593260aa 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -758,8 +758,11 @@ static bool sg_is_valid_dxfer(sg_io_hdr_t *hp)
>  		if (hp->dxferp || hp->dxfer_len > 0)
>  			return false;
>  		return true;
> -	case SG_DXFER_TO_DEV:
>  	case SG_DXFER_FROM_DEV:
> +		if (hp->dxferp || hp->dxfer_len < 0)
> +			return false;
> +		return true;
> +	case SG_DXFER_TO_DEV:
>  	case SG_DXFER_TO_FROM_DEV:
>  		if (!hp->dxferp || hp->dxfer_len == 0)
>  			return false;
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
  2017-07-05 13:49 [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers Johannes Thumshirn
  2017-07-06 11:44 ` Hannes Reinecke
@ 2017-07-06 18:47 ` Douglas Gilbert
  2017-07-07  7:57   ` Johannes Thumshirn
  1 sibling, 1 reply; 11+ messages in thread
From: Douglas Gilbert @ 2017-07-06 18:47 UTC (permalink / raw)
  To: Johannes Thumshirn, Martin K . Petersen
  Cc: Linux SCSI Mailinglist, Linux Kernel Mailinglist, Chris Clayton

On 2017-07-05 09:49 AM, Johannes Thumshirn wrote:
> SG_DXFER_FROM_DEV transfers do not have a dxferp as we set it to NULL,
> but must have a length bigger than 0. This fixes a regression introduced
> by commit 28676d869bbb ("scsi: sg: check for valid direction before
> starting the request")

It is not clear to me that dxferp is set to NULL for the newer sg_v3
interface. In the sg.c source of lk 4.12.0 around line 654 (in the
sg_write(...) function) only the older interface passes through; the
newer interface bypasses that section with a 'return sg_new_write(...)'
on line 606.

Can you check your patch with one of the utilities from sg3_utils
such as sg_inq which will use SG_DXFER_FROM_DEV with the newer
interface?


BTW I'm not sure why dxferp is set to NULL for SG_DXFER_FROM_DEV
transfers; perhaps some magic done by the block layer. Maybe a
comment in the code (e.g. on line 654) would help.

Also sg_is_valid_dxfer() is only called once and is more complex
than it looks; so perhaps it could be inlined back in
sg_common_write().

Doug Gilbert

> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> Fixes: 28676d869bbb ("scsi: sg: check for valid direction before starting the request")
> Reported-by: Chris Clayton <chris2553@googlemail.com>
> Tested-by: Chris Clayton <chris2553@googlemail.com>
> Cc: Doug Gilbert <dgilbert@interlog.com>
> ---
>   drivers/scsi/sg.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 21225d62b0c1..3c91593260aa 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -758,8 +758,11 @@ static bool sg_is_valid_dxfer(sg_io_hdr_t *hp)
>   		if (hp->dxferp || hp->dxfer_len > 0)
>   			return false;
>   		return true;
> -	case SG_DXFER_TO_DEV:
>   	case SG_DXFER_FROM_DEV:
> +		if (hp->dxferp || hp->dxfer_len < 0)
> +			return false;
> +		return true;
> +	case SG_DXFER_TO_DEV:
>   	case SG_DXFER_TO_FROM_DEV:
>   		if (!hp->dxferp || hp->dxfer_len == 0)
>   			return false;
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
  2017-07-06 18:47 ` Douglas Gilbert
@ 2017-07-07  7:57   ` Johannes Thumshirn
  0 siblings, 0 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2017-07-07  7:57 UTC (permalink / raw)
  To: Douglas Gilbert
  Cc: Martin K . Petersen, Linux SCSI Mailinglist,
	Linux Kernel Mailinglist, Chris Clayton

On Thu, Jul 06, 2017 at 02:47:22PM -0400, Douglas Gilbert wrote:
> Can you check your patch with one of the utilities from sg3_utils
> such as sg_inq which will use SG_DXFER_FROM_DEV with the newer
> interface?

Correct, this patch broke sg_inq. I'll send a corrected v2.

> BTW I'm not sure why dxferp is set to NULL for SG_DXFER_FROM_DEV
> transfers; perhaps some magic done by the block layer. Maybe a
> comment in the code (e.g. on line 654) would help.

This is due to:

commit fad7f01e61bf737fe8a3740d803f000db57ecac6
Author: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Date:   Tue Sep 2 16:20:20 2008 +0900

    sg: set dxferp to NULL for READ with the older SG interface
    
    With the older SG interface, we don't know a user-space address to
    trasfer data when executing a SCSI command. So we can't pass a
    user-space address to blk_rq_map_user.
    
    This patch fixes sg to pass a NULL user-space address to
    blk_rq_map_user so that it just sets up a request and bios with page
    frames propely without data transfer.
    
    Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
    Signed-off-by: Jens Axboe <jens.axboe@oracle.com>

> 
> Also sg_is_valid_dxfer() is only called once and is more complex
> than it looks; so perhaps it could be inlined back in
> sg_common_write().

The compiler will inline it anyways (at least the one I checked with) and
inlining it into sg_common_write() won't make the code more readable IMHO. But
ultimately it's your driver so if you insist I'll do.

-- 
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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
  2017-07-18 16:18     ` Greg Kroah-Hartman
@ 2017-07-19  6:48       ` Johannes Thumshirn
  0 siblings, 0 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2017-07-19  6:48 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Martin K. Petersen, stable, Douglas Gilbert

On Tue, Jul 18, 2017 at 06:18:29PM +0200, Greg KH wrote:
> On Tue, Jul 18, 2017 at 11:54:31AM -0400, Martin K. Petersen wrote:
> > 
> > Greg,
> > 
> > > On Tue, Jul 18, 2017 at 09:42:21AM +0200, Johannes Thumshirn wrote:
> > >> (commit 68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47 upstream)
> > >
> > > There is no such commit in Linus's tree :(
> > 
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/scsi/sg.c?id=68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47
> 
> {sigh} I hadn't updated my local tree.
> 
> As this isn't in a -rc kernel yet, is it ok for me to wait until it
> shows up in one before adding it to a stable tree?
> 
> And why wasn't it marked with a "cc: stable" in it so this would all
> happen automatically?

Because I forgot it. I'm sorry.

-- 
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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
  2017-07-18 15:54   ` Martin K. Petersen
@ 2017-07-18 16:18     ` Greg Kroah-Hartman
  2017-07-19  6:48       ` Johannes Thumshirn
  0 siblings, 1 reply; 11+ messages in thread
From: Greg Kroah-Hartman @ 2017-07-18 16:18 UTC (permalink / raw)
  To: Martin K. Petersen; +Cc: Johannes Thumshirn, stable, Douglas Gilbert

On Tue, Jul 18, 2017 at 11:54:31AM -0400, Martin K. Petersen wrote:
> 
> Greg,
> 
> > On Tue, Jul 18, 2017 at 09:42:21AM +0200, Johannes Thumshirn wrote:
> >> (commit 68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47 upstream)
> >
> > There is no such commit in Linus's tree :(
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/scsi/sg.c?id=68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47

{sigh} I hadn't updated my local tree.

As this isn't in a -rc kernel yet, is it ok for me to wait until it
shows up in one before adding it to a stable tree?

And why wasn't it marked with a "cc: stable" in it so this would all
happen automatically?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
  2017-07-18 15:45 ` Greg Kroah-Hartman
@ 2017-07-18 15:54   ` Martin K. Petersen
  2017-07-18 16:18     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 11+ messages in thread
From: Martin K. Petersen @ 2017-07-18 15:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Johannes Thumshirn, stable, Douglas Gilbert, Martin K . Petersen


Greg,

> On Tue, Jul 18, 2017 at 09:42:21AM +0200, Johannes Thumshirn wrote:
>> (commit 68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47 upstream)
>
> There is no such commit in Linus's tree :(

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/scsi/sg.c?id=68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
  2017-07-18  7:42 Johannes Thumshirn
  2017-07-18  7:50 ` Greg Kroah-Hartman
@ 2017-07-18 15:45 ` Greg Kroah-Hartman
  2017-07-18 15:54   ` Martin K. Petersen
  1 sibling, 1 reply; 11+ messages in thread
From: Greg Kroah-Hartman @ 2017-07-18 15:45 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: stable, Douglas Gilbert, Martin K . Petersen

On Tue, Jul 18, 2017 at 09:42:21AM +0200, Johannes Thumshirn wrote:
> (commit 68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47 upstream)

There is no such commit in Linus's tree :(

Where did this come from?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
  2017-07-18  7:50 ` Greg Kroah-Hartman
@ 2017-07-18  7:52   ` Johannes Thumshirn
  0 siblings, 0 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2017-07-18  7:52 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: stable, Douglas Gilbert, Martin K . Petersen

On Tue, Jul 18, 2017 at 09:50:07AM +0200, Greg KH wrote:
> What stable tree(s) do you want this to be applied to?

I only have reports for 4.12 and this is where the broken commit went in. So I
guess 4.12 should be sufficient.

Thanks,
	Johannes

-- 
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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
  2017-07-18  7:42 Johannes Thumshirn
@ 2017-07-18  7:50 ` Greg Kroah-Hartman
  2017-07-18  7:52   ` Johannes Thumshirn
  2017-07-18 15:45 ` Greg Kroah-Hartman
  1 sibling, 1 reply; 11+ messages in thread
From: Greg Kroah-Hartman @ 2017-07-18  7:50 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: stable, Douglas Gilbert, Martin K . Petersen

On Tue, Jul 18, 2017 at 09:42:21AM +0200, Johannes Thumshirn wrote:
> (commit 68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47 upstream)
> 
> SG_DXFER_FROM_DEV transfers do not necessarily have a dxferp as we set
> it to NULL for the old sg_io read/write interface, but must have a
> length bigger than 0. This fixes a regression introduced by commit
> 28676d869bbb ("scsi: sg: check for valid direction before starting the
> request")
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> Fixes: 28676d869bbb ("scsi: sg: check for valid direction before starting the request")
> Reported-by: Chris Clayton <chris2553@googlemail.com>
> Tested-by: Chris Clayton <chris2553@googlemail.com>
> Cc: Douglas Gilbert <dgilbert@interlog.com>
> Reviewed-by: Hannes Reinecke <hare@suse.com>
> Tested-by: Chris Clayton <chris2553@googlemail.com>
> Acked-by: Douglas Gilbert <dgilbert@interlog.com>
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
> ---
>  drivers/scsi/sg.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

What stable tree(s) do you want this to be applied to?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers
@ 2017-07-18  7:42 Johannes Thumshirn
  2017-07-18  7:50 ` Greg Kroah-Hartman
  2017-07-18 15:45 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2017-07-18  7:42 UTC (permalink / raw)
  To: stable
  Cc: Greg Kroah-Hartman, Johannes Thumshirn, Douglas Gilbert,
	Martin K . Petersen

(commit 68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47 upstream)

SG_DXFER_FROM_DEV transfers do not necessarily have a dxferp as we set
it to NULL for the old sg_io read/write interface, but must have a
length bigger than 0. This fixes a regression introduced by commit
28676d869bbb ("scsi: sg: check for valid direction before starting the
request")

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Fixes: 28676d869bbb ("scsi: sg: check for valid direction before starting the request")
Reported-by: Chris Clayton <chris2553@googlemail.com>
Tested-by: Chris Clayton <chris2553@googlemail.com>
Cc: Douglas Gilbert <dgilbert@interlog.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Tested-by: Chris Clayton <chris2553@googlemail.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
---
 drivers/scsi/sg.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 21225d62b0c1..1e82d4128a84 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -758,8 +758,11 @@ static bool sg_is_valid_dxfer(sg_io_hdr_t *hp)
 		if (hp->dxferp || hp->dxfer_len > 0)
 			return false;
 		return true;
-	case SG_DXFER_TO_DEV:
 	case SG_DXFER_FROM_DEV:
+		if (hp->dxfer_len < 0)
+			return false;
+		return true;
+	case SG_DXFER_TO_DEV:
 	case SG_DXFER_TO_FROM_DEV:
 		if (!hp->dxferp || hp->dxfer_len == 0)
 			return false;
-- 
2.12.3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-07-19  6:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-05 13:49 [PATCH] scsi: sg: fix SG_DXFER_FROM_DEV transfers Johannes Thumshirn
2017-07-06 11:44 ` Hannes Reinecke
2017-07-06 18:47 ` Douglas Gilbert
2017-07-07  7:57   ` Johannes Thumshirn
2017-07-18  7:42 Johannes Thumshirn
2017-07-18  7:50 ` Greg Kroah-Hartman
2017-07-18  7:52   ` Johannes Thumshirn
2017-07-18 15:45 ` Greg Kroah-Hartman
2017-07-18 15:54   ` Martin K. Petersen
2017-07-18 16:18     ` Greg Kroah-Hartman
2017-07-19  6:48       ` Johannes Thumshirn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.