Skip to content

Commit 2fc431d

Browse files
Nicholas Bellingergregkh
authored andcommitted
iscsi-target: Fail connection on short sendmsg writes
commit 6bf6ca7 upstream. This patch changes iscsit_do_tx_data() to fail on short writes when kernel_sendmsg() returns a value different than requested transfer length, returning -EPIPE and thus causing a connection reset to occur. This avoids a potential bug in the original code where a short write would result in kernel_sendmsg() being called again with the original iovec base + length. In practice this has not been an issue because iscsit_do_tx_data() is only used for transferring 48 byte headers + 4 byte digests, along with seldom used control payloads from NOPIN + TEXT_RSP + REJECT with less than 32k of data. So following Al's audit of iovec consumers, go ahead and fail the connection on short writes for now, and remove the bogus logic ahead of his proper upstream fix. Reported-by: Al Viro <viro@zeniv.linux.org.uk> Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a27d8a2 commit 2fc431d

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

‎drivers/target/iscsi/iscsi_target_util.c‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,15 +1358,15 @@ static int iscsit_do_tx_data(
13581358
struct iscsi_conn *conn,
13591359
struct iscsi_data_count *count)
13601360
{
1361-
int data = count->data_length, total_tx = 0, tx_loop = 0, iov_len;
1361+
int ret, iov_len;
13621362
struct kvec *iov_p;
13631363
struct msghdr msg;
13641364

13651365
if (!conn || !conn->sock || !conn->conn_ops)
13661366
return -1;
13671367

1368-
if (data <= 0) {
1369-
pr_err("Data length is: %d\n", data);
1368+
if (count->data_length <= 0) {
1369+
pr_err("Data length is: %d\n", count->data_length);
13701370
return -1;
13711371
}
13721372

@@ -1375,20 +1375,16 @@ static int iscsit_do_tx_data(
13751375
iov_p = count->iov;
13761376
iov_len = count->iov_count;
13771377

1378-
while (total_tx < data) {
1379-
tx_loop = kernel_sendmsg(conn->sock, &msg, iov_p, iov_len,
1380-
(data - total_tx));
1381-
if (tx_loop <= 0) {
1382-
pr_debug("tx_loop: %d total_tx %d\n",
1383-
tx_loop, total_tx);
1384-
return tx_loop;
1385-
}
1386-
total_tx += tx_loop;
1387-
pr_debug("tx_loop: %d, total_tx: %d, data: %d\n",
1388-
tx_loop, total_tx, data);
1378+
ret = kernel_sendmsg(conn->sock, &msg, iov_p, iov_len,
1379+
count->data_length);
1380+
if (ret != count->data_length) {
1381+
pr_err("Unexpected ret: %d send data %d\n",
1382+
ret, count->data_length);
1383+
return -EPIPE;
13891384
}
1385+
pr_debug("ret: %d, sent data: %d\n", ret, count->data_length);
13901386

1391-
return total_tx;
1387+
return ret;
13921388
}
13931389

13941390
int rx_data(

0 commit comments

Comments
 (0)