From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ursula Braun Subject: Re: [PATCH net-next] net/smc: cast sizeof to int for comparison Date: Mon, 17 Sep 2018 13:49:10 +0200 Message-ID: References: <20180915100036.20100-1-yuehaibing@huawei.com> <554a145a-d59d-9033-1702-4987a9c4bc94@linux.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: davem@davemloft.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org To: YueHaibing Return-path: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:52714 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727660AbeIQRQT (ORCPT ); Mon, 17 Sep 2018 13:16:19 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8HBnHqC120364 for ; Mon, 17 Sep 2018 07:49:20 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2mja4ybxv9-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 17 Sep 2018 07:49:20 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 17 Sep 2018 12:49:14 +0100 In-Reply-To: Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: 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 >>> --- >>> 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 >> >> >> >