Skip to contentSkip to conversation

libiscsi: fix potential buffer overrun in __iscsi_conn_send_pdu

PATCH In review [email protected] 3 participants 3 messages Sep 3, 2014 – Sep 7, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libiscsi: fix potential buffer overrun in __iscsi_conn_send_pdu

From: Mike Christie <[email protected]>

This patches fixes a potential buffer overrun in __iscsi_conn_send_pdu. This function is used by iscsi drivers and userspace to send iscsi PDUs/ commands. For login commands, we have a set buffer size. For all other commands we do not support data buffers.

This was reported by Dan Carpenter here:
http://www.spinics.net/lists/linux-scsi/msg66838.html

---
 drivers/scsi/libiscsi.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/scsi/libiscsi.c +10 -0
index ea025e4..191b597 100644
@@ -717,11 +717,21 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 			return NULL;
 		}
 
+		if (data_size > ISCSI_DEF_MAX_RECV_SEG_LEN) {
+			iscsi_conn_printk(KERN_ERR, conn, "Invalid buffer len of %u for login task. Max len is %u\n", data_size, ISCSI_DEF_MAX_RECV_SEG_LEN);
+			return NULL;
+		}
+
 		task = conn->login_task;
 	} else {
 		if (session->state != ISCSI_STATE_LOGGED_IN)
 			return NULL;
 
+		if (data_size != 0) {
+			iscsi_conn_printk(KERN_ERR, conn, "Can not send data buffer of len %u for op 0x%x\n", data_size, opcode);
+			return NULL;
+		}
+
 		BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE);
 		BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED);
 
Signature · 1 line
1.7.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Wed, Sep 03, 2014 at 12:00:39AM -0500, [email protected] wrote:

From: Mike Christie <[email protected]>

This patches fixes a potential buffer overrun in __iscsi_conn_send_pdu. This function is used by iscsi drivers and userspace to send iscsi PDUs/ commands. For login commands, we have a set buffer size. For all other commands we do not support data buffers.

Quoted 5 lines

This was reported by Dan Carpenter here:
http://www.spinics.net/lists/linux-scsi/msg66838.html

Looks good,

Reviewed-by on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 33 lines · On 9/3/2014 8:00 AM, [email protected] wrote:

From: Mike Christie <[email protected]>

This patches fixes a potential buffer overrun in __iscsi_conn_send_pdu. This function is used by iscsi drivers and userspace to send iscsi PDUs/ commands. For login commands, we have a set buffer size. For all other commands we do not support data buffers.

This was reported by Dan Carpenter here:
http://www.spinics.net/lists/linux-scsi/msg66838.html

---
  drivers/scsi/libiscsi.c |   10 ++++++++++
  1 files changed, 10 insertions(+), 0 deletions(-)
drivers/scsi/libiscsi.c +5 -0
index ea025e4..191b597 100644
@@ -717,11 +717,21 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  			return NULL;
  		}
 
+		if (data_size > ISCSI_DEF_MAX_RECV_SEG_LEN) {
+			iscsi_conn_printk(KERN_ERR, conn, "Invalid buffer len of %u for login task. Max len is %u\n", data_size, ISCSI_DEF_MAX_RECV_SEG_LEN);
+			return NULL;
+		}
+
  		task = conn->login_task;
  	} else {
  		if (session->state != ISCSI_STATE_LOGGED_IN)

drivers/scsi/libiscsi.c __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, · line 737

Quoted 10 lines
drivers/scsi/libiscsi.c +5 -0
  			return NULL;
 
+		if (data_size != 0) {
+			iscsi_conn_printk(KERN_ERR, conn, "Can not send data buffer of len %u for op 0x%x\n", data_size, opcode);
+			return NULL;
+		}
+
  		BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE);
  		BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED);
 

Looks good to me too,