Module Name:    src
Committed By:   hannken
Date:           Sun Mar 27 20:18:05 UTC 2022

Modified Files:
        src/sys/uvm: uvm_mmap.c

Log Message:
Make mmap() with "len == 0" an error if not MAP_ANON.  We should return
an error for MAP_ANON too but unfortunately our /libexec/ld.elf_so
sometimes creates an empty anon mapping for the bss of a shared library.

At least FreeBSD and Solaris return this error too and according to POSIX
"If len is zero, mmap() shall fail and no mapping shall be established".

Fixes PR pkg/56338 Installing qt5-qtdeclarative leaves a dangling reference

The dangling reference here originates from vn_mmap() taking a vnode
reference for this empty mapping that will never be released.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/sys/uvm/uvm_mmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_mmap.c
diff -u src/sys/uvm/uvm_mmap.c:1.176 src/sys/uvm/uvm_mmap.c:1.177
--- src/sys/uvm/uvm_mmap.c:1.176	Wed Jul 21 06:35:45 2021
+++ src/sys/uvm/uvm_mmap.c	Sun Mar 27 20:18:05 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_mmap.c,v 1.176 2021/07/21 06:35:45 skrll Exp $	*/
+/*	$NetBSD: uvm_mmap.c,v 1.177 2022/03/27 20:18:05 hannken Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.176 2021/07/21 06:35:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.177 2022/03/27 20:18:05 hannken Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_pax.h"
@@ -304,6 +304,9 @@ sys_mmap(struct lwp *l, const struct sys
 	if ((flags & (MAP_SHARED|MAP_PRIVATE)) == (MAP_SHARED|MAP_PRIVATE))
 		return EINVAL;
 
+	if (size == 0 && (flags & MAP_ANON) == 0)
+		return EINVAL;
+
 	/*
 	 * align file position and save offset.  adjust size.
 	 */

Reply via email to