Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/uvm Make mmap() with "len == 0" an error if not MAP_ANON...



details:   https://anonhg.NetBSD.org/src/rev/9ee7a4ec68c2
branches:  trunk
changeset: 364484:9ee7a4ec68c2
user:      hannken <hannken%NetBSD.org@localhost>
date:      Sun Mar 27 20:18:05 2022 +0000

description:
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.

diffstat:

 sys/uvm/uvm_mmap.c |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r 2181ac68ed8a -r 9ee7a4ec68c2 sys/uvm/uvm_mmap.c
--- a/sys/uvm/uvm_mmap.c        Sun Mar 27 18:39:01 2022 +0000
+++ b/sys/uvm/uvm_mmap.c        Sun Mar 27 20:18:05 2022 +0000
@@ -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 @@
        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.
         */



Home | Main Index | Thread Index | Old Index