Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3715447imm; Mon, 17 Sep 2018 01:50:36 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY0W6aHGCi34rorPNr4D7utCmvi61t+Mt6eNPTM/bMLVLNYU3VDe5ipUVIx+Fwde1NiICeX X-Received: by 2002:a17:902:7606:: with SMTP id k6-v6mr23480368pll.300.1537174236229; Mon, 17 Sep 2018 01:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537174236; cv=none; d=google.com; s=arc-20160816; b=vSpe4x4E60wquNeHZ3eN1yYi9p2+uu4V5EI+Zf43WfOKIZ+55IgC7VUI7w4dMIak9K 1geZ2+hCoSPQZ9bsYXkxJNzy6eXd8YZl1FesfaVtPgCEKf8lMHe0PMOnsqJLSXGvkXQL rEow+QDRct22GrY6qhiGdXIewODwKMYsOEHeLMCDry0P8VVTgfk2pwMlHoMwSg21YKBv o26M5KrSGacm8ziiQEWD81DxSswsW3Uxfd1IVNXFmeQgIHue3CXnNyk+F3WI/nNuQ5O5 r+zeho6h7uIuLs2/7ptmbkaWQUYfGvZrNrYIgor9ACUEnXv7DZCzxBjbo2XlAZNmoxCG zZIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:autocrypt :openpgp:from:references:cc:to:subject; bh=+CcZdi3JN0PBiHB2vn1XLHMPHhZH95XhbYs74UGNdvw=; b=FgTZsBPafO7mYdORJxWTOrveQ8E7HbSBfSOH7ONGP0To6WaMTU7C4ci/CQFiDFnRK1 d32sVjOYxtNnVXC3/jmXes4m41Hz6+UQe1x4654yuS0P3PYeRpImUR6GVN9O64CvDae1 QcGCOW4zXwuM0Lly+Nm1HCLs6Cb55Vu+F3faYfc5Iy/MACs4CgPPDdktmPQIb+m1qSaF cLWqe8hwotU+SCsnLeXudySLW7vXLgIHoRoagGQizNkKS/xiRFnMvKX5ylKLdito5SlR VjCgwVz/PSf3S2e/O9Pye06DyR66hmbRaDsSmAfRNLqe6lVK1eJBbzlKKvKYxrh2UPmr dyUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k127-v6si15038971pga.407.2018.09.17.01.50.21; Mon, 17 Sep 2018 01:50:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728095AbeIQOQR (ORCPT + 99 others); Mon, 17 Sep 2018 10:16:17 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56264 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727133AbeIQOQP (ORCPT ); Mon, 17 Sep 2018 10:16:15 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8H8jSt1052972 for ; Mon, 17 Sep 2018 04:50:53 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2mj7h9c0xy-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 17 Sep 2018 04:50:52 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 17 Sep 2018 09:49:46 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 17 Sep 2018 09:49:44 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w8H8nhSa56885420 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 17 Sep 2018 08:49:43 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7803EAE053; Mon, 17 Sep 2018 11:48:53 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 39474AE051; Mon, 17 Sep 2018 11:48:53 +0100 (BST) Received: from oc7163163645.ibm.com (unknown [9.145.57.131]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 17 Sep 2018 11:48:53 +0100 (BST) Subject: Re: [PATCH net-next] net/smc: cast sizeof to int for comparison To: YueHaibing Cc: davem@davemloft.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org References: <20180915100036.20100-1-yuehaibing@huawei.com> From: Ursula Braun Openpgp: preference=signencrypt Autocrypt: addr=ubraun@linux.ibm.com; prefer-encrypt=mutual; keydata= xsFNBFfk6uIBEADL7CmNIA6b1fxIX9RZltqQwLRemtjMyS1iSLenbaS0NMF2MLWgSsXyuy0A 0Bz5h+xlOt3SMj7jv8YZmFvSw1EXElJ+RMa/LeiN51zDLICNgc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ZQQYAQIADwUCV+Tq4gIbDAUJ EswDAAAKCRDMvao0xe1mRax3D/9Y4D2ANmumdJgvEAPLdEm3kLEL858HVx7GJolVrA9szN3a 82YVrJiaXgSVf3j6hSl1tI2qeSRTLNzgfFJUP7EI8WAMI0HV70Ilh3b6HEq7Mcts9uEFasz1 FidTJ0P4oM8mGVuWk47ozXoqIFtyqDfV9lKRaj8oC8gW9zDcNeQXdJzGbjR8WQa2J4BjN2ir G1uP1uWmXa9BhZYFQizhRkboZvkVHQNw6MxkQPhK1DNdQb+Z2uH8ELD41Kw3nxLnIHb3w7Ff mS8HBL+cu9sNWrW2TXZ1NTJucTg3+2zRHnpGzt11roz5xgEWxPRraZo1SsPOJ5eAxi2u/JNo AFLDNjI9K6N5ZJQfJSlbQ9+6nOzW1th8K2iPcPWuWbplQKeaRo6UQCafCJaj+CxC2iTzmzau Sw+xokHdgtDvSBFHvpJf0atERNKd5bWcJGtpxQxPQlx/XsWm4pB4XXlbk1WjOoFQeRQOyWCv eHRz7wGpY0fe9Q/UWkV40gLoP6d9BD9ZWbGvvT2NZtDCnaHTZ/trtADgxno5TVdr3VzIHah3 mLlLUk+oxMnqJvLTPXppz2/0AsGbEFcLs6fO7P1zr48yAGzNqXlZCiCUZ5DPqvAeOEFHiJUh HjXBWPHQYZeG0DNdRY/dunPOGKIYwUlSY/SaIGvstrmeIGlMBd3TqWZ8qIqvrg== Date: Mon, 17 Sep 2018 10:49:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180915100036.20100-1-yuehaibing@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 18091708-0020-0000-0000-000002C72960 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18091708-0021-0000-0000-000021149629 Message-Id: <554a145a-d59d-9033-1702-4987a9c4bc94@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-17_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809170093 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Regards, Ursula