Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp770315ima; Wed, 24 Oct 2018 08:58:50 -0700 (PDT) X-Google-Smtp-Source: AJdET5eIzUKC9vjskOeEDt5usWQiGU75Yomq/nn2HySTM14vpPsxAqDuuUfohHNOueJ8akEHUMPK X-Received: by 2002:a17:902:6ac7:: with SMTP id i7-v6mr3086521plt.268.1540396730867; Wed, 24 Oct 2018 08:58:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540396730; cv=none; d=google.com; s=arc-20160816; b=UZV2nXD9k2KlatZ8f4ssA4J2l8U53cUz8mbrOxTfGTzdnH0lqlVhKg5R/ceMowte8B ycPlDCPa1pWITlo9bs5ghgYDWESEGkTstygu70aiZGcCykSNqrjotDzEMGnw8dkV0p0B wg0oWjvpRiKJme78uo3fr0CWJHUCoTwqE0St3wALy6duwhaQlJEAOtoMtVWcqDi6cxVD m/pPlq/ImBrLZSO6xeo68WX6WBGhfrVjodIhVtEYovYSthzrvBwOVGIP3231jOFi/nHB UPHNdlg7w7C0YqDqwkyImt0/F7vDuqkLDmhqKRsEelYSCyRqm6nTNjoLX/D7pMlCXz/T 0abg== 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=+pfnxkbYFdHo0r57Vfcfvqwk2/qVCccGCujRfgnxoa8=; b=IgHh7UiTWuxjyNnMjywEe3jCWlPgW7yu7KTF9RL8Ort3oWnKYrZBZOmsFXABkOToX2 8zTacVxMvkh+XJAbmMEALQ7kFj1FBT+dixqi50pzomZHl7YW5VGHT6WhhDGoQGl2OEqX w+MmvxwBxVtI4WoSibw1PcICUX55VDXniPGEpwasv5xJooLy7hjGwn8MAmvBbdOI6gxu QIyA2H/q28liVwyWhqYtrdKVfUNsG/Y95WSPK7FaBFLiNtYRs1b4sPyGEFB/B+wbLYKq nWl5bqDAi4/58zipI43+2uJ9T2qT6OXtUIW2okCAXYbFjS5kCNrh7htb6P+19DA5lTqE x2YQ== 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 t187-v6si5190213pfd.148.2018.10.24.08.58.32; Wed, 24 Oct 2018 08:58:50 -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 S1726857AbeJYA0r (ORCPT + 99 others); Wed, 24 Oct 2018 20:26:47 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:35468 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726543AbeJYA0r (ORCPT ); Wed, 24 Oct 2018 20:26:47 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id w9OFvdMx025338; Wed, 24 Oct 2018 17:57:39 +0200 Date: Wed, 24 Oct 2018 17:57:39 +0200 From: Willy Tarreau To: Wang Hai Cc: 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: <20181024155739.GA25314@1wt.eu> References: <20181024154729.5312-1-wanghaifine@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181024154729.5312-1-wanghaifine@gmail.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 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. > if (len < 0) > return -EINVAL; Then only negative values are dropped. So unless I'm missing something obvious, you're just allowing len to be as large as 2GB-1 based on the user's fed optlen. Am I wrong ? Willy