From 1cbeec6bdc951a2a4261d7060e286d6dc38dfa01 Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Thu, 5 Jan 2017 14:41:21 +0100 Subject: [PATCH] pdu: verify header digest we never verified the received header digest. do that now. Signed-off-by: Peter Lieven --- lib/pdu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/pdu.c b/lib/pdu.c index 1275b33..63adcc6 100644 --- a/lib/pdu.c +++ b/lib/pdu.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "iscsi.h" #include "iscsi-private.h" #include "scsi-lowlevel.h" @@ -429,6 +430,20 @@ iscsi_process_pdu(struct iscsi_context *iscsi, struct iscsi_in_pdu *in) uint8_t ahslen = in->hdr[4]; struct iscsi_pdu *pdu; + /* verify header checksum */ + if (iscsi->header_digest != ISCSI_HEADER_DIGEST_NONE) { + uint32_t crc, crc_rcvd = 0; + crc = crc32c(in->hdr, ISCSI_RAW_HEADER_SIZE); + crc_rcvd |= in->hdr[ISCSI_RAW_HEADER_SIZE+0]; + crc_rcvd |= in->hdr[ISCSI_RAW_HEADER_SIZE+1] << 8; + crc_rcvd |= in->hdr[ISCSI_RAW_HEADER_SIZE+2] << 16; + crc_rcvd |= in->hdr[ISCSI_RAW_HEADER_SIZE+3] << 24; + if (crc != crc_rcvd) { + iscsi_set_error(iscsi, "header checksum verification failed: calculated 0x%" PRIx32 " received 0x%" PRIx32, crc, crc_rcvd); + return -1; + } + } + if (ahslen != 0) { iscsi_set_error(iscsi, "cant handle expanded headers yet"); return -1;