Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp835435ima; Wed, 24 Oct 2018 09:55:09 -0700 (PDT) X-Google-Smtp-Source: AJdET5c6es7N/TLGtN3CFFPgg18wrlmyCe4pSlGPG0w98VF4HWs3hGn8G/onA0KgHYYXO/GE4hHd X-Received: by 2002:a63:d905:: with SMTP id r5-v6mr3278917pgg.314.1540400109906; Wed, 24 Oct 2018 09:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540400109; cv=none; d=google.com; s=arc-20160816; b=pzN95YUzLt/GIjxeNrpmwC1c1mTG90PAQIoUpMokuX4Q0BqPbhpuzhasQp8J6qThyv eQw3LxsuS4XBmQLAuO4GCXBEv2eqWbLVBpjJSvg0z+AjG2iACZeMUMSlc0QDSSs7QsU/ 9WCKM3THqWREYNGg+3jUkIZsAZtpO44PXsEQoWzcCIPAn5Yobp6WyzD+07+o/0Zvv90O pZWF/BHrAtANU+9YdFDNie1F4t7urW+GT+SPC8syrM4QG7uAyBXZXwqqbLtyjlBx5NsD oZZpJsIgdPwMDIZmsNknGjQjSDTV4Ugie6XqNPT9Byt8N7dc9RF5hjMSa8bL8MbGyhgi lUKQ== 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:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=tJzSLcWZvaOIGJ3mXizRDjtaQZ+4YMGJZocertM8Q3A=; b=pzc+kou+SIt8KPvXFdiOtjsQJcnzCexrZ9iuSbmzM6+VZVik+7Do1l94ezHbdVvwns Fxm1vX+NOpS00kDTLmyNdGb21arpBAhYd1yu/ex9mWu4Tga/LnHHD2QNMlrQ8R6q7zU5 3YyLac1E58GcyspwUljt8JNgnaQa2QxYuuUdjox+QXJpKnuteF/cR3+BemlPKIDTQF8K gWloUh4yMeGJeJ1yZ6oJw1UYJiTqCNr/+W/y6DADYBoAR1WguiulwiDo6gJ8D+OiGELu 8PXYdABpKRVxmtLt2TmqOkuzouOlNGzjpy7v/ivjlWz1dyOscHu4fiVQJ6G0apYahI9K 5sHQ== 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 b4-v6si5236962pfg.90.2018.10.24.09.54.54; Wed, 24 Oct 2018 09:55:09 -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 S1727607AbeJYBXG (ORCPT + 99 others); Wed, 24 Oct 2018 21:23:06 -0400 Received: from smtprelay0188.hostedemail.com ([216.40.44.188]:33825 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727535AbeJYBXG (ORCPT ); Wed, 24 Oct 2018 21:23:06 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay03.hostedemail.com (Postfix) with ESMTP id 4E7758368EF0; Wed, 24 Oct 2018 16:54:16 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::,RULES_HIT:41:355:379:599:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:5007:7903:9707:10004:10400:10848:11232:11658:11914:12740:12760:12895:13019:13069:13311:13357:13439:14096:14097:14659:14721:21080:21627:30012:30034:30054:30070:30090:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:31,LUA_SUMMARY:none X-HE-Tag: ducks88_7f5d1b57e64e X-Filterd-Recvd-Size: 2956 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf04.hostedemail.com (Postfix) with ESMTPA; Wed, 24 Oct 2018 16:54:14 +0000 (UTC) Message-ID: Subject: Re: [PATCH] Change judgment len position From: Joe Perches To: Willy Tarreau Cc: Wang Hai , edumazet@google.com, davem@davemloft.net, kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 24 Oct 2018 09:54:13 -0700 In-Reply-To: <20181024163230.GA25382@1wt.eu> References: <20181024154729.5312-1-wanghaifine@gmail.com> <20181024155739.GA25314@1wt.eu> <60f08664db5751949ddfb34666bfda77f99682f1.camel@perches.com> <20181024163230.GA25382@1wt.eu> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.30.1-1build1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-10-24 at 18:32 +0200, Willy Tarreau wrote: > On Wed, Oct 24, 2018 at 09:23:19AM -0700, Joe Perches wrote: > > On Wed, 2018-10-24 at 17:57 +0200, Willy Tarreau wrote: > > > On Wed, Oct 24, 2018 at 11:47:29PM +0800, Wang Hai wrote: > > > > To determine whether len is less than zero, it should be put before > > > > the function min_t, because the return value of min_t is not likely > > > > to be less than zero. > > > > > > Huh? First, the <0 test is made on "len", not "min_t", so it still > > > is signed. Second, you're in fact completely removing the test here, > > > look : > > > > > > > struct net *net = sock_net(sk); > > > > int val, len; > > > > > > > > + len = min_t(unsigned int, len, sizeof(int)); > > > > + > > > > > > len is used uninitialized here, so the result is undefined. > > > > > > > if (get_user(len, optlen)) > > > > return -EFAULT; > > > > > > Then it gets overridden by get_user() > > > > > > > - len = min_t(unsigned int, len, sizeof(int)); > > > > - > > > > > > Then its positive values are not bounded anymore since you moved the test. > > > > Not quite. > > > > Problem here is negative values are tested as > > large positive values and limited to 4 > > > > ie: > > ien len = -1, > > len = min_t(unsigned int, len, sizeof(int)); > > > > len is now 4 > > > > > > if (len < 0) > > > > return -EINVAL; > > > > So this test len < 0 could be moved up above min_t > > It could indeed, or we could also have min_t() done on an int instead > of an unsigned int and this would avoid the need to shuffle the code > around and open a huge hole like this one. I think if the point is to test for negative numbers, it's clearer to do that before using min_t.and it's probably clearer not to use min_t at all. if (get_user(len, optlen)) return -EFAULT; if (len < 0) return -EINVAL; if (len > sizeof(int)) len = sizeof(int);