Date: Thu, 25 Feb 2010 21:28:50 +0100 From: Juergen Lock <nox@jelal.kn-bremen.de> To: Juergen Lock <nox@jelal.kn-bremen.de> Cc: freebsd-hackers@FreeBSD.org, freebsd-emulation@FreeBSD.org, Tim Kientzle <kientzle@FreeBSD.org> Subject: 32 bit Linux lseek missing overflow check (was: Re: Linuxolator patches: stat and lseek SEEK_END for disk devices) Message-ID: <20100225202850.GA79505@triton8.kn-bremen.de> In-Reply-To: <20100223215010.GA67619@triton8.kn-bremen.de> References: <20100223215010.GA67619@triton8.kn-bremen.de>
next in thread | previous in thread | raw e-mail | index | archive | help
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; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100225202850.GA79505>