From owner-svn-src-head@FreeBSD.ORG Fri Jul 24 18:53:46 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EA5DB106566B; Fri, 24 Jul 2009 18:53:46 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id A76B58FC1F; Fri, 24 Jul 2009 18:53:46 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 447D246B03; Fri, 24 Jul 2009 14:53:46 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id 0DA088A0A1; Fri, 24 Jul 2009 14:53:45 -0400 (EDT) From: John Baldwin To: Robert Watson Date: Fri, 24 Jul 2009 14:21:53 -0400 User-Agent: KMail/1.9.7 References: <200907241340.n6ODeP2B011222@svn.freebsd.org> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200907241421.54000.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Fri, 24 Jul 2009 14:53:45 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r195839 - head/usr.bin/locate/locate X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jul 2009 18:53:47 -0000 On Friday 24 July 2009 1:45:01 pm Robert Watson wrote: > > On Fri, 24 Jul 2009, John Baldwin wrote: > > > Move the check to ensure the locate database has the minimum required size > > when using mmap() before invoking mmap(). This avoids a confusing error > > message when locate is invoked against a zero-size database after the > > recent change to make mmap() fail requests to map 0 bytes. > > Does this mean we should anticipate other possible application compatibility > problems? And I guess that means a 7.2 userspace (i.e., jail) on an 8.0 > kernel won't support locate? In the case of locate(8) the only difference was in the error message received. In 7.2 if you used /dev/null as your locate database then you would trigger the "database too small" error. In 8.0 prior to this fix it was failing due to mmap() dying with EINVAL so a more confusing "Invalid parameter" error was emitted. This just makes the error message more readable. In general I would not expect 3rd party applications to break since other OS's such as Linux and OpenSolaris already fail mmap() with a length of 0 with EINVAL: http://fxr.watson.org/fxr/source/mm/mmap.c?v=linux-2.6#L932 http://fxr.watson.org/fxr/source/common/os/grow.c?v=OPENSOLARIS;im=excerpts#L647 Curiously NetBSD, OpenBSD, and Darwin all seem to return a random address that isn't really mapped with no error value. NetBSD silently returns 0 without doing anything for an munmap() with a length of 0. OpenBSD will return 0 if the address passed to munmap() is a valid address for the process w/o doing anything and EINVAL if the address is not valid I think (so passing the return value of mmap(.., 0) to munmap() may or may not succeed on OpenBSD). Darwin returns EINVAL for an munmap() with a length of 0. DFBSD does the same thing FreeBSD did before my commit to mmap(). > Robert > > > > > Submitted by: Jaakko Heinonen jh of saunalahti dot fi > > Approved by: re (kensmith) > > MFC after: 1 week > > > > Modified: > > head/usr.bin/locate/locate/fastfind.c > > head/usr.bin/locate/locate/locate.c > > > > Modified: head/usr.bin/locate/locate/fastfind.c > > ============================================================================== > > --- head/usr.bin/locate/locate/fastfind.c Thu Jul 23 21:12:21 2009 (r195838) > > +++ head/usr.bin/locate/locate/fastfind.c Fri Jul 24 13:40:25 2009 (r195839) > > @@ -154,9 +154,6 @@ fastfind > > > > /* init bigram table */ > > #ifdef FF_MMAP > > - if (len < (2*NBG)) > > - errx(1, "database too small: %s", database); > > - > > for (c = 0, p = bigram1, s = bigram2; c < NBG; c++, len-= 2) { > > p[c] = check_bigram_char(*paddr++); > > s[c] = check_bigram_char(*paddr++); > > > > Modified: head/usr.bin/locate/locate/locate.c > > ============================================================================== > > --- head/usr.bin/locate/locate/locate.c Thu Jul 23 21:12:21 2009 (r195838) > > +++ head/usr.bin/locate/locate/locate.c Fri Jul 24 13:40:25 2009 (r195839) > > @@ -291,6 +291,8 @@ search_mmap(db, s) > > fstat(fd, &sb) == -1) > > err(1, "`%s'", db); > > len = sb.st_size; > > + if (len < (2*NBG)) > > + errx(1, "database too small: %s", db); > > > > if ((p = mmap((caddr_t)0, (size_t)len, > > PROT_READ, MAP_SHARED, > > > -- John Baldwin