Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp813791ima; Wed, 24 Oct 2018 09:34:02 -0700 (PDT) X-Google-Smtp-Source: AJdET5fXj/iDe1iAk6TiJtUEBEMwysCcMdF25cN90giNGnxtfaMpJgD9KMJppWOJp6xItOpWo55B X-Received: by 2002:a17:902:9696:: with SMTP id n22-v6mr3202968plp.282.1540398842485; Wed, 24 Oct 2018 09:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540398842; cv=none; d=google.com; s=arc-20160816; b=L6dFB2F9rOpqKxcXZ5pjkHKeyJBNgfajxt9wCIUsqETZKm4uGOMBO313d3WeE8oYB/ 2QbdWauyyelLFh8UbFPcRmZisIlrWG1GB/rGgYMQglHwuC7QrNborn/UNaAQPKzcFImE n4vbCfhwluHSsSvAsifdkmW/wRp26nWogv5q6Gtn93czx5wGxzDaUkXWZK7EHcnspxCa zOLDxjYvM5+1KSAmzGBKQCdBbjHuYBBY6W9p5bHRqQ49oEDnwkSmZkp5gClJA9Jejf1C 6W2iTJztYpfRAcxNC40fUhYH+wTpkx2PWpszjBQfRxcZx31q2lSn3wIGkyerY5Yp451D 2+tg== 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; bh=GGjem0tF4TW4bzzj5fpL/xem0H0OqU4vMWAK6H70OTA=; b=FSlhB87M3rFL09QVq+wAsSxdUK5I35KT6CZXP6KMs1m8lq+VGa4TXamLAmtgX5q6UF baC6KS1wY4PEgmA9g5UR9woXBwn082BoGyV0mG2I6Mun259CNIQu7emqdAQ044Ewhis/ ifsFHMoDqK6yiRf8QH7mlTJhc6o5Wg70FuK+rcpCxmJm6TSrI49v8zIiw+b85iEaWRRy NK0i5c9XTMG3+VIXVBSrkr2zAvI1KAFWrTQQFcuFWXB65OlwgIeTfxYf48Jjbkq3GvOW jIDwkCSh02EPShxwtr36RGI6f7l0DfQuTZxjsWxjrH14TwVCoulzsBlGuDgYeUAFcQrC TsEA== 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 i33-v6si5065149pld.433.2018.10.24.09.33.46; Wed, 24 Oct 2018 09:34:02 -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 S1726819AbeJYBBx (ORCPT + 99 others); Wed, 24 Oct 2018 21:01:53 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:35490 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726433AbeJYBBx (ORCPT ); Wed, 24 Oct 2018 21:01:53 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id w9OGWUTi025385; Wed, 24 Oct 2018 18:32:30 +0200 Date: Wed, 24 Oct 2018 18:32:30 +0200 From: Willy Tarreau To: Joe Perches 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 Subject: Re: [PATCH] Change judgment len position Message-ID: <20181024163230.GA25382@1wt.eu> References: <20181024154729.5312-1-wanghaifine@gmail.com> <20181024155739.GA25314@1wt.eu> <60f08664db5751949ddfb34666bfda77f99682f1.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <60f08664db5751949ddfb34666bfda77f99682f1.camel@perches.com> User-Agent: Mutt/1.6.1 (2016-04-27) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Willy