php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40760 not honoring mode of shm_attach
Submitted: 2007-03-08 17:41 UTC Modified: 2007-03-09 10:38 UTC
From: secker at careviewcom dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.1 OS: Debian 'Etch', kern 2.6.17-2-486
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: secker at careviewcom dot com
New email:
PHP Version: OS:

 

 [2007-03-08 17:41 UTC] secker at careviewcom dot com
Description:
------------
If I create a Shared memory segment using shm_attach with one user, and set it as readable by all users, but only writable by the owner, then other users cannot open the segment via shm_attach, they get permission denied errors.

I would guess this is maybe because shm_attach can't open a segment as read-only, and always tried to open it as rw?

Reproduce code:
---------------
run as someuser1:

<?php
   $f = ftok('somefile', 'I');
   $sh = shm_attach($f, 1024000, 0644);
?>

works if its not already created by another user...


run as someuser2:

<?php
   $f = ftok('somefile', 'I');
   $sh = shm_attach($f);
?>



Expected result:
----------------
what I would expect is that since I created it as 0644, other users should be able to access it via read-only mode (which I can do if I open it using shmop_open with the read-only flag instead).

Actual result:
--------------
second user gets "Permission Denied" php warning messages.

once again, I think this is mearly a result of shm_attach not actually ever opening an shm as read-only, always read-write... but I might be mistaken. 


Thanks.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-09 10:38 UTC] tony2001@php.net
>$sh = shm_attach($f);

http://php.net/shm_attach
"..and the optional perm-bits perm (default: 0666)..."

>I would guess this is maybe because shm_attach can't open a segment
>as read-only, and always tried to open it as rw?
Exactly.
That's because by default it tries to open it in 0666 mode.
Specify 0644 and voila.. 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 23:01:33 2025 UTC