From 4e08d27031139f85fcaa7ed784ef8dce56379975 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 26 May 2013 15:21:43 -0700 Subject: [PATCH] Add tests from SANITIZE OVERWRITE parameter length --- Makefile.am | 1 + lib/scsi-lowlevel.c | 2 +- test-tool/iscsi-test-cu.c | 1 + test-tool/iscsi-test-cu.h | 1 + test-tool/test_sanitize_paramlen.c | 122 +++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 test-tool/test_sanitize_paramlen.c diff --git a/Makefile.am b/Makefile.am index f63c45d..a28fde3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -268,6 +268,7 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \ test-tool/test_reserve6_lun_reset.c \ test-tool/test_sanitize_simple.c \ test-tool/test_sanitize_overwrite.c \ + test-tool/test_sanitize_paramlen.c \ test-tool/test_startstopunit_simple.c \ test-tool/test_startstopunit_pwrcnd.c \ test-tool/test_startstopunit_noloej.c \ diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index d348506..3a89519 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -364,7 +364,7 @@ scsi_cdb_sanitize(int immed, int ause, int sa, int param_len) } else { task->xfer_dir = SCSI_XFER_NONE; } - task->expxferlen = param_len; + task->expxferlen = (param_len + 3) & 0xfffc; return task; } diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index d8482e3..1f92c2e 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -224,6 +224,7 @@ static CU_TestInfo tests_readonly[] = { static CU_TestInfo tests_sanitize[] = { { (char *)"Sanitize", test_sanitize_simple }, { (char *)"Overwrite", test_sanitize_overwrite }, + { (char *)"ParamLen", test_sanitize_paramlen }, CU_TEST_INFO_NULL }; diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index a0376cd..72180d0 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -153,6 +153,7 @@ void test_reserve6_lun_reset(void); void test_sanitize_simple(void); void test_sanitize_overwrite(void); +void test_sanitize_paramlen(void); void test_startstopunit_simple(void); void test_startstopunit_pwrcnd(void); diff --git a/test-tool/test_sanitize_paramlen.c b/test-tool/test_sanitize_paramlen.c new file mode 100644 index 0000000..fd84748 --- /dev/null +++ b/test-tool/test_sanitize_paramlen.c @@ -0,0 +1,122 @@ +/* + Copyright (C) 2013 Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include +#include +#include +#include + +#include + +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test-cu.h" + +void +test_sanitize_paramlen(void) +{ + int i, ret; + struct iscsi_data data; + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test SANITIZE ParameterListLength"); + + CHECK_FOR_SANITIZE; + + data.size = 8; + data.data = alloca(data.size); + memset(data.data, 0, data.size); + + + logging(LOG_VERBOSE, "BLOCK_ERASE parameter list length must be 0"); + logging(LOG_VERBOSE, "Test that non-zero param length is an error for " + "BLOCK ERASE"); + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 8, &data); + if (ret == -2) { + logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not implemented."); + CU_PASS("SANITIZE is not implemented."); + return; + } else { + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "CRYPTO_ERASE parameter list length must be 0"); + logging(LOG_VERBOSE, "Test that non-zero param length is an error for " + "CRYPTO ERASE"); + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 8, &data); + if (ret == -2) { + logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not implemented."); + CU_PASS("SANITIZE is not implemented."); + return; + } else { + CU_ASSERT_EQUAL(ret, 0); + } + + logging(LOG_VERBOSE, "EXIT_FAILURE_MODE parameter list length must " + "be 0"); + logging(LOG_VERBOSE, "Test that non-zero param length is an error for " + "EXIT_FAILURE_MODE"); + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_EXIT_FAILURE_MODE, 8, &data); + if (ret == -2) { + logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not implemented."); + CU_PASS("SANITIZE is not implemented."); + return; + } else { + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "OVERWRITE parameter list length must " + "be > 4 and < blocksize+5"); + for (i = 0; i < 5; i++) { + logging(LOG_VERBOSE, "Test OVERWRITE with ParamLen:%d is an " + "error.", i); + + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_OVERWRITE, i, &data); + if (ret == -2) { + logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not " + "implemented."); + CU_PASS("SANITIZE is not implemented."); + return; + } else { + CU_ASSERT_EQUAL(ret, 0); + } + } + + + logging(LOG_VERBOSE, "Test OVERWRITE with ParamLen:%d is an " + "error.", i); + + data.size = block_size + 8; + data.data = alloca(data.size); + memset(data.data, 0, data.size); + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_OVERWRITE, block_size + 5, &data); + if (ret == -2) { + logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not " + "implemented."); + CU_PASS("SANITIZE is not implemented."); + return; + } else { + CU_ASSERT_EQUAL(ret, 0); + } +}