[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <a11a5898-b422-4344-c043-de2b19d24023@linux.ibm.com>
Date: Mon, 17 Sep 2018 13:49:10 +0200
From: Ursula Braun <ubraun@...ux.ibm.com>
To: YueHaibing <yuehaibing@...wei.com>
Cc: davem@...emloft.net, linux-kernel@...r.kernel.org,
netdev@...r.kernel.org, linux-s390@...r.kernel.org
Subject: Re: [PATCH net-next] net/smc: cast sizeof to int for comparison
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@...wei.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
>>
>>
>>
>
Powered by blists - more mailing lists