From 17fe37ecd10d9b0d8e4358c242cffa3352493e47 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 11 Apr 2013 03:14:57 +0000 Subject: [PATCH] scst: Fix scst_set_lun_not_supported_inquiry() Avoid that the call stack below is triggered when an INQUIRY is sent to an scst_local LUN that does not exist. [2990]: scst: scst_set_resp_data_len:2870:***ERROR***: Too big response data len 36 (max 0), limiting it to the max (dev (no LUN)) Pid: 2990, comm: kworker/u:3 Tainted: G O 3.9.0-rc4-debug+ #1 Call Trace: [] scst_set_resp_data_len+0x1b1/0x1d0 [scst] [] scst_set_lun_not_supported_inquiry+0x140/0x400 [scst] [] ? sched_clock_local+0x25/0x90 [] scst_set_cmd_error+0xef/0x210 [scst] [] ? scst_translate_lun+0x125/0x320 [scst] [] __scst_init_cmd+0x1f0/0x270 [scst] [] scst_init_cmd+0x6b/0x310 [scst] [] scst_cmd_init_done+0x124/0x5b0 [scst] [] ? scst_rx_cmd+0xb8/0x220 [scst] [] ? sched_clock_cpu+0xa8/0x110 [] scst_local_queuecommand+0x1ae/0x3c0 [scst_local] [] ? scsi_request_fn+0x34f/0x530 [] ? _raw_spin_unlock_irq+0x30/0x50 [] scsi_dispatch_cmd+0x150/0x4b0 [] scsi_request_fn+0x361/0x530 [] __blk_run_queue+0x37/0x50 [] blk_execute_rq_nowait+0x81/0x100 [] ? __init_waitqueue_head+0x46/0x60 [] blk_execute_rq+0x152/0x200 [] ? bio_phys_segments+0x21/0x30 [] ? blk_rq_bio_prep+0x30/0xb0 [] scsi_execute+0xe6/0x180 [] scsi_execute_req+0xbd/0x130 [] scsi_probe_and_add_lun+0x257/0xe10 [] ? __slab_free+0x2c0/0x311 [] __scsi_scan_target+0x2a3/0x790 [] ? __pm_runtime_resume+0x69/0xa0 [] ? _raw_spin_unlock_irqrestore+0x3f/0x80 [] scsi_scan_target+0xfe/0x110 [] scst_process_aens+0xcc/0x210 [scst_local] [] ? _raw_spin_lock+0x72/0x80 [] ? spin_lock+0x9/0x10 [scst_local] [] scst_aen_work_fn+0x79/0x140 [scst_local] [] process_one_work+0x1da/0x650 [] ? process_one_work+0x172/0x650 [] worker_thread+0x112/0x330 [] ? rescuer_thread+0x260/0x260 [] kthread+0xed/0x100 [] ? lock_release_holdtime.part.26+0x15/0x1a0 [] ? flush_kthread_worker+0x190/0x190 [] ret_from_fork+0x7c/0xb0 [] ? flush_kthread_worker+0x190/0x190 Signed-off-by: Bart Van Assche git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4837 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 4063ffefd..4672a4878 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -1544,6 +1544,9 @@ static int scst_set_lun_not_supported_inquiry(struct scst_cmd *cmd) } if (cmd->sg == NULL) { + if (cmd->bufflen == 0) + cmd->bufflen = min_t(int, 36, get_unaligned_be16(&cmd->cdb[3])); + /* * If target driver preparing data buffer using tgt_alloc_data_buf() * callback, it is responsible to copy the sense to its buffer @@ -1557,9 +1560,6 @@ static int scst_set_lun_not_supported_inquiry(struct scst_cmd *cmd) goto go; } - if (cmd->bufflen == 0) - cmd->bufflen = min_t(int, 36, get_unaligned_be16(&cmd->cdb[3])); - cmd->sg = scst_alloc_sg(cmd->bufflen, GFP_ATOMIC, &cmd->sg_cnt); if (cmd->sg == NULL) { PRINT_ERROR("%s", "Unable to alloc sg for INQUIRY "