scsi: target: fix unsigned comparision with less than zero
Subsystems (3)
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.
--- drivers/target/target_core_configfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/target/target_core_configfs.c +6 -3
@@ -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
Quoted 5 lines · Colin King
From: Colin Ian King <[email protected]>
Currently an error return is being assigned to an unsigned
size_tvarianle 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_trather than asize_t.Fixes 0322913cab79 ("scsi: target: Add device product id and revision configfs attributes")Signed-off-by Colin Ian King <[email protected]>--- drivers/target/target_core_configfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/target/target_core_configfs.c +6
-3@@ -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)) {
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_tvarianle and then checked if the result is less than zero which will always be false. Fix this by making retWhat 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_trather than asize_t.Fixes 0322913cab79 ("scsi: target: Add device product id and revision configfs attributes")Signed-off-by Colin Ian King <[email protected]>--- drivers/target/target_core_configfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/target/target_core_configfs.c +6
-3@@ -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)) {
Mike Christie
Reviewed-byQuoted 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_tvarianle 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.
Martin K. Petersen
AppliedColin,
Quoted 3 lines
Currently an error return is being assigned to an unsigned
size_tvarianle and then checked if the result is less than zero which will always be false. Fix this by making retssize_trather than asize_t.
Applied to 5.2/scsi-queue, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering