Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1122276imm; Tue, 3 Jul 2018 06:01:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfYGxbdDLhVjro0w4PBDxFOF512jmdP6N7K7XddXKGx+kYnwWyamlJtBbdejWoTRm4zgF7/ X-Received: by 2002:aa7:87d0:: with SMTP id i16-v6mr25747538pfo.82.1530622906422; Tue, 03 Jul 2018 06:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530622906; cv=none; d=google.com; s=arc-20160816; b=Q3slvo9bauriMOw0A/6OiQJEXHZL8lhbW9T0g4LeQ+NGun6Peda9Lg+5NyuwX+K2YP LBs0MiUh3LMVFlma117ZC3R0Wt5pnQqn/tkZObdNjk7mM928AzptpXnxi4PD13vicp3U +nq2I45CLnsAhEzXdKEk6UlxI8Ui5Wg0BiBEcc/98CZlWygLzfUjhID1lM5rVYJk90US 5VgJBDRDnmFucaJDwOog5FFf1H3PqiLLUHtcCbj3gEwtT+dUD9sqBi+ns1B9itgBmAHK jld1zE6kxpEL1BhPt5FrkkrtjZ2X4JyB1r6oHZGBpLes0fxyzRuB+qqSj3obrz3fV4L4 HWbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=NaUA/FnOoQaZqv9f2fXWUCRsyDmSiB8esHiCe4r87oM=; b=xBV6RG1vUPjAo0Af37YrMmhWViGXaRwmlfDcT6Iegt9UcEWPaxaUJYt+zvk9rUFk1S GIszQwtM03hKZW5tYxcG/1SZy/55jgPcJKm29YxFMR1+bC+3+mbjHYe5yDJ3WTBClFy4 8FqsZacUY9u81tUskLQmtiDdyWDhSJR+omMkItWtT3iJi8laHU0kARdh5acv3OcH/w5/ rVvw+bbkXpQsYTkBZlwberIs+ImZkKnjRft7j0lkJEzjHypHt3bF1HFVBDRdHC6BAZk6 wiWLF04SuAGXp4iAc9jK+nheExqr2kovVWZUlJ2y1U4RKW2jSjbpC0BCUP8ptRe0uaG/ vZ0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=gR48ANz0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l30-v6si1053086plg.420.2018.07.03.06.01.29; Tue, 03 Jul 2018 06:01:46 -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; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=gR48ANz0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753362AbeGCNAp (ORCPT + 99 others); Tue, 3 Jul 2018 09:00:45 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59296 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752494AbeGCNAl (ORCPT ); Tue, 3 Jul 2018 09:00:41 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w63CwVO7006043; Tue, 3 Jul 2018 13:00:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=NaUA/FnOoQaZqv9f2fXWUCRsyDmSiB8esHiCe4r87oM=; b=gR48ANz0u5oSplptI8xWjaLJN9L6YVlAr/zlh3EdW/GtHMdYWIiAMOPzBWFKchADE0AS 9z601SGuyl7whqAKzdEIKase9EYyrpMO48EEdxBAkILPpfXHKByW8+F71ZsPux1gVE4V gtG8Mqoh9dGOAQS86/Zk1mmZD3IH+gS/XxErwlCSmM8y3APJyqMiKiRmHTW8L8bmgbRk Mf3Lg4MqxjX2up2KrJBu/KccnmIOodiZiN86P8jFsRDSQDHT/+R1D0nK5dZMpNLDv60l 9NlDktzo2mR/ETmEwu+a3ys8KP5QMPOhgWRRckrejxwfbHN09PACcLCsn0cvso6atw9e Yw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2jx1tp0djv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Jul 2018 13:00:34 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w63D0XdT025332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Jul 2018 13:00:34 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w63D0WEt012416; Tue, 3 Jul 2018 13:00:33 GMT Received: from mwanda (/197.157.0.57) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Jul 2018 06:00:32 -0700 Date: Tue, 3 Jul 2018 16:00:24 +0300 From: Dan Carpenter To: Julia Lawall Cc: Joe Perches , linux-usb@vger.kernel.org, Chengguang Xu , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-media@vger.kernel.org Subject: Re: [PATCH 0/3] cast sizeof to int for comparison Message-ID: <20180702091834.etunideivmb6p2sf@mwanda> References: <1530466325-1678-1-git-send-email-Julia.Lawall@lip6.fr> <653914f26dc8433a3f682b5e7eb850ab94bd431d.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8942 signatures=668704 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=535 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807030149 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 01, 2018 at 08:51:55PM +0200, Julia Lawall wrote: > > > On Sun, 1 Jul 2018, Joe Perches wrote: > > > On Sun, 2018-07-01 at 19:32 +0200, Julia Lawall wrote: > > > Comparing an int to a size, which is unsigned, causes the int to become > > > unsigned, giving the wrong result. > > > > > > The semantic match that finds this problem is as follows: > > > (http://coccinelle.lip6.fr/) > > > > Great, thanks. > > > > But what about the ones in net/smc like: > > > > > net/smc/smc_clc.c: > > > > > > len = kernel_sendmsg(smc->clcsock, &msg, &vec, 1, > > > sizeof(struct smc_clc_msg_decline)); > > > if (len < sizeof(struct smc_clc_msg_decline)) > > > > Are those detected by the semantic match and ignored? > > I wasn't sure how to justify that kernel_sendmsg returns a negative value. > If it is the case, I can send the patch. I only found this in one file, > but there were multiple occurrences. > In theory, Smatch is supposed to know return values but kernel_sendmsg() is too complicated for Smatch. It's a tricky thing... That particular check is correct and deliberate, but there is another check which is wrong. net/smc/smc_clc.c 369 len = kernel_sendmsg(smc->clcsock, &msg, &vec, 1, 370 sizeof(struct smc_clc_msg_decline)); 371 if (len < sizeof(struct smc_clc_msg_decline)) 372 smc->sk.sk_err = EPROTO; 373 if (len < 0) 374 smc->sk.sk_err = -len; If it's invalid we set an error code, if it's already an error we preserve the error code. 375 return sock_error(&smc->sk); [ snip ] 442 /* due to the few bytes needed for clc-handshake this cannot block */ 443 len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen); 444 if (len < sizeof(pclc)) { 445 if (len >= 0) { ^^^^^^^^ This is always true. 446 reason_code = -ENETUNREACH; 447 smc->sk.sk_err = -reason_code; 448 } else { 449 smc->sk.sk_err = smc->clcsock->sk->sk_err; 450 reason_code = -smc->sk.sk_err; 451 } 452 } The other two checks are not type promoted so they also work as intended. This is an interesting sort of bug I've written a Smatch script inspired by your work here. One for the type promotion and one for the impossible condition. I'll let you know how it goes. regards, dan carpenter