From owner-freebsd-bugs@FreeBSD.ORG Sun Mar 24 02:50:01 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 768D2AF1 for ; Sun, 24 Mar 2013 02:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 5D7277F4 for ; Sun, 24 Mar 2013 02:50:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.6/8.14.6) with ESMTP id r2O2o1oL022591 for ; Sun, 24 Mar 2013 02:50:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.6/8.14.6/Submit) id r2O2o1bt022590; Sun, 24 Mar 2013 02:50:01 GMT (envelope-from gnats) Resent-Date: Sun, 24 Mar 2013 02:50:01 GMT Resent-Message-Id: <201303240250.r2O2o1bt022590@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Eric van Gyzen Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 98CAE833 for ; Sun, 24 Mar 2013 02:47:10 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 7155F7B0 for ; Sun, 24 Mar 2013 02:47:10 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r2O2l9Q5013101 for ; Sun, 24 Mar 2013 02:47:09 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.5/8.14.5/Submit) id r2O2l9hW013100; Sun, 24 Mar 2013 02:47:09 GMT (envelope-from nobody) Message-Id: <201303240247.r2O2l9hW013100@red.freebsd.org> Date: Sun, 24 Mar 2013 02:47:09 GMT From: Eric van Gyzen To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: misc/177328: [patch] libstand fails on ext2fs directories with more than one block X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Mar 2013 02:50:01 -0000 >Number: 177328 >Category: misc >Synopsis: [patch] libstand fails on ext2fs directories with more than one block >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Mar 24 02:50:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Eric van Gyzen >Release: 8.1-RELEASE >Organization: Dell, Inc. >Environment: N/A >Description: When booting from an ext2fs file system, the loader skips the first 1k of a file if the directory entry for that file isn't in the first 1k of the directory of the root directory. >How-To-Repeat: Put several files in the boot directory, then add the kernel, to ensure that the kernel's directory entry isn't in the first block of the directory. >Fix: Port this fix from ufs.c (from 2004): http://svnweb.freebsd.org/base?view=revision&revision=134760 We've been running with the attached patch since August 2011. Patch attached with submission follows: diff --git a/src/lib/libstand/ext2fs.c b/src/lib/libstand/ext2fs.c index 53c4f56..40ce167 100644 --- a/src/lib/libstand/ext2fs.c +++ b/src/lib/libstand/ext2fs.c @@ -536,6 +536,17 @@ ext2fs_open(const char *upath, struct open_file *f) * Found terminal component. */ error = 0; + + // Reset the seek pointer to 0 when a file is successfully opened, + // since otherwise the initial seek offset will contain the directory + // offset of the filesystem block that contained its directory entry. + // This bug was mostly harmless because typically the directory is + // less than one filesystem block in size so the offset would be zero. + // It did however generally break loading a kernel from the (large) + // kernel compile directory. + // http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libstand/ufs.c#rev1.15 + fp->f_seekp = 0; + out: if (buf) free(buf); @@ -585,6 +596,16 @@ read_inode(ino_t inumber, struct open_file *f) fp->f_blkno[level] = -1; fp->f_buf_blkno = -1; + // Reset the seek pointer to 0 when a file is successfully opened, + // since otherwise the initial seek offset will contain the directory + // offset of the filesystem block that contained its directory entry. + // This bug was mostly harmless because typically the directory is + // less than one filesystem block in size so the offset would be zero. + // It did however generally break loading a kernel from the (large) + // kernel compile directory. + // http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libstand/ufs.c#rev1.15 + fp->f_seekp = 0; + out: free(buf); return (error); >Release-Note: >Audit-Trail: >Unformatted: