Skip to content

Commit

Permalink
[iscsi] Send any padding inline with the data segment
Browse files Browse the repository at this point in the history
Some iSCSI targets respond to a PDU before receiving the padding
bytes.  If the target responds quickly enough, this can cause iPXE to
start processing a new TX PDU before the padding bytes have been sent,
which results in a protocol violation.

Fix by always transmitting the padding bytes along with the data
segment.

Originally-fixed-by: Shyam Iyer <shyam_iyer@dell.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Mar 1, 2012
1 parent cb10137 commit 1d29377
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
2 changes: 0 additions & 2 deletions src/include/ipxe/iscsi.h
Expand Up @@ -515,8 +515,6 @@ enum iscsi_tx_state {
ISCSI_TX_AHS,
/** Sending the data segment */
ISCSI_TX_DATA,
/** Sending the data segment padding */
ISCSI_TX_DATA_PADDING,
};

/** State of an iSCSI RX engine */
Expand Down
37 changes: 9 additions & 28 deletions src/net/tcp/iscsi.c
Expand Up @@ -570,20 +570,23 @@ static int iscsi_tx_data_out ( struct iscsi_session *iscsi ) {
struct io_buffer *iobuf;
unsigned long offset;
size_t len;
size_t pad_len;

offset = ntohl ( data_out->offset );
len = ISCSI_DATA_LEN ( data_out->lengths );
pad_len = ISCSI_DATA_PAD_LEN ( data_out->lengths );

assert ( iscsi->command != NULL );
assert ( iscsi->command->data_out );
assert ( ( offset + len ) <= iscsi->command->data_out_len );

iobuf = xfer_alloc_iob ( &iscsi->socket, len );
iobuf = xfer_alloc_iob ( &iscsi->socket, ( len + pad_len ) );
if ( ! iobuf )
return -ENOMEM;

copy_from_user ( iob_put ( iobuf, len ),
iscsi->command->data_out, offset, len );
memset ( iob_put ( iobuf, pad_len ), 0, pad_len );

return xfer_deliver_iob ( &iscsi->socket, iobuf );
}
Expand Down Expand Up @@ -801,13 +804,17 @@ static int iscsi_tx_login_request ( struct iscsi_session *iscsi ) {
struct iscsi_bhs_login_request *request = &iscsi->tx_bhs.login_request;
struct io_buffer *iobuf;
size_t len;
size_t pad_len;

len = ISCSI_DATA_LEN ( request->lengths );
iobuf = xfer_alloc_iob ( &iscsi->socket, len );
pad_len = ISCSI_DATA_PAD_LEN ( request->lengths );
iobuf = xfer_alloc_iob ( &iscsi->socket, ( len + pad_len ) );
if ( ! iobuf )
return -ENOMEM;
iob_put ( iobuf, len );
iscsi_build_login_request_strings ( iscsi, iobuf->data, len );
memset ( iob_put ( iobuf, pad_len ), 0, pad_len );

return xfer_deliver_iob ( &iscsi->socket, iobuf );
}

Expand Down Expand Up @@ -1415,27 +1422,6 @@ static int iscsi_tx_data ( struct iscsi_session *iscsi ) {
}
}

/**
* Transmit data padding of an iSCSI PDU
*
* @v iscsi iSCSI session
* @ret rc Return status code
*
* Handle transmission of any data padding in a PDU data segment.
* iscsi::tx_bhs will be valid when this is called.
*/
static int iscsi_tx_data_padding ( struct iscsi_session *iscsi ) {
static const char pad[] = { '\0', '\0', '\0' };
struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
size_t pad_len;

pad_len = ISCSI_DATA_PAD_LEN ( common->lengths );
if ( ! pad_len )
return 0;

return xfer_deliver_raw ( &iscsi->socket, pad, pad_len );
}

/**
* Complete iSCSI PDU transmission
*
Expand Down Expand Up @@ -1494,11 +1480,6 @@ static void iscsi_tx_step ( struct iscsi_session *iscsi ) {
case ISCSI_TX_DATA:
tx = iscsi_tx_data;
tx_len = ISCSI_DATA_LEN ( common->lengths );
next_state = ISCSI_TX_DATA_PADDING;
break;
case ISCSI_TX_DATA_PADDING:
tx = iscsi_tx_data_padding;
tx_len = ISCSI_DATA_PAD_LEN ( common->lengths );
next_state = ISCSI_TX_IDLE;
break;
case ISCSI_TX_IDLE:
Expand Down

0 comments on commit 1d29377

Please sign in to comment.