This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Shared Memory Access Problem


On 12-09-07 04:08 PM, Jonathan Wakely wrote:
On 8 September 2012 00:03, Bob Furber wrote:

Why is the client capable of accessing shared memory when executed by root and not able to, when executed by a user?

This doesn't sound like it has anything to do with GCC.

After a lot of experimentation, I think the problem lies in shm_open().


The following code generates a /dev/shm/shared with -rw-r--r-- access privileges, making it inaccessible to others, even though the mode is set to rw-rw-rw-:

shmfd = shm_open( shm_name,	// shared memory block with this "/name"
		  O_CREAT,	// Create if not already there
		  0666 );	// with these access privileges

Same for:

shmfd = shm_open( shm_name,	// shared memory block with this "/name"
		  O_CREAT,	// Create if not already there
		| O_RDWR,	// allow read and write access
		  S_IRWXU	// 00700 user has rwx privileges
		| S_IRWXG	// 00070 group has rwx privileges
		| S_IRWXO );	// 00007 others has rwx privileges


However, if this is followed by:


fchmod( shmfd,
	  O_CREAT	// Create if not already there
	| O_RDWR	// allow read and write access
	| S_IRWXU	// 00700 user (file owner) has rwx privileges
	| S_IRWXG	// 00070 group (file owner) has rwx privileges
	| S_IRWXO );	// 00007 others has rwx privileges

/dev/shm/shared ends up with rw-rw-rw- privileges (since it is not executable).

smget() was more difficult to troubleshoot because it does not produce a file descriptor and I could not find the corresponding file to check its access privileges.

RF



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]