Date: Mon, 10 Jun 2019 10:17:44 +0300 From: Andriy Gapon <avg@FreeBSD.org> To: Doug Moore <dougm@rice.edu>, Doug Moore <dougm@FreeBSD.org>, src-committers@FreeBSD.org, svn-src-all@FreeBSD.org, svn-src-head@FreeBSD.org Subject: Re: svn commit: r348843 - head/sys/vm Message-ID: <bf8f80a0-4de9-dd98-6063-664a04973971@FreeBSD.org> In-Reply-To: <21baf615-3356-73a1-52b0-d2f33f4cf49d@rice.edu> References: <201906100307.x5A37BFt099669@repo.freebsd.org> <c54a0e35-d5c6-0711-d2bb-01e3dca802c3@FreeBSD.org> <21baf615-3356-73a1-52b0-d2f33f4cf49d@rice.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
On 10/06/2019 09:42, Doug Moore wrote: > -fwrapv concerns signed arithmetic. This calculation is with unsigned > arithmetic, and the possibility of wrapping around to 0 is part of the > language. Oh, sorry for the noise! > On 6/10/19 1:35 AM, Andriy Gapon wrote: >> On 10/06/2019 06:07, Doug Moore wrote: >>> Author: dougm >>> Date: Mon Jun 10 03:07:10 2019 >>> New Revision: 348843 >>> URL: https://svnweb.freebsd.org/changeset/base/348843 >>> >>> Log: >>> There are times when a len==0 parameter to mmap is okay. But on a >>> 32-bit machine, a len parameter just a few bytes short of 4G, rounded >>> up to a page boundary and hitting zero then, is not okay. Return >>> failure in that case. >>> >>> Reported by: pho >>> Reviewed by: alc, kib (mentor) >>> Tested by: pho >>> Differential Revision: https://reviews.freebsd.org/D20580 >>> >>> Modified: >>> head/sys/vm/vm_mmap.c >>> >>> Modified: head/sys/vm/vm_mmap.c >>> ============================================================================== >>> --- head/sys/vm/vm_mmap.c Sun Jun 9 22:55:21 2019 (r348842) >>> +++ head/sys/vm/vm_mmap.c Mon Jun 10 03:07:10 2019 (r348843) >>> @@ -257,7 +257,10 @@ kern_mmap(struct thread *td, uintptr_t addr0, size_t s >>> >>> /* Adjust size for rounding (on both ends). */ >>> size += pageoff; /* low end... */ >>> - size = (vm_size_t) round_page(size); /* hi end */ >>> + /* Check for rounding up to zero. */ >>> + if (round_page(size) < size) >> Is this guaranteed to work with all compilers? >> I think that some smart compilers may think that this condition is impossible. >> Are we finally using -fwrapv or something like it for kernel builds? >> >>> + return (EINVAL); >>> + size = round_page(size); /* hi end */ >>> >>> /* Ensure alignment is at least a page and fits in a pointer. */ >>> align = flags & MAP_ALIGNMENT_MASK; >>> >> -- Andriy Gapon
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bf8f80a0-4de9-dd98-6063-664a04973971>