linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: sd: don't crash the host on invalid commands
@ 2018-09-20  7:19 Johannes Thumshirn
  2018-09-20  7:33 ` Christoph Hellwig
  2018-09-20 18:18 ` Bart Van Assche
  0 siblings, 2 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2018-09-20  7:19 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: Linux Kernel Mailinglist, Linux SCSI Mailinglist,
	Johannes Thumshirn, Hannes Reinecke, Bart Van Assche,
	Christoph Hellwig

When sd_init_command() get's a with a unknown req_op() it crashes the
system via BUG().

This makes debugging the actual reason for the broken request
cmd_flags pretty hard as the system is down before it's able to write
out debugging data on the serial console or the trace buffer.

Change the BUG() to a WARN_ON() and return BLKPREP_KILL to fail
gracefully and return an I/O error to the producer of the request.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Christoph Hellwig <hch@lst.de>
---
Fixed Typo in Bart's mail, sorry for this.

 drivers/scsi/sd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index b79b366a94f7..19f28962d65b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1276,7 +1276,8 @@ static int sd_init_command(struct scsi_cmnd *cmd)
 	case REQ_OP_ZONE_RESET:
 		return sd_zbc_setup_reset_cmnd(cmd);
 	default:
-		BUG();
+		WARN_ON(1);
+		return BLKPREP_KILL;
 	}
 }
 
-- 
2.16.4


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

* Re: [PATCH] scsi: sd: don't crash the host on invalid commands
  2018-09-20  7:19 [PATCH] scsi: sd: don't crash the host on invalid commands Johannes Thumshirn
@ 2018-09-20  7:33 ` Christoph Hellwig
  2018-09-20 18:18 ` Bart Van Assche
  1 sibling, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2018-09-20  7:33 UTC (permalink / raw)
  To: Johannes Thumshirn
  Cc: Martin K . Petersen, Linux Kernel Mailinglist,
	Linux SCSI Mailinglist, Hannes Reinecke, Bart Van Assche,
	Christoph Hellwig

Looks good,

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

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

* Re: [PATCH] scsi: sd: don't crash the host on invalid commands
  2018-09-20  7:19 [PATCH] scsi: sd: don't crash the host on invalid commands Johannes Thumshirn
  2018-09-20  7:33 ` Christoph Hellwig
@ 2018-09-20 18:18 ` Bart Van Assche
  2018-09-21  6:29   ` Johannes Thumshirn
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2018-09-20 18:18 UTC (permalink / raw)
  To: Johannes Thumshirn, Martin K . Petersen
  Cc: Linux Kernel Mailinglist, Linux SCSI Mailinglist,
	Hannes Reinecke, Christoph Hellwig

On Thu, 2018-09-20 at 09:19 +0200, Johannes Thumshirn wrote:
> When sd_init_command() get's a with a unknown req_op() it crashes the
> system via BUG().
> 
> This makes debugging the actual reason for the broken request
> cmd_flags pretty hard as the system is down before it's able to write
> out debugging data on the serial console or the trace buffer.
> 
> Change the BUG() to a WARN_ON() and return BLKPREP_KILL to fail
> gracefully and return an I/O error to the producer of the request.
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> Cc: Hannes Reinecke <hare@suse.de>
> Cc: Bart Van Assche <bvanassche@acm.org>
> Cc: Christoph Hellwig <hch@lst.de>
> ---
> Fixed Typo in Bart's mail, sorry for this.
> 
>  drivers/scsi/sd.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index b79b366a94f7..19f28962d65b 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -1276,7 +1276,8 @@ static int sd_init_command(struct scsi_cmnd *cmd)
>  	case REQ_OP_ZONE_RESET:
>  		return sd_zbc_setup_reset_cmnd(cmd);
>  	default:
> -		BUG();
> +		WARN_ON(1);
> +		return BLKPREP_KILL;
>  	}
>  }

Have you considered to use WARN_ON_ONCE() instead of WARN_ON(1)? Otherwise
this patch looks good to me.

Thanks,

Bart.


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

* Re: [PATCH] scsi: sd: don't crash the host on invalid commands
  2018-09-20 18:18 ` Bart Van Assche
@ 2018-09-21  6:29   ` Johannes Thumshirn
  0 siblings, 0 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2018-09-21  6:29 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, Linux Kernel Mailinglist,
	Linux SCSI Mailinglist, Hannes Reinecke, Christoph Hellwig

On Thu, Sep 20, 2018 at 11:18:19AM -0700, Bart Van Assche wrote:
> On Thu, 2018-09-20 at 09:19 +0200, Johannes Thumshirn wrote:
> 
> Have you considered to use WARN_ON_ONCE() instead of WARN_ON(1)? Otherwise
> this patch looks good to me.

Indeed I did and then forgot to 'git commit --amend' it befroe sending it out.
I'll do so now.

	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] 5+ messages in thread

* [PATCH] scsi: sd: don't crash the host on invalid commands
@ 2018-09-20  7:15 Johannes Thumshirn
  0 siblings, 0 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2018-09-20  7:15 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: Linux Kernel Mailinglist, Linux SCSI Mailinglist,
	Johannes Thumshirn, Hannes Reinecke, Bart Van Asche,
	Christoph Hellwig

When sd_init_command() get's a with a unknown req_op() it crashes the
system via BUG().

This makes debugging the actual reason for the broken request
cmd_flags pretty hard as the system is down before it's able to write
out debugging data on the serial console or the trace buffer.

Change the BUG() to a WARN_ON() and return BLKPREP_KILL to fail
gracefully and return an I/O error to the producer of the request.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Bart Van Asche <bvanasche@acm.org>
Cc: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/sd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index b79b366a94f7..19f28962d65b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1276,7 +1276,8 @@ static int sd_init_command(struct scsi_cmnd *cmd)
 	case REQ_OP_ZONE_RESET:
 		return sd_zbc_setup_reset_cmnd(cmd);
 	default:
-		BUG();
+		WARN_ON(1);
+		return BLKPREP_KILL;
 	}
 }
 
-- 
2.16.4


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

end of thread, other threads:[~2018-09-21  6:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-20  7:19 [PATCH] scsi: sd: don't crash the host on invalid commands Johannes Thumshirn
2018-09-20  7:33 ` Christoph Hellwig
2018-09-20 18:18 ` Bart Van Assche
2018-09-21  6:29   ` Johannes Thumshirn
  -- strict thread matches above, loose matches on Subject: below --
2018-09-20  7:15 Johannes Thumshirn

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