From owner-freebsd-bugs Wed Dec 4 12: 0: 5 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 259C637B401 for ; Wed, 4 Dec 2002 12:00:02 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 34EDF43EBE for ; Wed, 4 Dec 2002 12:00:01 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id gB4K01x3032198 for ; Wed, 4 Dec 2002 12:00:01 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id gB4K01dn032197; Wed, 4 Dec 2002 12:00:01 -0800 (PST) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D4CBD37B401 for ; Wed, 4 Dec 2002 11:59:02 -0800 (PST) Received: from mailman.packetdesign.com (dns.packetdesign.com [65.192.41.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 60EA443EAF for ; Wed, 4 Dec 2002 11:59:02 -0800 (PST) (envelope-from archie@packetdesign.com) Received: from bubba.packetdesign.com (bubba.packetdesign.com [192.168.0.223]) by mailman.packetdesign.com (8.12.3/8.12.3) with ESMTP id gB4Jx2nL067669 for ; Wed, 4 Dec 2002 11:59:02 -0800 (PST) (envelope-from archie@packetdesign.com) Received: from bubba.packetdesign.com (localhost [127.0.0.1]) by bubba.packetdesign.com (8.12.6/8.12.6) with ESMTP id gB4Jx1mD068578 for ; Wed, 4 Dec 2002 11:59:01 -0800 (PST) (envelope-from archie@bubba.packetdesign.com) Received: (from archie@localhost) by bubba.packetdesign.com (8.12.6/8.12.6/Submit) id gB4Jx15C068577; Wed, 4 Dec 2002 11:59:01 -0800 (PST) Message-Id: <200212041959.gB4Jx15C068577@bubba.packetdesign.com> Date: Wed, 4 Dec 2002 11:59:01 -0800 (PST) From: Archie Cobbs Reply-To: Archie Cobbs To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: kern/45994: Pages marked read-only via mprotect() are zeroed in core files Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 45994 >Category: kern >Synopsis: Pages marked read-only via mprotect() are zeroed in core files >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Dec 04 12:00:00 PST 2002 >Closed-Date: >Last-Modified: >Originator: Archie Cobbs >Release: FreeBSD 4.7-PRERELEASE i386 >Organization: Packet Design >Environment: FYI this also happens on -current. System: FreeBSD bubba.packetdesign.com 4.7-PRERELEASE FreeBSD 4.7-PRERELEASE #0: Sat Sep 14 10:55:14 PDT 2002 archie@bubba.packetdesign.com:/usr/obj/usr/src/sys/BUBBA i386 >Description: Program marks a page read-only via mprotect(2). Program gets a fatal signal and dumps core. GDB is then run on the core file. Problem: the mprotected()'ed page is all zeroes, even though the page had non-zero contents when the program was actually running. If the program is run directly under GDB, this does not happen. >How-To-Repeat: $ cat > mprotect.c #include #include #include #include #include #include #define PGPROTECT 4096 static char buf[PGPROTECT+1] __attribute__ ((aligned(PGPROTECT))); static void sighandler(int signum) { switch (signum) { case SIGBUS: case SIGSEGV: #if 0 /* Uncomment this and buf is dumped properly in the core file */ if (mprotect(buf, PGPROTECT, PROT_READ | PROT_WRITE) == -1) err(1, "mprotect"); #endif abort(); } } int main(int argc, char *argv[]) { int prot_mode = PROT_READ; int len; signal(SIGBUS, sighandler); signal(SIGSEGV, sighandler); strcpy(buf, "This is a test"); len = strlen(buf); if (mprotect(buf, PGPROTECT, prot_mode) == -1) err(1, "mprotect(PROT_READ)"); printf("buf: %s\n", buf); buf[len] = '!'; printf("buf: %s\n", buf); return (0); } ^D $ cc -g -Wall -o mprotect mprotect.c $ ./mprotect buf: This is a test Abort(core dumped) $ gdb mprotect mprotect.core GNU gdb 4.18 (FreeBSD) Copyright 1998 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-unknown-freebsd"...Deprecated bfd_read called at /usr/src/gnu/usr.bin/binutils/gdb/../../../../contrib/gdb/gdb/dbxread.c line 2627 in elfstab_build_psymtabs Deprecated bfd_read called at /usr/src/gnu/usr.bin/binutils/gdb/../../../../contrib/gdb/gdb/dbxread.c line 933 in fill_symbuf Core was generated by `mprotect'. Program terminated with signal 6, Abort trap. Reading symbols from /usr/lib/libc.so.4...done. Reading symbols from /usr/libexec/ld-elf.so.1...done. #0 0x2809c50c in kill () from /usr/lib/libc.so.4 (gdb) x/16b buf 0x804b000 : 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x804b008 : 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 (gdb) >Fix: Unknown. >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message