From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 25 20:30:52 2010 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4E9D8106564A; Thu, 25 Feb 2010 20:30:52 +0000 (UTC) (envelope-from nox@jelal.kn-bremen.de) Received: from smtp.kn-bremen.de (gelbbaer.kn-bremen.de [78.46.108.116]) by mx1.freebsd.org (Postfix) with ESMTP id 0AE338FC1E; Thu, 25 Feb 2010 20:30:51 +0000 (UTC) Received: by smtp.kn-bremen.de (Postfix, from userid 10) id E91551E00173; Thu, 25 Feb 2010 21:30:50 +0100 (CET) Received: from triton8.kn-bremen.de (noident@localhost [127.0.0.1]) by triton8.kn-bremen.de (8.14.3/8.14.3) with ESMTP id o1PKSoIG079567; Thu, 25 Feb 2010 21:28:50 +0100 (CET) (envelope-from nox@triton8.kn-bremen.de) Received: (from nox@localhost) by triton8.kn-bremen.de (8.14.3/8.14.3/Submit) id o1PKSovb079566; Thu, 25 Feb 2010 21:28:50 +0100 (CET) (envelope-from nox) From: Juergen Lock Date: Thu, 25 Feb 2010 21:28:50 +0100 To: Juergen Lock Message-ID: <20100225202850.GA79505@triton8.kn-bremen.de> References: <20100223215010.GA67619@triton8.kn-bremen.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100223215010.GA67619@triton8.kn-bremen.de> User-Agent: Mutt/1.5.20 (2009-06-14) X-Mailman-Approved-At: Thu, 25 Feb 2010 20:53:32 +0000 Cc: freebsd-hackers@FreeBSD.org, freebsd-emulation@FreeBSD.org, Tim Kientzle Subject: 32 bit Linux lseek missing overflow check (was: Re: Linuxolator patches: stat and lseek SEEK_END for disk devices) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2010 20:30:52 -0000 On Tue, Feb 23, 2010 at 10:50:10PM +0100, Juergen Lock wrote: > Hi! > > Before this gets buried on -hackers in another thead... :) > > I now have disks appear as block devices for Linux processes (there > already was commented out code for that in linux_stats.c, I hope my > version is now `correct enough' to be usable [1]), and I made a simple > patch to make lseek SEEK_END (L_XTND in the source) dtrt on disk > devices too by simply invoking the DIOCGMEDIASIZE ioctl there; [2] > both of these things are what (some) Linux processes expect. > > Patches are here: (made on stable/8, if they don't apply on head > I'll have to make extra versions for that...) > http://people.freebsd.org/~nox/linuxdisk-blk.patch [1] > http://people.freebsd.org/~nox/lseek-seek_end.patch [2] > > And yes, with these patches the Linux bsdtar mentioned on -hackers > in the `"tar tfv /dev/cd0" speedup patch' thread now also runs fast > on FreeBSD. :) I now added an vn_isdisk() check to the second patch after comments from julian, and I made a new patch that adds an overflow check to the 32 bit linux lseek: (also at http://people.freebsd.org/~nox/linux-lseek-overflow.patch ) Index: src/sys/compat/linux/linux_file.c =================================================================== RCS file: /home/scvs/src/sys/compat/linux/linux_file.c,v retrieving revision 1.119.2.1 diff -u -p -u -p -r1.119.2.1 linux_file.c --- src/sys/compat/linux/linux_file.c 3 Aug 2009 08:13:06 -0000 1.119.2.1 +++ src/sys/compat/linux/linux_file.c 25 Feb 2010 20:08:47 -0000 @@ -226,6 +226,7 @@ linux_lseek(struct thread *td, struct li int whence; } */ tmp_args; int error; + l_off_t l_off; #ifdef DEBUG if (ldebug(lseek)) @@ -236,6 +237,10 @@ linux_lseek(struct thread *td, struct li tmp_args.offset = (off_t)args->off; tmp_args.whence = args->whence; error = lseek(td, &tmp_args); + /* Check for overflow like Linux does. */ + l_off = *(off_t *)td->td_retval; + if (((off_t)l_off) != *(off_t *)td->td_retval) + error = EOVERFLOW; return error; }