From owner-freebsd-bugs@FreeBSD.ORG Sun Jun 22 06:19:46 2008 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E7DD81065687 for ; Sun, 22 Jun 2008 06:19:45 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.155]) by mx1.freebsd.org (Postfix) with ESMTP id 7EF328FC12 for ; Sun, 22 Jun 2008 06:19:45 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: by fg-out-1718.google.com with SMTP id l26so1074316fgb.35 for ; Sat, 21 Jun 2008 23:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=NwPER7Ahog1ODdVzalj+bMWiIk5C6nBGAEwBGWjMQJA=; b=JEN65j36WyOyJhsS7bO0MHHlAMD3tOIzYeqOjqO9Ei7CfX4gJvCN3GUjoD9hRh4O7B tZryEAoIqoZAFc5zuWPAK/tJzLA9AaQH0sf9C5Sv6sffbHSjsPJjDKkKoraV7IV36g4Z m2hUE6zTZAL3QoapiA7aE5Szw4nx10sZERuCw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=wBK4vgqSQ2WufGOJtdofbKQp2M/tyyC98Yn2taEAgKl7BRTq+6ZrDhkI797E6loMaW 6tUZpp6mkHj64/TKvTBJrbQwRDzf6o8xLkTBzKt+JfsRqqNjHa6NOtIydFYFnVPl/pCA 8Q0bsutqR5so3SvEG21+8I01jhlTV/Z75JB6Y= Received: by 10.86.78.4 with SMTP id a4mr6553834fgb.14.1214115583960; Sat, 21 Jun 2008 23:19:43 -0700 (PDT) Received: by 10.86.51.1 with HTTP; Sat, 21 Jun 2008 23:19:43 -0700 (PDT) Message-ID: <7d6fde3d0806212319q779b1dd9r823b9777a9694185@mail.gmail.com> Date: Sat, 21 Jun 2008 23:19:43 -0700 From: "Garrett Cooper" To: "Giorgos Keramidas" In-Reply-To: <200806220310.m5M3A4KJ007718@freefall.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200806220310.m5M3A4KJ007718@freefall.freebsd.org> Cc: freebsd-bugs@freebsd.org Subject: Re: bin/124409: fsck(8) requires exact entry for mountpoints when executing / bug by design in getfsfile(3) in .../lib/libc/gen/fstab.c X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Jun 2008 06:19:46 -0000 On Sat, Jun 21, 2008 at 8:10 PM, Giorgos Keramidas wrote: > The following reply was made to PR bin/124409; it has been noted by GNATS. > > From: Giorgos Keramidas > To: "Garrett Cooper" > Cc: bug-followup@freebsd.org > Subject: Re: bin/124409: fsck(8) requires exact entry for mountpoints when executing / bug by design in getfsfile(3) in .../lib/libc/gen/fstab.c > Date: Sun, 22 Jun 2008 06:07:37 +0300 > > On Mon, 16 Jun 2008 20:28:08 -0700, "Garrett Cooper" wrote: > > On Tue, Jun 10, 2008 at 2:27 AM, Garrett Cooper wrote: > >> Ok.... it appears I wasn't intelligent enough to post this in the right > >> place last night. Comments please? > >> > >> Hi hackers, > >> > >> I have a question, pending a bug found in getfsfile(3) [1]. > >> > >> Is there any possibility where a mountpoint be any value other > >> > >> than a directory, a symlink, or "none", i.e. a flat file? > >> > >> Thanks, > >> > >> -Garrett > >> > >> References: > >> > >> http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/124409 (not fully in PR > >> > >> database yet). > > > > Going once, going twice... > > Hi Garrett :-) > > When I wrote the original comment in that PR I had something like this > in mind: > > %%% > *** src.7789d2851415/lib/libc/gen/fstab.c Sun Jun 22 05:57:09 2008 > --- /home/build/src/lib/libc/gen/fstab.c Sun Jun 22 05:56:48 2008 > *************** struct fstab * > *** 236,245 **** > getfsfile(name) > const char *name; > { > if (setfsent()) > ! while (fstabscan()) > ! if (!strcmp(_fs_fstab.fs_file, name)) > return(&_fs_fstab); > return((struct fstab *)NULL); > } > > --- 236,256 ---- > getfsfile(name) > const char *name; > { > + char name_path[PATH_MAX]; > + char fstab_path[PATH_MAX]; > + > + if (realpath(name, name_path) == NULL) > + return((struct fstab *)NULL); > if (setfsent()) > ! while (fstabscan()) { > ! if (strcmp(_fs_fstab.fs_file, name) == 0 || > ! strcmp(_fs_fstab.fs_file, name_path) == 0) > ! return(&_fs_fstab); > ! if (realpath(_fs_fstab.fs_file, fstab_path) == NULL) > ! return((struct fstab *)NULL); > ! if (strcmp(fstab_path, name_path) == 0) > return(&_fs_fstab); > + } > return((struct fstab *)NULL); > } > > %%% > > I tried to avoid unnecessary realpath(3) calls as much as possible, but > there is still the possibility for at least N+1 calls, where N is the > number of entries in fstab... > > Can you test the above patch, and let me know if it looks ok, if you > have a better fix in the works, etc.? It seems to pass the bug you > originally reported when I run: > > % env LD_PRELOAD=/home/build/obj/home/build/src/lib/libc/libc.so.7 \ > fsck ///cdrom/// > fsck: exec fsck_cd9660 for /dev/acd0 in /sbin:/usr/sbin: No such file or directory > > The failure later is ok, because we don't have fsck_cd9660 for CD-ROMs. There was a reason why I avoided going straight to realpath... didn't realpath have security issues and the like, such that it wasn't Linux (it isn't included in glibc) uses a function called canonicalize() for resolving paths, which does something similar to realpath, but doesn't resolve symlinks, IIRC, and thus avoids the security / race condition issue. Cheers, -Garrett