Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3755037imm; Mon, 17 Sep 2018 02:39:30 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaTCKydCaUf2IKwmWgkSilJqFeXuVOId6ccKJe2cjdlg7xD+jul7QpkZYIY6stNu5/p7tDK X-Received: by 2002:a17:902:2e83:: with SMTP id r3-v6mr24004117plb.80.1537177170086; Mon, 17 Sep 2018 02:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537177170; cv=none; d=google.com; s=arc-20160816; b=J0YzL1I/LD3LUIhuQ6ugDk4jkCx+reec3c/RuWClSuOOyStr4soi+o6BU+jfaq7Hpw zZksXDwFcP/p867j1rv45cPFEwAWi5rdVPtqApoTIXfk3oWylMg/1ujzoeP4FEgvd50A nKWhLg7YLRvUiAaAv28SeQvb7bqGKwkW5easbRonDTRLx6yIy1sfFo5SJP+5dtTA8njK xp5S4MqqTW1A1AoKFaerPUOFYh4zf6ABZEKQv9bHnrq8276CP4CQ7dcNnbKBC0OHRDhj WF4560bmGVv9vL5eiQDBXIgr5PA6xGGmD7H3UYsbPEej8JCfFZ96HbUQNHUtkWlFM/i6 9xLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=Qy9lYXUlall1sm/J4m+z78ya8uZpfkrPuauhcyqMXaI=; b=jt6Jss8U7OUpFMNXZuZ0nEMtQNS5m5l6AYM9k0MhUjOaHwcjukFUKkeyQ1wf+fQ/FS TP1LNpvI/07ruR8dAkQRjgE893AJscqPMGqzMSUorXn1TntnI74CWLtqMa84EPb9op7v YIP/JfN6E+qJjPDYwD4a+lEFQXSaHNENZ/2iXRx4JRIfotDKeeZyM31300h+YcVbQZx8 GTNst5KQ/W7G8wBK8xp5Tx2vGuX6tFUKD1gDoH8iOAKfQv29kjkp/GITyrTEGWnrEogP Xzv4vkY8JD2unVJP1EWCbvzI7o4fGjTQjFueA5cN/XkPmgPbuZ6j5fZ3vw5UxNdu6DCk zEkw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y14-v6si14701155plp.371.2018.09.17.02.39.13; Mon, 17 Sep 2018 02:39:30 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727473AbeIQPFZ (ORCPT + 99 others); Mon, 17 Sep 2018 11:05:25 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:12589 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726753AbeIQPFZ (ORCPT ); Mon, 17 Sep 2018 11:05:25 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id DC27AB63C0407; Mon, 17 Sep 2018 17:38:45 +0800 (CST) Received: from [127.0.0.1] (10.177.31.96) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.399.0; Mon, 17 Sep 2018 17:38:42 +0800 Subject: Re: [PATCH net-next] net/smc: cast sizeof to int for comparison To: Ursula Braun References: <20180915100036.20100-1-yuehaibing@huawei.com> <554a145a-d59d-9033-1702-4987a9c4bc94@linux.ibm.com> CC: , , , From: YueHaibing Message-ID: Date: Mon, 17 Sep 2018 17:38:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <554a145a-d59d-9033-1702-4987a9c4bc94@linux.ibm.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.31.96] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > > Regards, Ursula > > >