From patchwork Mon Jul 10 07:38:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Yi X-Patchwork-Id: 9832465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8FDC1602BD for ; Mon, 10 Jul 2017 07:38:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8407E27480 for ; Mon, 10 Jul 2017 07:38:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78197283C4; Mon, 10 Jul 2017 07:38:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09C3727480 for ; Mon, 10 Jul 2017 07:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751161AbdGJHiH (ORCPT ); Mon, 10 Jul 2017 03:38:07 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33294 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751130AbdGJHiH (ORCPT ); Mon, 10 Jul 2017 03:38:07 -0400 Received: by mail-pf0-f195.google.com with SMTP id e199so13391188pfh.0 for ; Mon, 10 Jul 2017 00:38:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=fBx6fPfx/J39GXWzjI1kDsYFv0fyE9uJTngNHnNYLg4=; b=ihbyf72ACX93x+iYLuwiazb+nHpg7+WtZVgUs+Dby14ioaZZYtQ4nDNqcvaPlU1stR d2sGepWFPRF18XpGIgiYorEb9d6s3J2JoKW0fZr1ZNJywLEJuuSZXS0Su+U8T1rXXebB ikjy6JUEzTV+NzfrBMGrd4IaFhmi8Y7fpr76fd8MEDlOmPBDu9JUgWyhqJjqqzidtC++ ZHfVc9ybi6fuT4R3aCdd2wNy4MLvlLQObxr7RNqEdMYW9EWOmlVst8nc31yjsFn5Ak6P 29SNarhzBVVv/doGdEqN7Brj36VOZEcMx6GJDw8DMYhca+8OkCpezvEhokbjKH/34jbf Zo4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=fBx6fPfx/J39GXWzjI1kDsYFv0fyE9uJTngNHnNYLg4=; b=Eak42phrYNYSntEgSknhvsTUqjwllQfN2rLd80/8RdDUaREpihBOzV60K3Ti92DcpW PnDkJlQ/xdCW26kheXiqJosabZRMx8sBDxwrkSDLRPMmxFLUrLt+vZb0bevm5+ib3OJN 3Nm8pZlPkinU33d/iV+A3aIVL6lW2ok4thaJDFMFoaNU8T6c2tsrz9oco+xOFyP8wQZZ hJL6d7ynN01U+Yt4CbsNNEwhFI294/w16dX+14gClGNNqpCUfkWAFqzABaH1/HKybUSE +Sn+mAVAV1G1lVfTSQmlpWLhawZe9rJdaJ+Sk9G4WD/ZW7oXzQip2AyBwzAQiXfBs5bj wHYA== X-Gm-Message-State: AIVw111n8MG15nCQMbrWi7NtlEaIyB6gdTBMDNWHVFY9B7/NgjLeLjDN fIT8qdJr6O5oCohKYus= X-Received: by 10.84.198.3 with SMTP id o3mr16761343pld.84.1499672286018; Mon, 10 Jul 2017 00:38:06 -0700 (PDT) Received: from [10.12.12.133] (125-227-147-112.HINET-IP.hinet.net. [125.227.147.112]) by smtp.gmail.com with ESMTPSA id 74sm21844747pfh.49.2017.07.10.00.38.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Jul 2017 00:38:05 -0700 (PDT) From: Jiang Yi Subject: [PATCH] iscsi-target: Discard iscsi payload when datasn higher than expected To: nab@linux-iscsi.org Cc: target-devel@vger.kernel.org Message-ID: <419bcd22-b871-a812-fb5e-a889ecd85666@gmail.com> Date: Mon, 10 Jul 2017 15:38:04 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 Content-Language: en-US Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Nic, I ran libiscsi test suite and find that some test cases failed. One of them is "iSCSI.iSCSIdatasn": ./libiscsi/test-tool/iscsi-test-cu --test=iSCSI.iSCSIdatasn --verbose --Verbose-scsi --dataloss iscsi://${IP}:3260/${IQN}/0 This is the output of the failed test: // start of test output Send READCAPACITY10 (Expecting SUCCESS) LBA:0 pmi:0 [OK] READCAPACITY10 returned SUCCESS NO SENSE(0x00) (null)(0x0000) Send READCAPACITY16 (Expecting SUCCESS) [OK] READCAPACITY16 returned SUCCESS NO SENSE(0x00) (null)(0x0000) Send INQUIRY (Expecting SUCCESS) evpd:0 page_code:00 alloc_len:64 [OK] INQUIRY returned SUCCESS NO SENSE(0x00) (null)(0x0000) Send INQUIRY (Expecting SUCCESS) evpd:1 page_code:b0 alloc_len:64 [OK] INQUIRY returned SUCCESS NO SENSE(0x00) (null)(0x0000) Send INQUIRY (Expecting SUCCESS) evpd:1 page_code:b1 alloc_len:255 [OK] INQUIRY returned SUCCESS NO SENSE(0x00) (null)(0x0000) Send INQUIRY (Expecting SUCCESS) evpd:1 page_code:b2 alloc_len:64 [OK] INQUIRY returned SUCCESS NO SENSE(0x00) (null)(0x0000) Send REPORT_SUPPORTED_OPCODE (Expecting SUCCESS) RCTD:1 OPTIONS:0 OPCODE:0x00 SA:0 ALLOC_LEN:65535 [SKIPPED] REPORT_SUPPORTED_OPCODES is not implemented. Send MODESENSE6 (Expecting SUCCESS) [OK] MODESENSE6 returned SUCCESS NO SENSE(0x00) (null)(0x0000) Send PRIN/READ_KEYS CUnit - A unit testing framework for C - Version 2.1-2 http://cunit.sourceforge.net/ Suite: iSCSIdatasn Test: iSCSIDataSnInvalid ... Test sending invalid iSCSI DataSN Send two Data-Out PDU's with DataSN==0. Should fail. Send WRITE10 (Expecting SUCCESS) LBA:100 blocks:2 wrprotect:0 dpo:0 fua:0 fua_nv:0 group:0 [FAILED] WRITE10 command failed with sense. NO SENSE(0x00)/(null)(0x0000) Send Data-Out PDU with DataSN==27. Should fail Send WRITE10 (Expecting SUCCESS) LBA:100 blocks:1 wrprotect:0 dpo:0 fua:0 fua_nv:0 group:0 [FAILED] WRITE10 command failed with sense. NO SENSE(0x00)/(null)(0x0000) Send Data-Out PDU with DataSN==-1. Should fail Send WRITE10 (Expecting SUCCESS) LBA:100 blocks:1 wrprotect:0 dpo:0 fua:0 fua_nv:0 group:0 [OK] WRITE10 returned SUCCESS NO SENSE(0x00) (null)(0x0000) Send Data-Out PDU's in reverse order (DataSN == 1,0). Should fail Send WRITE10 (Expecting SUCCESS) LBA:100 blocks:2 wrprotect:0 dpo:0 fua:0 fua_nv:0 group:0 [FAILED] WRITE10 command failed with sense. NO SENSE(0x00)/(null)(0x0000) FAILED 1. test_iscsi_datasn_invalid.c:142 - CU_ASSERT_NOT_EQUAL(ret,0) Run Summary: Type Total Ran Passed Failed Inactive suites 1 1 n/a 0 0 tests 1 1 0 1 0 asserts 4 4 3 1 n/a Elapsed time = 2.808 seconds Tests completed with return value: 0 // end of test output To fix it, I propose a patch: Signed-off-by: Jiang Yi --- drivers/target/iscsi/iscsi_target_erl0.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target_erl0.c b/drivers/target/iscsi/iscsi_target_erl0.c index 7fe2aa7..15fe495 100644 --- a/drivers/target/iscsi/iscsi_target_erl0.c +++ b/drivers/target/iscsi/iscsi_target_erl0.c @@ -297,7 +297,10 @@ static int iscsit_dataout_check_sequence( pr_err("Command ITT: 0x%08x set ISCSI_FLAG_CMD_FINAL" " before end of DataOUT sequence, protocol" " error.\n", cmd->init_task_tag); - return DATAOUT_CANNOT_RECOVER; + if (iscsit_dump_data_payload(conn, payload_length, 1) < 0) { + return DATAOUT_CANNOT_RECOVER; + } + return DATAOUT_WITHIN_COMMAND_RECOVERY; } } else { if (next_burst_len < seq->xfer_len) { @@ -382,7 +385,10 @@ static int iscsit_dataout_check_datasn( if (!conn->sess->sess_ops->ErrorRecoveryLevel) { pr_err("Unable to perform within-command recovery" " while ERL=0.\n"); - return DATAOUT_CANNOT_RECOVER; + if (iscsit_dump_data_payload(conn, payload_length, 1) < 0) { + return DATAOUT_CANNOT_RECOVER; + } + return DATAOUT_WITHIN_COMMAND_RECOVERY; } dump: if (iscsit_dump_data_payload(conn, payload_length, 1) < 0)