Skip to contentSkip to conversation

target: fix truncated PR-in ReadKeys response

PATCH Superseded David Disseldorp 3 participants 6 messages May 31, 2018 – Jun 4, 2018 SCSI target

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: fix truncated PR-in ReadKeys response

SPC5r17 states that the contents of the ADDITIONAL LENGTH field are not altered based on the allocation length, so always calculate and pack the full key list length even if the list itself is truncated.

This behaviour can be tested using the libiscsi PrinReadKeys.Truncate test.

---
 drivers/target/target_core_pr.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/target/target_core_pr.c +10 -5
index 01ac306131c1..2e865fdaa362 100644
@@ -3727,11 +3727,16 @@ core_scsi3_pri_read_keys(struct se_cmd *cmd)
 		 * Check for overflow of 8byte PRI READ_KEYS payload and
 		 * next reservation key list descriptor.
 		 */
-		if ((add_len + 8) > (cmd->data_length - 8))
-			break;
-
-		put_unaligned_be64(pr_reg->pr_res_key, &buf[off]);
-		off += 8;
+		if ((off + 8) <= cmd->data_length) {
+			put_unaligned_be64(pr_reg->pr_res_key, &buf[off]);
+			off += 8;
+		}
+		/*
+		 * SPC5r17: 6.16.2 READ KEYS service action
+		 * The ADDITIONAL LENGTH field indicates the number of bytes in
+		 * the Reservation key list. The contents of the ADDITIONAL
+		 * LENGTH field are not altered based on the allocation length
+		 */
 		add_len += 8;
 	}
 	spin_unlock(&dev->t10_pr.registration_lock);
Signature · 1 line
2.13.6
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · David Disseldorp

SPC5r17 states that the contents of the ADDITIONAL LENGTH field are not altered based on the allocation length, so always calculate and pack the full key list length even if the list itself is truncated.

This behaviour can be tested using the libiscsi PrinReadKeys.Truncate test.

---
 drivers/target/target_core_pr.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/target/target_core_pr.c +3 -5
index 01ac306131c1..2e865fdaa362 100644
@@ -3727,11 +3727,16 @@ core_scsi3_pri_read_keys(struct se_cmd *cmd)
 		 * Check for overflow of 8byte PRI READ_KEYS payload and
 		 * next reservation key list descriptor.
 		 */
-		if ((add_len + 8) > (cmd->data_length - 8))
-			break;
-
-		put_unaligned_be64(pr_reg->pr_res_key, &buf[off]);
-		off += 8;
+		if ((off + 8) <= cmd->data_length) {
+			put_unaligned_be64(pr_reg->pr_res_key, &buf[off]);
+			off += 8;

drivers/target/target_core_pr.c core_scsi3_pri_read_keys(struct se_cmd *cmd) · line 3742

Quoted 10 lines
drivers/target/target_core_pr.c +7 -0
+		}
+		/*
+		 * SPC5r17: 6.16.2 READ KEYS service action
+		 * The ADDITIONAL LENGTH field indicates the number of bytes in
+		 * the Reservation key list. The contents of the ADDITIONAL
+		 * LENGTH field are not altered based on the allocation length
+		 */
 		add_len += 8;
 	}
 	spin_unlock(&dev->t10_pr.registration_lock);

Looks ok to me.

#2 lore raw
In reply to David Disseldorp

--------------------------------------------------
From: "David Disseldorp" <[email protected]>
Sent: Friday, June 01, 2018 1:20 AM
To: <[email protected]>
Cc: "ronnie sahlberg" <[email protected]>; "David Disseldorp" <[email protected]>
Subject: [PATCH] target: fix truncated PR-in ReadKeys response

Quoted 46 lines

SPC5r17 states that the contents of the ADDITIONAL LENGTH field are not altered based on the allocation length, so always calculate and pack the full key list length even if the list itself is truncated.

This behaviour can be tested using the libiscsi PrinReadKeys.Truncate test.

---
drivers/target/target_core_pr.c | 15 ++++++++++-----

1 file changed, 10 insertions(+), 5 deletions(-)
drivers/target/target_core_pr.c +10 -5
index 01ac306131c1..2e865fdaa362 100644
@@ -3727,11 +3727,16 @@ core_scsi3_pri_read_keys(struct se_cmd *cmd)
 * Check for overflow of 8byte PRI READ_KEYS payload and
 * next reservation key list descriptor.
 */
- if ((add_len + 8) > (cmd->data_length - 8))
- break;
-
- put_unaligned_be64(pr_reg->pr_res_key, &buf[off]);
- off += 8;
+ if ((off + 8) <= cmd->data_length) {
+ put_unaligned_be64(pr_reg->pr_res_key, &buf[off]);
+ off += 8;
+ }
+ /*
+ * SPC5r17: 6.16.2 READ KEYS service action
+ * The ADDITIONAL LENGTH field indicates the number of bytes in
+ * the Reservation key list. The contents of the ADDITIONAL
+ * LENGTH field are not altered based on the allocation length
+ */
 add_len += 8;
 }
 spin_unlock(&dev->t10_pr.registration_lock);
Signature · 6 lines
2.13.6

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

This also fixes an issue in Windows server 2016 failover cluster with many client connections, the initial allocation length sent in cdb is 72 bytes which limits it to 8 keys, with additional length not affected by truncation, it will retry with correct size.
Interesting I was looking at the same issue in target_core_rbd.

#3 lore raw
In reply to David Disseldorp
Quoted 4 lines · Maged Mokhtar

This also fixes an issue in Windows server 2016 failover cluster with many client connections, the initial allocation length sent in cdb is 72 bytes which limits it to 8 keys, with additional length not affected by truncation, it will retry with correct size.

Interesting coincidence :) I only ran into this while looking at the spec for the enable_pr change. Can you confirm that this fixes Win 2016 PR behaviour with an iblock / ifile backstore? If so I'll respin the patch with an extra note in the commit message.

Cheers, David

#4 lore raw
In reply to David Disseldorp
Quoted 8 lines · David Disseldorp
Quoted 5 lines · Maged Mokhtar

This also fixes an issue in Windows server 2016 failover cluster with many client connections, the initial allocation length sent in cdb is 72 bytes which limits it to 8 keys, with additional length not affected
by truncation, it will retry with correct size.

Quoted 7 lines

Interesting coincidence :) I only ran into this while looking at the spec for the enable_pr change. Can you confirm that this fixes Win 2016 PR behaviour with an iblock / ifile backstore? If so I'll respin the patch with an extra note in the commit message.

Cheers, David
--

Yes it fixes the "Storage Spaces Persistent Reservation" test in the Windows 2016 Server Failover Cluster validation suites when having many connections that result in more than 8 registrations. I tested your patch on 4.17 with iblock.

#5 lore raw
In reply to David Disseldorp
Quoted 4 lines · Maged Mokhtar

Yes it fixes the "Storage Spaces Persistent Reservation" test in the Windows 2016 Server Failover Cluster validation suites when having many connections that result in more than 8 registrations. I tested your patch on 4.17 with iblock.

Thanks a lot for confirming this, Maged. Patch with new commit message to follow...

Cheers, David