From owner-freebsd-hackers@FreeBSD.ORG Tue Nov 17 10:20:23 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 47A541065676 for ; Tue, 17 Nov 2009 10:20:23 +0000 (UTC) (envelope-from sharadc@in.niksun.com) Received: from in.niksun.com (210.18.76.166.sify.net [210.18.76.166]) by mx1.freebsd.org (Postfix) with ESMTP id 323D98FC2A for ; Tue, 17 Nov 2009 10:20:21 +0000 (UTC) Received: from sharadc.in.niksun.com (unknown [10.60.5.27]) by in.niksun.com (Postfix) with ESMTP id D92275CBE; Tue, 17 Nov 2009 15:39:17 +0530 (IST) From: Sharad Chandra Organization: NIKSUN To: freebsd-hackers@freebsd.org Date: Tue, 17 Nov 2009 15:29:19 +0530 User-Agent: KMail/1.9.4 X-Face: "$jQ]ksJ8"4@"hbi0lV=]BJ`myq*p; AcKl=e)=?utf-8?q?=5B3jei!uFob=0A=09?=(xpq6aZ|P(h&l}OxOfr`KGp2}$`IF-)7F6Pp[X#)n*&VF>=?utf-8?q?BoCU0iZ=3F6=7CAZpbi=23F=3B=5E0wP-d=0A=09W=5EucFs*nP?=@dj7x`; _PG@wRen8\in2VpfmCz(,.|>=?utf-8?q?U2KD*hIJHk86=5EH=5E=0A=09ct/-=3F=3D8i16u?=,oB'J*9^\#aN' MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_4PnALyOOKlA8Off" Message-Id: <200911171529.20098.sharadc@in.niksun.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Manprit Singh Subject: mprotect(2) clears the flag for whole page which causes program crash. X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Nov 2009 10:20:23 -0000 --Boundary-00=_4PnALyOOKlA8Off Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, mportect clears the exec flag of whole page by which my program crashed. I am attaching sample code. It is performing below task 1) allocate memory1 2) allocate memory2 3) change permission of memory 1 and 2 to exec by mprotect. 4) clear the exec permission of memory 1 and free it. 5) execute the memory2 by mapping to pointer function. 6) clear the exec permission of memory 2 and free it. Program crashed at step 5 if memory 1 and 2 are in same page. $ uname -a FreeBSD app164.in.niksun.com 7.2-RELEASE FreeBSD 7.2-RELEASE #0: Fri May 1 07:18:07 UTC 2009 root@driscoll.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 $ gcc -g -o test -Wall mprotect.c $ ./test mem1 at: 34369183888 mem2 at: 34369183892 address difference: 4 test_func1 function returned 0 test_func2 will crash here Segmentation fault (core dumped) Is it known bug or is there any workaround? How will a userland process make sure that process will not crash as malloc(3) can allocate where ever it get the memory free to use. -- Thanks, Sharad Chandra --Boundary-00=_4PnALyOOKlA8Off--