Reputation: 27
Suppose I call shmget
with the following arguments:
int shmid = shmget(KEY, 1024*4096, IPC_CREAT|0644);
and further, suppose that the segment with key KEY
already exists. How do the permission mode bits OR'd into the shmflg
argument (in this case, 0644
) of shmget
affect shmget
's behavior? Does shmget
perform any kind of "permission verification on the permissions of the segment with these permission flags? Specifically what does that verification entail?
Upvotes: 1
Views: 414
Reputation: 180538
How do the permission mode bits OR'd into the
shmflg argument
[...] ofshmget
affectshmget
's behavior?
POSIX is a bit tricky to interpret on this question for the case where there is already a shared-memory segment for the specified key, but the intent seems to be that it operates analogously with open()
. That is, if the process's uid and gid and the requested mode are inconsistent with the segment's uid, gid, and permissions, then the function fails. Specifically,
The
shmget()
function shall fail if: [...] A shared memory identifier exists for key but operation permission as specified by the low-order nine bits ofshmflg
would not be granted [...].
The Linux manpage for shmget()
has similar text, and also specifically says that
If the shared memory segment already exists, the permissions are verified [...].
This is not different from POSIX, just more explicit.
Another section of POSIX gives more details, which boil down to saying that the read / and or write access are granted or denied based on the set of permission bits applicable to the process according to its euid and egid.
Does shmget perform any kind of "permission verification on the permissions of the segment with these permission flags? Specifically what does that verification entail?
Yes, as described above and in the linked POSIX specifications.
It remains a bit unclear to me what "operation permission as specified by the low-order nine bits of shmflg
" are. One could interpret it to mean the permissions the calling process would have on the segment if it were creating it, but I think it really means just that all of the mode bits that are turned on in shmflag
are also on in the segment's permissions field.
Upvotes: 1