From owner-svn-src-all@freebsd.org Mon Jun 10 21:26:15 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 31C6F15C9B58; Mon, 10 Jun 2019 21:26:15 +0000 (UTC) (envelope-from dougm@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C525B8DC34; Mon, 10 Jun 2019 21:26:14 +0000 (UTC) (envelope-from dougm@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9DD961FF4F; Mon, 10 Jun 2019 21:26:14 +0000 (UTC) (envelope-from dougm@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x5ALQExr078528; Mon, 10 Jun 2019 21:26:14 GMT (envelope-from dougm@FreeBSD.org) Received: (from dougm@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x5ALQEvO078526; Mon, 10 Jun 2019 21:26:14 GMT (envelope-from dougm@FreeBSD.org) Message-Id: <201906102126.x5ALQEvO078526@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dougm set sender to dougm@FreeBSD.org using -f From: Doug Moore Date: Mon, 10 Jun 2019 21:26:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r348879 - in head/sys: sys vm X-SVN-Group: head X-SVN-Commit-Author: dougm X-SVN-Commit-Paths: in head/sys: sys vm X-SVN-Commit-Revision: 348879 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: C525B8DC34 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.955,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jun 2019 21:26:15 -0000 Author: dougm Date: Mon Jun 10 21:26:14 2019 New Revision: 348879 URL: https://svnweb.freebsd.org/changeset/base/348879 Log: Change the check for 'size' wrapping around to zero in kern_mmap to account for both the lower and upper bound modifications. Change the error returned to ENOMEM. Rename the parameter size to len and make size a local variable that stores the value of len after it has been modified. This addresses concerns expressed by Bruce Evans after r348843. Reported by: brde@optusnet.com.au Reviewed by: kib, markj (mentors) MFC after: 3 days Relnotes: yes Differential Revision: https://reviews.freebsd.org/D20592 Modified: head/sys/sys/syscallsubr.h head/sys/vm/vm_mmap.c Modified: head/sys/sys/syscallsubr.h ============================================================================== --- head/sys/sys/syscallsubr.h Mon Jun 10 21:24:38 2019 (r348878) +++ head/sys/sys/syscallsubr.h Mon Jun 10 21:26:14 2019 (r348879) @@ -173,7 +173,7 @@ int kern_mknodat(struct thread *td, int fd, const char enum uio_seg pathseg, int mode, dev_t dev); int kern_mlock(struct proc *proc, struct ucred *cred, uintptr_t addr, size_t len); -int kern_mmap(struct thread *td, uintptr_t addr, size_t size, int prot, +int kern_mmap(struct thread *td, uintptr_t addr, size_t len, int prot, int flags, int fd, off_t pos); int kern_mprotect(struct thread *td, uintptr_t addr, size_t size, int prot); int kern_msgctl(struct thread *, int, int, struct msqid_ds *); Modified: head/sys/vm/vm_mmap.c ============================================================================== --- head/sys/vm/vm_mmap.c Mon Jun 10 21:24:38 2019 (r348878) +++ head/sys/vm/vm_mmap.c Mon Jun 10 21:26:14 2019 (r348879) @@ -179,13 +179,13 @@ sys_mmap(struct thread *td, struct mmap_args *uap) } int -kern_mmap(struct thread *td, uintptr_t addr0, size_t size, int prot, int flags, +kern_mmap(struct thread *td, uintptr_t addr0, size_t len, int prot, int flags, int fd, off_t pos) { struct vmspace *vms; struct file *fp; vm_offset_t addr; - vm_size_t pageoff; + vm_size_t pageoff, size; vm_prot_t cap_maxprot; int align, error; cap_rights_t rights; @@ -210,7 +210,7 @@ kern_mmap(struct thread *td, uintptr_t addr0, size_t s * pos. */ if (!SV_CURPROC_FLAG(SV_AOUT)) { - if ((size == 0 && curproc->p_osrel >= P_OSREL_MAP_ANON) || + if ((len == 0 && curproc->p_osrel >= P_OSREL_MAP_ANON) || ((flags & MAP_ANON) != 0 && (fd != -1 || pos != 0))) return (EINVAL); } else { @@ -255,12 +255,12 @@ kern_mmap(struct thread *td, uintptr_t addr0, size_t s pageoff = (pos & PAGE_MASK); pos -= pageoff; - /* Adjust size for rounding (on both ends). */ - size += pageoff; /* low end... */ - /* Check for rounding up to zero. */ - if (round_page(size) < size) - return (EINVAL); + /* Compute size from len by rounding (on both ends). */ + size = len + pageoff; /* low end... */ size = round_page(size); /* hi end */ + /* Check for rounding up to zero. */ + if (len < size) + return (ENOMEM); /* Ensure alignment is at least a page and fits in a pointer. */ align = flags & MAP_ALIGNMENT_MASK; @@ -317,7 +317,7 @@ kern_mmap(struct thread *td, uintptr_t addr0, size_t s addr = round_page((vm_offset_t)vms->vm_daddr + lim_max(td, RLIMIT_DATA)); } - if (size == 0) { + if (len == 0) { /* * Return success without mapping anything for old * binaries that request a page-aligned mapping of