Skip to contentSkip to conversation

scsi: target: fix unsigned comparision with less than zero

PATCH Applied Colin King 3 participants 5 messages Mar 20, 2019 – Mar 21, 2019

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 scsi: target: fix unsigned comparision with less than zero

From: Colin Ian King <[email protected]>

Currently an error return is being assigned to an unsigned size_t varianle and then checked if the result is less than zero which will always be false. Fix this by making ret ssize_t rather than a size_t.

Fixes 0322913cab79 ("scsi: target: Add device product id and revision configfs attributes")
---
 drivers/target/target_core_configfs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/target/target_core_configfs.c +6 -3
index 8f3faef235b5..3fe79875b3ac 100644
@@ -1267,7 +1267,8 @@ static ssize_t target_wwn_vendor_id_store(struct config_item *item,
 	/* +2 to allow for a trailing (stripped) '\n' and null-terminator */
 	unsigned char buf[INQUIRY_VENDOR_LEN + 2];
 	char *stripped = NULL;
-	size_t len, ret;
+	size_t len;
+	ssize_t ret;
 
 	len = strlcpy(buf, page, sizeof(buf));
 	if (len < sizeof(buf)) {
@@ -1322,7 +1323,8 @@ static ssize_t target_wwn_product_id_store(struct config_item *item,
 	/* +2 to allow for a trailing (stripped) '\n' and null-terminator */
 	unsigned char buf[INQUIRY_MODEL_LEN + 2];
 	char *stripped = NULL;
-	size_t len, ret;
+	size_t len;
+	ssize_t ret;
 
 	len = strlcpy(buf, page, sizeof(buf));
 	if (len < sizeof(buf)) {
@@ -1377,7 +1379,8 @@ static ssize_t target_wwn_revision_store(struct config_item *item,
 	/* +2 to allow for a trailing (stripped) '\n' and null-terminator */
 	unsigned char buf[INQUIRY_REVISION_LEN + 2];
 	char *stripped = NULL;
-	size_t len, ret;
+	size_t len;
+	ssize_t ret;
 
 	len = strlcpy(buf, page, sizeof(buf));
 	if (len < sizeof(buf)) {
Signature · 1 line
2.20.1
#1 lore raw
Quoted 5 lines · Colin King

From: Colin Ian King <[email protected]>

Currently an error return is being assigned to an unsigned size_t varianle and then checked if the result is less than zero which will always be false. Fix this by making ret

What kernel version was this made against?

For Martin's 5.2 queue branch, with these scsi changes it looks like strlcpy returns a size_t. And then below it looks like we compare the return value from that function to the buffer size and the max len of the string we support. We do not seem to check for less than zero.

Quoted 43 lines

ssize_t rather than a size_t.

Fixes 0322913cab79 ("scsi: target: Add device product id and revision configfs attributes")
---
 drivers/target/target_core_configfs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/target/target_core_configfs.c +6 -3
index 8f3faef235b5..3fe79875b3ac 100644
@@ -1267,7 +1267,8 @@ static ssize_t target_wwn_vendor_id_store(struct config_item *item,
 	/* +2 to allow for a trailing (stripped) '\n' and null-terminator */
 	unsigned char buf[INQUIRY_VENDOR_LEN + 2];
 	char *stripped = NULL;
-	size_t len, ret;
+	size_t len;
+	ssize_t ret;
 
 	len = strlcpy(buf, page, sizeof(buf));
 	if (len < sizeof(buf)) {
@@ -1322,7 +1323,8 @@ static ssize_t target_wwn_product_id_store(struct config_item *item,
 	/* +2 to allow for a trailing (stripped) '\n' and null-terminator */
 	unsigned char buf[INQUIRY_MODEL_LEN + 2];
 	char *stripped = NULL;
-	size_t len, ret;
+	size_t len;
+	ssize_t ret;
 
 	len = strlcpy(buf, page, sizeof(buf));
 	if (len < sizeof(buf)) {
@@ -1377,7 +1379,8 @@ static ssize_t target_wwn_revision_store(struct config_item *item,
 	/* +2 to allow for a trailing (stripped) '\n' and null-terminator */
 	unsigned char buf[INQUIRY_REVISION_LEN + 2];
 	char *stripped = NULL;
-	size_t len, ret;
+	size_t len;
+	ssize_t ret;
 
 	len = strlcpy(buf, page, sizeof(buf));
 	if (len < sizeof(buf)) {
#2 lore raw
Quoted 8 lines · Mike Christie
Quoted 5 lines · Colin King

From: Colin Ian King <[email protected]>

Currently an error return is being assigned to an unsigned size_t varianle and then checked if the result is less than zero which will always be false. Fix this by making ret

What kernel version was this made against?

today's linux-next

Quoted 50 lines

For Martin's 5.2 queue branch, with these scsi changes it looks like strlcpy returns a size_t. And then below it looks like we compare the return value from that function to the buffer size and the max len of the string we support. We do not seem to check for less than zero.

Quoted 43 lines

ssize_t rather than a size_t.

Fixes 0322913cab79 ("scsi: target: Add device product id and revision configfs attributes")
---
 drivers/target/target_core_configfs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/target/target_core_configfs.c +6 -3
index 8f3faef235b5..3fe79875b3ac 100644
@@ -1267,7 +1267,8 @@ static ssize_t target_wwn_vendor_id_store(struct config_item *item,
 	/* +2 to allow for a trailing (stripped) '\n' and null-terminator */
 	unsigned char buf[INQUIRY_VENDOR_LEN + 2];
 	char *stripped = NULL;
-	size_t len, ret;
+	size_t len;
+	ssize_t ret;
 
 	len = strlcpy(buf, page, sizeof(buf));
 	if (len < sizeof(buf)) {
@@ -1322,7 +1323,8 @@ static ssize_t target_wwn_product_id_store(struct config_item *item,
 	/* +2 to allow for a trailing (stripped) '\n' and null-terminator */
 	unsigned char buf[INQUIRY_MODEL_LEN + 2];
 	char *stripped = NULL;
-	size_t len, ret;
+	size_t len;
+	ssize_t ret;
 
 	len = strlcpy(buf, page, sizeof(buf));
 	if (len < sizeof(buf)) {
@@ -1377,7 +1379,8 @@ static ssize_t target_wwn_revision_store(struct config_item *item,
 	/* +2 to allow for a trailing (stripped) '\n' and null-terminator */
 	unsigned char buf[INQUIRY_REVISION_LEN + 2];
 	char *stripped = NULL;
-	size_t len, ret;
+	size_t len;
+	ssize_t ret;
 
 	len = strlcpy(buf, page, sizeof(buf));
 	if (len < sizeof(buf)) {
Reviewed-by
#3 lore raw
In reply to Mike Christie
Quoted 7 lines · Mike Christie
Quoted 5 lines · Colin King

From: Colin Ian King <[email protected]>

Currently an error return is being assigned to an unsigned size_t varianle and then checked if the result is less than zero which will always be false. Fix this by making ret

Quoted 8 lines

What kernel version was this made against?

For Martin's 5.2 queue branch, with these scsi changes it looks like strlcpy returns a size_t. And then below it looks like we compare the return value from that function to the buffer size and the max len of the string we support. We do not seem to check for less than zero.

My mistake. I was looking at len and not ret.

Patch looks ok to me.

#4 lore raw
In reply to Colin King

Colin,

Quoted 3 lines

Currently an error return is being assigned to an unsigned size_t varianle and then checked if the result is less than zero which will always be false. Fix this by making ret ssize_t rather than a size_t.

Applied to 5.2/scsi-queue, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering