linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] scsi: target: fix unsigned comparision with less than zero
@ 2019-03-20 16:37 Colin King
  2019-03-20 17:14 ` Mike Christie
  2019-03-21  0:33 ` Martin K. Petersen
  0 siblings, 2 replies; 5+ messages in thread
From: Colin King @ 2019-03-20 16:37 UTC (permalink / raw)
  To: Martin K . Petersen, linux-scsi, target-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

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")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/target/target_core_configfs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 8f3faef235b5..3fe79875b3ac 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -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.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH][next] scsi: target: fix unsigned comparision with less than zero
  2019-03-20 16:37 [PATCH][next] scsi: target: fix unsigned comparision with less than zero Colin King
@ 2019-03-20 17:14 ` Mike Christie
  2019-03-20 17:14   ` Colin Ian King
  2019-03-20 17:15   ` Mike Christie
  2019-03-21  0:33 ` Martin K. Petersen
  1 sibling, 2 replies; 5+ messages in thread
From: Mike Christie @ 2019-03-20 17:14 UTC (permalink / raw)
  To: Colin King, Martin K . Petersen, linux-scsi, target-devel
  Cc: kernel-janitors, linux-kernel

On 03/20/2019 11:37 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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.


> ssize_t rather than a size_t.
> 
> Fixes: 0322913cab79 ("scsi: target: Add device product id and revision configfs attributes")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/target/target_core_configfs.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
> index 8f3faef235b5..3fe79875b3ac 100644
> --- a/drivers/target/target_core_configfs.c
> +++ b/drivers/target/target_core_configfs.c
> @@ -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)) {
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH][next] scsi: target: fix unsigned comparision with less than zero
  2019-03-20 17:14 ` Mike Christie
@ 2019-03-20 17:14   ` Colin Ian King
  2019-03-20 17:15   ` Mike Christie
  1 sibling, 0 replies; 5+ messages in thread
From: Colin Ian King @ 2019-03-20 17:14 UTC (permalink / raw)
  To: Mike Christie, Martin K . Petersen, linux-scsi, target-devel
  Cc: kernel-janitors, linux-kernel

On 20/03/2019 17:14, Mike Christie wrote:
> On 03/20/2019 11:37 AM, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> 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

> 
> 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.
> 
> 
>> ssize_t rather than a size_t.
>>
>> Fixes: 0322913cab79 ("scsi: target: Add device product id and revision configfs attributes")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>>  drivers/target/target_core_configfs.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
>> index 8f3faef235b5..3fe79875b3ac 100644
>> --- a/drivers/target/target_core_configfs.c
>> +++ b/drivers/target/target_core_configfs.c
>> @@ -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)) {
>>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH][next] scsi: target: fix unsigned comparision with less than zero
  2019-03-20 17:14 ` Mike Christie
  2019-03-20 17:14   ` Colin Ian King
@ 2019-03-20 17:15   ` Mike Christie
  1 sibling, 0 replies; 5+ messages in thread
From: Mike Christie @ 2019-03-20 17:15 UTC (permalink / raw)
  To: Colin King, Martin K . Petersen, linux-scsi, target-devel
  Cc: kernel-janitors, linux-kernel

On 03/20/2019 12:14 PM, Mike Christie wrote:
> On 03/20/2019 11:37 AM, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> 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.
> 
> 

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

Patch looks ok to me.

Reviewed-by: Mike Christie <mchristi@redhat.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH][next] scsi: target: fix unsigned comparision with less than zero
  2019-03-20 16:37 [PATCH][next] scsi: target: fix unsigned comparision with less than zero Colin King
  2019-03-20 17:14 ` Mike Christie
@ 2019-03-21  0:33 ` Martin K. Petersen
  1 sibling, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2019-03-21  0:33 UTC (permalink / raw)
  To: Colin King
  Cc: Martin K . Petersen, linux-scsi, target-devel, kernel-janitors,
	linux-kernel


Colin,

> 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!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-21  0:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-20 16:37 [PATCH][next] scsi: target: fix unsigned comparision with less than zero Colin King
2019-03-20 17:14 ` Mike Christie
2019-03-20 17:14   ` Colin Ian King
2019-03-20 17:15   ` Mike Christie
2019-03-21  0:33 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).