Re: capable open_port() check wrong for kmem

From: Chris Wright (
Date: Wed Dec 11 2002 - 19:43:48 EST

* carbonated beverage ( wrote:
> It's rather annoying and counter-intuitive to have:
> crw-r----- 1 root kmem 1, 2 Sep 8 21:56 /dev/kmem
> but to have the following code fragment give:
> int fd;
> fd = open("/dev/kmem", O_RDONLY);
> if(fd == -1) {
> fprintf(stderr, "Can't open /dev/kmem: %s\n", strerror(errno));
> }
> Can't open /dev/kmem: Operation not permitted
> with a user in the kmem group.
> Also, the utility I'm writing doesn't need write access, so why give it to
> the process in the first place?

Then open O_RDONLY (with CAP_SYS_RAWIO). Then the utility won't have
write access. If that's all you are worried about.


If you have only one capability (CAP_SYS_RAWIO), you are not owner of
/dev/kmem, you are in group kmem, and /dev/kmem is 0640, then all you will
get is read-only access to /dev/kmem. This does not require kernel changes.


Linux Security Modules
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Sun Dec 15 2002 - 22:00:23 EST