From a9ff96ae6ef6150be799dfe36f01908ec2a0a9d2 Mon Sep 17 00:00:00 2001 From: Folkert van Heusden Date: Thu, 10 Oct 2024 13:49:25 +0200 Subject: [PATCH 1/2] WRITE SAME 10/16 with TL=0 means write x upto the end; this is also limited to MAX_WS_LEN --- scsi.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scsi.cpp b/scsi.cpp index 9cad33a..710d9a8 100644 --- a/scsi.cpp +++ b/scsi.cpp @@ -765,11 +765,20 @@ std::optional scsi::send(const uint64_t lun, const uint8_t *const if (ok) { scsi::scsi_rw_result rc = rw_ok; + const uint64_t size_in_blocks = b->get_size_in_blocks(); + if (transfer_length == 0) { - for(uint64_t i=lba; iget_size_in_blocks() && rc == rw_ok; i++) { - rc = response.r2t.write_same_is_unmap ? - trim(i, 1) : - write(i, 1, data.first); + if (size_in_blocks - lba > MAX_WS_LEN) { + DOLOG(logging::ll_debug, "scsi::validate_request", "-", "WRITE_SAME maximum number of blocks for TL=0"); + response.sense_data = error_invalid_field(); + ok = false; + } + else { + for(uint64_t i=lba; iget_size_in_blocks() && rc == rw_ok; i++) { + rc = response.r2t.write_same_is_unmap ? + trim(i, 1) : + write(i, 1, data.first); + } } } else { From 226d29be13ca0d4c61128e955e526e39681c3e48 Mon Sep 17 00:00:00 2001 From: Folkert van Heusden Date: Thu, 10 Oct 2024 14:00:55 +0200 Subject: [PATCH 2/2] only do data digest if check is enabled --- server.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server.cpp b/server.cpp index db51b48..0059290 100644 --- a/server.cpp +++ b/server.cpp @@ -211,7 +211,9 @@ std::tuple server::receive_pdu(com_client *cons else { pdu_obj->set_data({ data_temp, data_length }); } - auto incoming_crc32c = crc32_0x11EDC6F41(data_temp, padded_data_length, { }); + std::pair incoming_crc32c { }; + if (digest_chk) + incoming_crc32c = crc32_0x11EDC6F41(data_temp, padded_data_length, { }); delete [] data_temp; (*ses)->add_bytes_rx(padded_data_length);