Permissions Issue

The place for general PHP questions and hints for PHP on IBM i
Post Reply
art5009
Posts: 3
Joined: Mon Mar 02, 2015 2:38 am

Permissions Issue

Post by art5009 » Mon Mar 02, 2015 2:46 am

I have a php loadable module that allows a memory pointer to be passed to a php application that is a string with a bunch of system information. Basically, it does

open(/dev/kmem)
p=mmap()
return p

this all works fine in Freebsd 9.1 and php 5.3.x, but with freebsd 10 and php 5.4.38 it only works when kmem is opened read_only. I "was" able to open in RDWR mode on the older system.

My question is, is it PHP or FreeBSD that's causing the open to fail (EPERM is returned). What's baffling is that I can open /dev/kmem from a php program RDWR, but it fails within the module.

I don't really need RDWR at the moment, but I'd like to know what is different. Its a nifty way to pass info to an app quickly without dealing with setting up shared memory.

TIA

Art

mark397
Posts: 87
Joined: Thu May 30, 2013 6:12 pm

Re: Permissions Issue

Post by mark397 » Mon Mar 02, 2015 5:15 pm

I believe it shouldn't have worked before (at least without modifying file permissions). You'll need to check the file permissions of /dev/kmem, which should be root. On my local Linux install I have not touched permissions on it, and the file attributes are as follows:

Code: Select all

mark@mark:~> ls -l /dev/kmem
crw-r----- 1 root kmem 1, 2 Feb  2 12:04 /dev/kmem
If my apache instance running under the user wwwrun tries to access it there will be read only permissions if the wwwrun user is a member of the kmem group, and no permissions if it is not. My suggestion if you have this setup is to add the apache instance's user to the kmem group and add the write permission for the group level using chmod 660.

art5009
Posts: 3
Joined: Mon Mar 02, 2015 2:38 am

Re: Permissions Issue

Post by art5009 » Tue Mar 03, 2015 12:51 am

The error is EPERM, not EACCESS. /dev/kmem is owned by daemon. It's not on public web servers so security isn't too much of a concern.

as mentioned:

$fp = fopen('/dev/kmem',"w");

works fine in PHP; it behaves differently within an extension module. It's not file permissions; *someone* has decided not to allow the operation; I'll have to run 5.4 on my 9.1 system to see if it's php or FreeBSD 10. I was hoping to avoid another lost half day.

art5009
Posts: 3
Joined: Mon Mar 02, 2015 2:38 am

Re: Permissions Issue

Post by art5009 » Tue Mar 03, 2015 3:21 am

It looks like a FreeBSD 10 issue. No problem running v5.4.38 on FBSD 9

Post Reply