linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net/smc: cast sizeof to int for comparison
@ 2018-09-15 10:00 YueHaibing
  2018-09-15 11:35 ` Andreas Schwab
  2018-09-17  8:49 ` Ursula Braun
  0 siblings, 2 replies; 7+ messages in thread
From: YueHaibing @ 2018-09-15 10:00 UTC (permalink / raw)
  To: davem, ubraun; +Cc: linux-kernel, netdev, linux-s390, YueHaibing

Comparing an int to a size, which is unsigned, causes the int to become
unsigned, giving the wrong result. kernel_sendmsg can return a negative
error code.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 net/smc/smc_clc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
index 83aba9a..fd0f5ce 100644
--- a/net/smc/smc_clc.c
+++ b/net/smc/smc_clc.c
@@ -446,7 +446,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
 	vec[i++].iov_len = sizeof(trl);
 	/* due to the few bytes needed for clc-handshake this cannot block */
 	len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
-	if (len < sizeof(pclc)) {
+	if (len < (int)sizeof(pclc)) {
 		if (len >= 0) {
 			reason_code = -ENETUNREACH;
 			smc->sk.sk_err = -reason_code;
-- 
1.8.3.1



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

* Re: [PATCH net-next] net/smc: cast sizeof to int for comparison
  2018-09-15 10:00 [PATCH net-next] net/smc: cast sizeof to int for comparison YueHaibing
@ 2018-09-15 11:35 ` Andreas Schwab
  2018-09-17  3:57   ` YueHaibing
  2018-09-17  8:49 ` Ursula Braun
  1 sibling, 1 reply; 7+ messages in thread
From: Andreas Schwab @ 2018-09-15 11:35 UTC (permalink / raw)
  To: YueHaibing; +Cc: davem, ubraun, linux-kernel, netdev, linux-s390

On Sep 15 2018, YueHaibing <yuehaibing@huawei.com> wrote:

> Comparing an int to a size, which is unsigned, causes the int to become
> unsigned, giving the wrong result. kernel_sendmsg can return a negative
> error code.
>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  net/smc/smc_clc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
> index 83aba9a..fd0f5ce 100644
> --- a/net/smc/smc_clc.c
> +++ b/net/smc/smc_clc.c
> @@ -446,7 +446,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
>  	vec[i++].iov_len = sizeof(trl);
>  	/* due to the few bytes needed for clc-handshake this cannot block */
>  	len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
> -	if (len < sizeof(pclc)) {
> +	if (len < (int)sizeof(pclc)) {
>  		if (len >= 0) {
>  			reason_code = -ENETUNREACH;
>  			smc->sk.sk_err = -reason_code;

It would perhaps be better to handle len < 0 first.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

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

* Re: [PATCH net-next] net/smc: cast sizeof to int for comparison
  2018-09-15 11:35 ` Andreas Schwab
@ 2018-09-17  3:57   ` YueHaibing
  2018-09-17  8:42     ` Andreas Schwab
  0 siblings, 1 reply; 7+ messages in thread
From: YueHaibing @ 2018-09-17  3:57 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: davem, ubraun, linux-kernel, netdev, linux-s390

On 2018/9/15 19:35, Andreas Schwab wrote:
> On Sep 15 2018, YueHaibing <yuehaibing@huawei.com> wrote:
> 
>> Comparing an int to a size, which is unsigned, causes the int to become
>> unsigned, giving the wrong result. kernel_sendmsg can return a negative
>> error code.
>>
>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>> ---
>>  net/smc/smc_clc.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
>> index 83aba9a..fd0f5ce 100644
>> --- a/net/smc/smc_clc.c
>> +++ b/net/smc/smc_clc.c
>> @@ -446,7 +446,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
>>  	vec[i++].iov_len = sizeof(trl);
>>  	/* due to the few bytes needed for clc-handshake this cannot block */
>>  	len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
>> -	if (len < sizeof(pclc)) {
>> +	if (len < (int)sizeof(pclc)) {
>>  		if (len >= 0) {
>>  			reason_code = -ENETUNREACH;
>>  			smc->sk.sk_err = -reason_code;
> 
> It would perhaps be better to handle len < 0 first.

That need refactor the err hangding, is worth doing it?

> 
> Andreas.
> 


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

* Re: [PATCH net-next] net/smc: cast sizeof to int for comparison
  2018-09-17  3:57   ` YueHaibing
@ 2018-09-17  8:42     ` Andreas Schwab
  0 siblings, 0 replies; 7+ messages in thread
From: Andreas Schwab @ 2018-09-17  8:42 UTC (permalink / raw)
  To: YueHaibing; +Cc: davem, ubraun, linux-kernel, netdev, linux-s390

On Sep 17 2018, YueHaibing <yuehaibing@huawei.com> wrote:

> On 2018/9/15 19:35, Andreas Schwab wrote:
>> On Sep 15 2018, YueHaibing <yuehaibing@huawei.com> wrote:
>> 
>>> Comparing an int to a size, which is unsigned, causes the int to become
>>> unsigned, giving the wrong result. kernel_sendmsg can return a negative
>>> error code.
>>>
>>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>>> ---
>>>  net/smc/smc_clc.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
>>> index 83aba9a..fd0f5ce 100644
>>> --- a/net/smc/smc_clc.c
>>> +++ b/net/smc/smc_clc.c
>>> @@ -446,7 +446,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
>>>  	vec[i++].iov_len = sizeof(trl);
>>>  	/* due to the few bytes needed for clc-handshake this cannot block */
>>>  	len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
>>> -	if (len < sizeof(pclc)) {
>>> +	if (len < (int)sizeof(pclc)) {
>>>  		if (len >= 0) {
>>>  			reason_code = -ENETUNREACH;
>>>  			smc->sk.sk_err = -reason_code;
>> 
>> It would perhaps be better to handle len < 0 first.
>
> That need refactor the err hangding, is worth doing it?

Just a few lines moving around, IFAICS.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

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

* Re: [PATCH net-next] net/smc: cast sizeof to int for comparison
  2018-09-15 10:00 [PATCH net-next] net/smc: cast sizeof to int for comparison YueHaibing
  2018-09-15 11:35 ` Andreas Schwab
@ 2018-09-17  8:49 ` Ursula Braun
  2018-09-17  9:38   ` YueHaibing
  1 sibling, 1 reply; 7+ messages in thread
From: Ursula Braun @ 2018-09-17  8:49 UTC (permalink / raw)
  To: YueHaibing; +Cc: davem, linux-kernel, netdev, linux-s390



On 09/15/2018 12:00 PM, YueHaibing wrote:
> Comparing an int to a size, which is unsigned, causes the int to become
> unsigned, giving the wrong result. kernel_sendmsg can return a negative
> error code.
> 

Thanks for reporting this issue!

> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  net/smc/smc_clc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
> index 83aba9a..fd0f5ce 100644
> --- a/net/smc/smc_clc.c
> +++ b/net/smc/smc_clc.c
> @@ -446,7 +446,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
>  	vec[i++].iov_len = sizeof(trl);
>  	/* due to the few bytes needed for clc-handshake this cannot block */
>  	len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
> -	if (len < sizeof(pclc)) {
> +	if (len < (int)sizeof(pclc)) {
>  		if (len >= 0) {
>  			reason_code = -ENETUNREACH;
>  			smc->sk.sk_err = -reason_code;
> 

Your fix helps, but I would like to follow the hint of Andreas Schwab, and split
the return value check like this:

---
 net/smc/smc_clc.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

--- a/net/smc/smc_clc.c
+++ b/net/smc/smc_clc.c
@@ -446,14 +446,12 @@ int smc_clc_send_proposal(struct smc_soc
 	vec[i++].iov_len = sizeof(trl);
 	/* due to the few bytes needed for clc-handshake this cannot block */
 	len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
-	if (len < sizeof(pclc)) {
-		if (len >= 0) {
-			reason_code = -ENETUNREACH;
-			smc->sk.sk_err = -reason_code;
-		} else {
-			smc->sk.sk_err = smc->clcsock->sk->sk_err;
-			reason_code = -smc->sk.sk_err;
-		}
+	if (len < 0) {
+		smc->sk.sk_err = smc->clcsock->sk->sk_err;
+		reason_code = -smc->sk.sk_err;
+	} else if (len < (int)sizeof(pclc)) {
+		reason_code = -ENETUNREACH;
+		smc->sk.sk_err = -reason_code;
 	}
 
 	return reason_code;

Agreed?

Regards, Ursula


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

* Re: [PATCH net-next] net/smc: cast sizeof to int for comparison
  2018-09-17  8:49 ` Ursula Braun
@ 2018-09-17  9:38   ` YueHaibing
  2018-09-17 11:49     ` Ursula Braun
  0 siblings, 1 reply; 7+ messages in thread
From: YueHaibing @ 2018-09-17  9:38 UTC (permalink / raw)
  To: Ursula Braun; +Cc: davem, linux-kernel, netdev, linux-s390


On 2018/9/17 16:49, Ursula Braun wrote:
> 
> 
> On 09/15/2018 12:00 PM, YueHaibing wrote:
>> Comparing an int to a size, which is unsigned, causes the int to become
>> unsigned, giving the wrong result. kernel_sendmsg can return a negative
>> error code.
>>
> 
> Thanks for reporting this issue!
> 
>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>> ---
>>  net/smc/smc_clc.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
>> index 83aba9a..fd0f5ce 100644
>> --- a/net/smc/smc_clc.c
>> +++ b/net/smc/smc_clc.c
>> @@ -446,7 +446,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
>>  	vec[i++].iov_len = sizeof(trl);
>>  	/* due to the few bytes needed for clc-handshake this cannot block */
>>  	len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
>> -	if (len < sizeof(pclc)) {
>> +	if (len < (int)sizeof(pclc)) {
>>  		if (len >= 0) {
>>  			reason_code = -ENETUNREACH;
>>  			smc->sk.sk_err = -reason_code;
>>
> 
> Your fix helps, but I would like to follow the hint of Andreas Schwab, and split
> the return value check like this:
> 
> ---
>  net/smc/smc_clc.c |   14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> --- a/net/smc/smc_clc.c
> +++ b/net/smc/smc_clc.c
> @@ -446,14 +446,12 @@ int smc_clc_send_proposal(struct smc_soc
>  	vec[i++].iov_len = sizeof(trl);
>  	/* due to the few bytes needed for clc-handshake this cannot block */
>  	len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
> -	if (len < sizeof(pclc)) {
> -		if (len >= 0) {
> -			reason_code = -ENETUNREACH;
> -			smc->sk.sk_err = -reason_code;
> -		} else {
> -			smc->sk.sk_err = smc->clcsock->sk->sk_err;
> -			reason_code = -smc->sk.sk_err;
> -		}
> +	if (len < 0) {
> +		smc->sk.sk_err = smc->clcsock->sk->sk_err;
> +		reason_code = -smc->sk.sk_err;
> +	} else if (len < (int)sizeof(pclc)) {
> +		reason_code = -ENETUNREACH;
> +		smc->sk.sk_err = -reason_code;
>  	}
>  
>  	return reason_code;
> 
> Agreed?

Yes, Need a new patch from me?

> 
> Regards, Ursula
> 
> 
> 


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

* Re: [PATCH net-next] net/smc: cast sizeof to int for comparison
  2018-09-17  9:38   ` YueHaibing
@ 2018-09-17 11:49     ` Ursula Braun
  0 siblings, 0 replies; 7+ messages in thread
From: Ursula Braun @ 2018-09-17 11:49 UTC (permalink / raw)
  To: YueHaibing; +Cc: davem, linux-kernel, netdev, linux-s390



On 09/17/2018 11:38 AM, YueHaibing wrote:
> 
> On 2018/9/17 16:49, Ursula Braun wrote:
>>
>>
>> On 09/15/2018 12:00 PM, YueHaibing wrote:
>>> Comparing an int to a size, which is unsigned, causes the int to become
>>> unsigned, giving the wrong result. kernel_sendmsg can return a negative
>>> error code.
>>>
>>
>> Thanks for reporting this issue!
>>
>>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>>> ---
>>>  net/smc/smc_clc.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
>>> index 83aba9a..fd0f5ce 100644
>>> --- a/net/smc/smc_clc.c
>>> +++ b/net/smc/smc_clc.c
>>> @@ -446,7 +446,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
>>>  	vec[i++].iov_len = sizeof(trl);
>>>  	/* due to the few bytes needed for clc-handshake this cannot block */
>>>  	len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
>>> -	if (len < sizeof(pclc)) {
>>> +	if (len < (int)sizeof(pclc)) {
>>>  		if (len >= 0) {
>>>  			reason_code = -ENETUNREACH;
>>>  			smc->sk.sk_err = -reason_code;
>>>
>>
>> Your fix helps, but I would like to follow the hint of Andreas Schwab, and split
>> the return value check like this:
>>
>> ---
>>  net/smc/smc_clc.c |   14 ++++++--------
>>  1 file changed, 6 insertions(+), 8 deletions(-)
>>
>> --- a/net/smc/smc_clc.c
>> +++ b/net/smc/smc_clc.c
>> @@ -446,14 +446,12 @@ int smc_clc_send_proposal(struct smc_soc
>>  	vec[i++].iov_len = sizeof(trl);
>>  	/* due to the few bytes needed for clc-handshake this cannot block */
>>  	len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
>> -	if (len < sizeof(pclc)) {
>> -		if (len >= 0) {
>> -			reason_code = -ENETUNREACH;
>> -			smc->sk.sk_err = -reason_code;
>> -		} else {
>> -			smc->sk.sk_err = smc->clcsock->sk->sk_err;
>> -			reason_code = -smc->sk.sk_err;
>> -		}
>> +	if (len < 0) {
>> +		smc->sk.sk_err = smc->clcsock->sk->sk_err;
>> +		reason_code = -smc->sk.sk_err;
>> +	} else if (len < (int)sizeof(pclc)) {
>> +		reason_code = -ENETUNREACH;
>> +		smc->sk.sk_err = -reason_code;
>>  	}
>>  
>>  	return reason_code;
>>
>> Agreed?
> 
> Yes, Need a new patch from me?
> 

Not necessary, I will make sure this patch version is added to the smc code.

>>
>> Regards, Ursula
>>
>>
>>
> 


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

end of thread, other threads:[~2018-09-17 11:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-15 10:00 [PATCH net-next] net/smc: cast sizeof to int for comparison YueHaibing
2018-09-15 11:35 ` Andreas Schwab
2018-09-17  3:57   ` YueHaibing
2018-09-17  8:42     ` Andreas Schwab
2018-09-17  8:49 ` Ursula Braun
2018-09-17  9:38   ` YueHaibing
2018-09-17 11:49     ` Ursula Braun

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).