Skip to contentSkip to conversation

scsi: iscsi: Exclude zero from the endpoint ID range

PATCH Applied Sergey Gorenko 4 participants 4 messages Jun 13, 2022 – Jun 14, 2022

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

PATCH 1/1 scsi: iscsi: Exclude zero from the endpoint ID range

The kernel returns an endpoint ID as r.ep_connect_ret.handle in the iscsi_uevent. The iscsid validates a received endpoint ID and treats zero as an error. The commit referenced in the fixes line changed the endpoint ID range, and zero is always assigned to the first endpoint ID. So, the first attempt to create a new iSER connection always fails.

Fixes 3c6ae371b8a1 ("scsi: iscsi: Release endpoint ID when its freed")
---
 drivers/scsi/scsi_transport_iscsi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/scsi_transport_iscsi.c +6 -1
index 2c0dd64159b0..5d21f07456c6 100644
@@ -212,7 +212,12 @@ iscsi_create_endpoint(int dd_size)
 		return NULL;
 
 	mutex_lock(&iscsi_ep_idr_mutex);
-	id = idr_alloc(&iscsi_ep_idr, ep, 0, -1, GFP_NOIO);
+
+	/*
+	 * First endpoint id should be 1 to comply with user space
+	 * applications (iscsid).
+	 */
+	id = idr_alloc(&iscsi_ep_idr, ep, 1, -1, GFP_NOIO);
 	if (id < 0) {
 		mutex_unlock(&iscsi_ep_idr_mutex);
 		printk(KERN_ERR "Could not allocate endpoint ID. Error %d.\n",
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Sergey Gorenko

The kernel returns an endpoint ID as r.ep_connect_ret.handle in the iscsi_uevent. The iscsid validates a received endpoint ID and treats zero as an error. The commit referenced in the fixes line changed the endpoint ID range, and zero is always assigned to the first endpoint ID. So, the first attempt to create a new iSER connection always fails.

Fixes 3c6ae371b8a1 ("scsi: iscsi: Release endpoint ID when its freed")
---
 drivers/scsi/scsi_transport_iscsi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/scsi_transport_iscsi.c +0 -0
index 2c0dd64159b0..5d21f07456c6 100644
@@ -212,7 +212,12 @@ iscsi_create_endpoint(int dd_size)
 		return NULL;
 
 	mutex_lock(&iscsi_ep_idr_mutex);

drivers/scsi/scsi_transport_iscsi.c iscsi_create_endpoint(int dd_size) · line 223

Quoted 10 lines
drivers/scsi/scsi_transport_iscsi.c +6 -1
-	id = idr_alloc(&iscsi_ep_idr, ep, 0, -1, GFP_NOIO);
+
+	/*
+	 * First endpoint id should be 1 to comply with user space
+	 * applications (iscsid).
+	 */
+	id = idr_alloc(&iscsi_ep_idr, ep, 1, -1, GFP_NOIO);
 	if (id < 0) {
 		mutex_unlock(&iscsi_ep_idr_mutex);
 		printk(KERN_ERR "Could not allocate endpoint ID. Error %d.\n",

Varun submitted a similar patch yesterday:

https://lore.kernel.org/all/[email protected]/T/

Your patch is nicer, because it has the comment about userspace. Let's go with the patch in this email.

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Sergey Gorenko
Quoted 21 lines · Sergey Gorenko

The kernel returns an endpoint ID as r.ep_connect_ret.handle in the iscsi_uevent. The iscsid validates a received endpoint ID and treats zero as an error. The commit referenced in the fixes line changed the endpoint ID range, and zero is always assigned to the first endpoint ID. So, the first attempt to create a new iSER connection always fails.

Fixes 3c6ae371b8a1 ("scsi: iscsi: Release endpoint ID when its freed")
---
  drivers/scsi/scsi_transport_iscsi.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/scsi_transport_iscsi.c +0 -0
index 2c0dd64159b0..5d21f07456c6 100644
@@ -212,7 +212,12 @@ iscsi_create_endpoint(int dd_size)
  		return NULL;
 
  	mutex_lock(&iscsi_ep_idr_mutex);

drivers/scsi/scsi_transport_iscsi.c iscsi_create_endpoint(int dd_size) · line 223

Quoted 10 lines
drivers/scsi/scsi_transport_iscsi.c +6 -1
-	id = idr_alloc(&iscsi_ep_idr, ep, 0, -1, GFP_NOIO);
+
+	/*
+	 * First endpoint id should be 1 to comply with user space
+	 * applications (iscsid).
+	 */
+	id = idr_alloc(&iscsi_ep_idr, ep, 1, -1, GFP_NOIO);
  	if (id < 0) {
  		mutex_unlock(&iscsi_ep_idr_mutex);
  		printk(KERN_ERR "Could not allocate endpoint ID. Error %d.\n",
#3 lore raw
In reply to Sergey Gorenko
Quoted 8 lines · Sergey Gorenko

The kernel returns an endpoint ID as r.ep_connect_ret.handle in the iscsi_uevent. The iscsid validates a received endpoint ID and treats zero as an error. The commit referenced in the fixes line changed the endpoint ID range, and zero is always assigned to the first endpoint ID. So, the first attempt to create a new iSER connection always fails.

[...]

Applied to 5.19/scsi-fixes, thanks!

[1/1] scsi: iscsi: Exclude zero from the endpoint ID range

      https://git.kernel.org/mkp/scsi/c/f6eed15f3ea7
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering