From owner-freebsd-hackers Mon Feb 28 17: 4:53 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from orion.ac.hmc.edu (Orion.AC.HMC.Edu [134.173.32.20]) by hub.freebsd.org (Postfix) with ESMTP id 9136637B9DA for ; Mon, 28 Feb 2000 17:04:45 -0800 (PST) (envelope-from brdavis@orion.ac.hmc.edu) Received: (from brdavis@localhost) by orion.ac.hmc.edu (8.8.8/8.8.8) id RAA20023; Mon, 28 Feb 2000 17:04:43 -0800 (PST) Date: Mon, 28 Feb 2000 17:04:43 -0800 From: Brooks Davis To: Brooks Davis Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: mprotect(2) won't make shared memory read-only Message-ID: <20000228170443.A16556@orion.ac.hmc.edu> References: <20000228125013.A25992@orion.ac.hmc.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre4i In-Reply-To: <20000228125013.A25992@orion.ac.hmc.edu>; from brooks@one-eyed-alien.net on Mon, Feb 28, 2000 at 12:50:13PM -0800 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Mon, Feb 28, 2000 at 12:50:13PM -0800, Brooks Davis wrote: > On a -current system as of a week or two ago (as well as a 3.3-RC and a > 2.2.8-STABLE box) I've found that mprotect fails with with EACCES when > trying to make a shared memory segment that was created user read/write > read-only. It works find if I malloc the memory instead and making the > shm segment write-only or inaccessible works fine as well. Is this > expected behavior? If so it's pretty weird. Following up on this. Charles Randall suggested I try shmctl to make the segment read-only. Unfortunatly it appears that shared memory premissions are screwed up as well. You can create a read-only shared memory segment either via shmget or via shmctl on an existing read-write segment and it will appear via ipcs, but it doesn't appear to have any effect. The following program creates a read-only segment and then proceds to write to it twice, both of which work under FreeBSD -current. When run on a Solaris 2.6 machine it segfaults in the first write. ---- /* Test read-only shared memory segments */ #include #include #include #include #include #include #include #define SIZE 1024*sizeof(int) int main(int argc, char **argv) { int *array; int shmid; shmid = shmget(IPC_PRIVATE, SIZE, SHM_R); array = shmat(shmid, NULL, 0); bzero(array, SIZE); fprintf(stderr, "array[0] = %d\n", array[0]); array[0] = 1; fprintf(stderr, "array[0] = %d\n", array[0]); shmctl(shmid, IPC_RMID, NULL); return 0; } ---- Thanks, Brooks -- Any statement of the form "X is the one, true Y" is FALSE. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message