Skip to contentSkip to conversation

target/iscsi: fix digest computation for chained SGs

PATCH Applied Spencer Baugh 4 participants 4 messages Jul 21, 2015 – Jul 31, 2015

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

PATCH 1/1 target/iscsi: fix digest computation for chained SGs

From: Alexei Potashnik <[email protected]>

Current implementation assumes that all the buffers of an IO are linked with a single SG list. Which makes it fail if SG chaining is used.

---
 drivers/target/iscsi/iscsi_target.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/target/iscsi/iscsi_target.c +4 -5
index 4e68b62..a4cf58c 100644
@@ -1209,7 +1209,6 @@ static u32 iscsit_do_crypto_hash_sg(
 	u8 *pad_bytes)
 {
 	u32 data_crc;
-	u32 i;
 	struct scatterlist *sg;
 	unsigned int page_off;
 
@@ -1218,15 +1217,15 @@ static u32 iscsit_do_crypto_hash_sg(
 	sg = cmd->first_data_sg;
 	page_off = cmd->first_data_sg_off;
 
-	i = 0;
 	while (data_length) {
-		u32 cur_len = min_t(u32, data_length, (sg[i].length - page_off));
+		u32 cur_len = min_t(u32, data_length, (sg->length - page_off));
 
-		crypto_hash_update(hash, &sg[i], cur_len);
+		crypto_hash_update(hash, sg, cur_len);
 
 		data_length -= cur_len;
 		page_off = 0;
-		i++;
+		/* iscsit_map_iovec has already checked for invalid sg pointers */
+		sg = sg_next(sg);
 	}
 
 	if (padding) {
Signature · 1 line
2.4.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Spencer Baugh

From: Alexei Potashnik <[email protected]>

Current implementation assumes that all the buffers of an IO are linked with a single SG list. Which makes it fail if SG chaining is used.

---
  drivers/target/iscsi/iscsi_target.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
drivers/target/iscsi/iscsi_target.c +1 -4
index 4e68b62..a4cf58c 100644
@@ -1209,7 +1209,6 @@ static u32 iscsit_do_crypto_hash_sg(
  	u8 *pad_bytes)
  {
  	u32 data_crc;
-	u32 i;
  	struct scatterlist *sg;
  	unsigned int page_off;
 
@@ -1218,15 +1217,15 @@ static u32 iscsit_do_crypto_hash_sg(
  	sg = cmd->first_data_sg;
  	page_off = cmd->first_data_sg_off;
 
-	i = 0;
  	while (data_length) {
-		u32 cur_len = min_t(u32, data_length, (sg[i].length - page_off));
+		u32 cur_len = min_t(u32, data_length, (sg->length - page_off));
 
-		crypto_hash_update(hash, &sg[i], cur_len);

drivers/target/iscsi/iscsi_target.c static u32 iscsit_do_crypto_hash_sg( · line 1231

Quoted 10 lines
drivers/target/iscsi/iscsi_target.c +3 -1
+		crypto_hash_update(hash, sg, cur_len);
 
  		data_length -= cur_len;
  		page_off = 0;
-		i++;
+		/* iscsit_map_iovec has already checked for invalid sg pointers */
+		sg = sg_next(sg);
  	}
 
  	if (padding) {

How were you able to get a chained SG list in the target code?

In any event, looks good,

#2 lore raw
Quoted 1 line · Sagi Grimberg

How were you able to get a chained SG list in the target code?

Local hack. So this bug can't be hit in current mainline code, but patch improves the code and removes a hidden booby-trap, so I think it makes sense to apply.

#3 lore raw
Quoted 7 lines · Roland Dreier
Quoted 1 line · Sagi Grimberg

How were you able to get a chained SG list in the target code?

Local hack. So this bug can't be hit in current mainline code, but patch improves the code and removes a hidden booby-trap, so I think it makes sense to apply.
--

Applied to target-pending/for-next.

Thanks Roland & Co.