2018-09-20 07:19:54

by Johannes Thumshirn

[permalink] [raw]
Subject: [PATCH] scsi: sd: don't crash the host on invalid commands

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 <[email protected]>
Cc: Hannes Reinecke <[email protected]>
Cc: Bart Van Assche <[email protected]>
Cc: Christoph Hellwig <[email protected]>
---
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



2018-09-20 07:33:41

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] scsi: sd: don't crash the host on invalid commands

Looks good,

Reviewed-by: Christoph Hellwig <[email protected]>

2018-09-20 18:18:44

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH] scsi: sd: don't crash the host on invalid commands

On Thu, 2018-09-20 at 09:19 +-0200, Johannes Thumshirn wrote:
+AD4 When sd+AF8-init+AF8-command() get's a with a unknown req+AF8-op() it crashes the
+AD4 system via BUG().
+AD4
+AD4 This makes debugging the actual reason for the broken request
+AD4 cmd+AF8-flags pretty hard as the system is down before it's able to write
+AD4 out debugging data on the serial console or the trace buffer.
+AD4
+AD4 Change the BUG() to a WARN+AF8-ON() and return BLKPREP+AF8-KILL to fail
+AD4 gracefully and return an I/O error to the producer of the request.
+AD4
+AD4 Signed-off-by: Johannes Thumshirn +ADw-jthumshirn+AEA-suse.de+AD4
+AD4 Cc: Hannes Reinecke +ADw-hare+AEA-suse.de+AD4
+AD4 Cc: Bart Van Assche +ADw-bvanassche+AEA-acm.org+AD4
+AD4 Cc: Christoph Hellwig +ADw-hch+AEA-lst.de+AD4
+AD4 ---
+AD4 Fixed Typo in Bart's mail, sorry for this.
+AD4
+AD4 drivers/scsi/sd.c +AHw 3 +-+--
+AD4 1 file changed, 2 insertions(+-), 1 deletion(-)
+AD4
+AD4 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
+AD4 index b79b366a94f7..19f28962d65b 100644
+AD4 --- a/drivers/scsi/sd.c
+AD4 +-+-+- b/drivers/scsi/sd.c
+AD4 +AEAAQA -1276,7 +-1276,8 +AEAAQA static int sd+AF8-init+AF8-command(struct scsi+AF8-cmnd +ACo-cmd)
+AD4 case REQ+AF8-OP+AF8-ZONE+AF8-RESET:
+AD4 return sd+AF8-zbc+AF8-setup+AF8-reset+AF8-cmnd(cmd)+ADs
+AD4 default:
+AD4 - BUG()+ADs
+AD4 +- WARN+AF8-ON(1)+ADs
+AD4 +- return BLKPREP+AF8-KILL+ADs
+AD4 +AH0
+AD4 +AH0

Have you considered to use WARN+AF8-ON+AF8-ONCE() instead of WARN+AF8-ON(1)? Otherwise
this patch looks good to me.

Thanks,

Bart.


2018-09-21 06:30:24

by Johannes Thumshirn

[permalink] [raw]
Subject: Re: [PATCH] scsi: sd: don't crash the host on invalid commands

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
[email protected] +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