From owner-freebsd-bugs@FreeBSD.ORG Fri Sep 3 22:00:14 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 40EEE10656C9 for ; Fri, 3 Sep 2010 22:00:14 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 02CA68FC14 for ; Fri, 3 Sep 2010 22:00:14 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o83M0DNX012544 for ; Fri, 3 Sep 2010 22:00:13 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o83M0Dth012526; Fri, 3 Sep 2010 22:00:13 GMT (envelope-from gnats) Resent-Date: Fri, 3 Sep 2010 22:00:13 GMT Resent-Message-Id: <201009032200.o83M0Dth012526@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ion Gaztaņaga Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 542FE10656D8 for ; Fri, 3 Sep 2010 21:51:28 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 42B0D8FC0A for ; Fri, 3 Sep 2010 21:51:28 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o83LpSWR018534 for ; Fri, 3 Sep 2010 21:51:28 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o83LpRd5018533; Fri, 3 Sep 2010 21:51:27 GMT (envelope-from nobody) Message-Id: <201009032151.o83LpRd5018533@www.freebsd.org> Date: Fri, 3 Sep 2010 21:51:27 GMT From: Ion Gaztaņaga To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: kern/150260: mmap fails with EPERM (not documented) if read-only shared memory is mmapped with MAP_PRIVATE & PROT_WRITE X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Sep 2010 22:00:14 -0000 >Number: 150260 >Category: kern >Synopsis: mmap fails with EPERM (not documented) if read-only shared memory is mmapped with MAP_PRIVATE & PROT_WRITE >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Sep 03 22:00:13 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Ion Gaztaņaga >Release: 8.0-RELEASE-p2 >Organization: >Environment: FreeBSD pcbsd-4080 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #4: Thu Jan 7 09:20:42 PST 2010 root@build8x32.pcbsd.org:/usr/obj/usr/pcbsd-build80/fbsd-source/8.0-src/sys/PCBSD i386 >Description: mmap allows copy on write file/shared memory mapping via MAP_PRIVATE and only requires a read-only file descriptor. This works with files but not with shared memory objects (mmap returns EPERM). >How-To-Repeat: Execute the attached c program >Fix: Patch attached with submission follows: #include #include #include #include #include #include int main() { shm_unlink("/myshm"); int fd = shm_open("/myshm", O_CREAT | O_RDWR, 0644); if(fd >= 0){ if(ftruncate(fd, 1000) < 0){ printf("Error truncating"); close(fd); } else{ close(fd); fd = shm_open("/myshm", O_RDONLY/*O_RDWR*/, 0644); if(fd >= 0){ void *addr = mmap(0, 1000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == addr){ printf("mmap failed, errno: %s", strerror(errno)); } else{ printf("mmap OK"); munmap(addr, 1000); } close(fd); } else{ printf("Error opening shmem"); } } } else{ printf("Error creating shmem"); } shm_unlink("/myshm"); return 0; } >Release-Note: >Audit-Trail: >Unformatted: