Skip to contentSkip to conversation

devfs permissions

DISCUSSION Russell Coker 2 participants 6 messages Feb 24, 2002 – Feb 26, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

I've been thinking about devfs permissions some more.

My initial idea was to totally replace the current kernel code with code in devfsd, however of course that raises the issue of what permissions to use to get the system far enough into the boot process to execute devfsd.

One potential solution to this is to make all devfs nodes have a default SID, and have the policy allow init_t and initrc_t programs full read-write access and devfs_t programs to change SID. Though this seems to be moving the uglyness from device node creation to policy.

Another potential solution is to keep the current method of assigning SIDs to devfs nodes, but use it only for the early stages of boot after which devfsd takes over.

In either case we need to have devfsd manage SIDs on devfs nodes, currently /dev/initctl and /dev/log don't get assigned a SID on devfs (also other pipes and sockets would have the same problem - but aren't as important and don't fail as spectacularly).

For interest I have attached the latest devfs_contexts file I am using. I have attempted to make it give the same result as the file_contexts entries for non-devfs systems as much as possible (but as it doesn't do regular expressions it's impossible to distinguish between CDs and hard drives).

At the moment if you want full functionality on an SE system with devfs you will have to write an init script that runs suitable chsid commands.

Signature · 4 lines
Signatures >4 lines are rude.  If you send email to me or to a mailing list
that I am subscribed to which has >4 lines of legalistic junk at the end
then you are specifically authorizing me to do whatever I wish with the
message (the sig won't be read).

# FLASK

#
# Security contexts for devfs entries.
#
# Each specifications has the form:
# pathname-prefix [ -type ] context
#
# The entry with the longest matching pathname prefix is used.

# / refers to the root directory of the devfs file system, and
# everything is specified relative to this root directory.
# If there is no entry with a matching pathname prefix, then 
# the devfs initial SID is used.
#
# The optional type field specifies the file type as shown in the mode
# field by ls, e.g. use -c to match only character device files, -b
# to match only block device files.
#

/ system_u:object_r:devfs_t
/null system_u:object_r:null_device_t
/zero system_u:object_r:zero_device_t
/console system_u:object_r:console_device_t
/kmem system_u:object_r:memory_device_t
/mem system_u:object_r:memory_device_t
/port system_u:object_r:memory_device_t
/random system_u:object_r:random_device_t
/urandom system_u:object_r:random_device_t
/tty system_u:object_r:devtty_t
/vc -c system_u:object_r:tty_device_t
/pts system_u:object_r:devpts_t
/scsi -c system_u:object_r:fixed_disk_device_t
/scsi -b system_u:object_r:fixed_disk_device_t
/ide -c system_u:object_r:fixed_disk_device_t
/ide -b system_u:object_r:fixed_disk_device_t
/discs -c system_u:object_r:fixed_disk_device_t
/discs -b system_u:object_r:fixed_disk_device_t
/cdroms -c system_u:object_r:removable_device_t
/cdroms -b system_u:object_r:removable_device_t
/floppy -c system_u:object_r:removable_device_t
/floppy -b system_u:object_r:removable_device_t
/rtc system_u:object_r:clock_device_t
/ppp system_u:object_r:net_device_t
/initctl system_u:object_r:initctl_t
/log system_u:object_r:devlog_t
/misc/psaux system_u:object_r:mouse_device_t
/input/mouse system_u:object_r:mouse_device_t
/gpmctl system_u:object_r:gpmctl_t
/ptmx system_u:object_r:ptmx_t
/misc/apm_bios system_u:object_r:apm_bios_t
/sound -c system_u:object_r:sound_device_t

# FLASK

#1 lore raw
Quoted 3 lines · Russell Coker

Another potential solution is to keep the current method of assigning SIDs to devfs nodes, but use it only for the early stages of boot after which devfsd takes over.

I'm inclined toward this approach.

Quoted 4 lines

For interest I have attached the latest devfs_contexts file I am using. I have attempted to make it give the same result as the file_contexts entries for non-devfs systems as much as possible (but as it doesn't do regular expressions it's impossible to distinguish between CDs and hard drives).

Thanks, merged.

--
Stephen D. Smalley, NAI Labs
[email protected]

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
In reply to Russell Coker
Quoted 4 lines · Russell Coker

In either case we need to have devfsd manage SIDs on devfs nodes, currently /dev/initctl and /dev/log don't get assigned a SID on devfs (also other pipes and sockets would have the same problem - but aren't as important and don't fail as spectacularly).

Files created at runtime, such as /dev/initctl and /dev/log, should be labeled based on the file_type_auto_trans() rules that already exist for the appropriate domains. Of course, the current rules assume that the parent directory type is device_t. I see that you changed the / entry in devfs_contexts from device_t to devfs_t. I'm not sure I agree with that change - it will require additional file_type_auto_trans rules for the devfs case. Why not use device_t for both devfs and traditional /dev?

--
Stephen D. Smalley, NAI Labs
[email protected]

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw
Quoted 6 lines · Stephen Smalley
Quoted 4 lines · Russell Coker

In either case we need to have devfsd manage SIDs on devfs nodes, currently /dev/initctl and /dev/log don't get assigned a SID on devfs (also other pipes and sockets would have the same problem - but aren't as important and don't fail as spectacularly).

Quoted 7 lines

Files created at runtime, such as /dev/initctl and /dev/log, should be labeled based on the file_type_auto_trans() rules that already exist for the appropriate domains. Of course, the current rules assume that the parent directory type is device_t. I see that you changed the / entry in devfs_contexts from device_t to devfs_t. I'm not sure I agree with that change - it will require additional file_type_auto_trans rules for the devfs case. Why not use device_t for both devfs and traditional /dev?

At the time it seemed like a good idea to have different permissions for devfs than for a regular directory, one reason for this is that there are system programs which have a genuine need for dynamically running mknod on a non-devfs system (such as LVM, and other systems that do similar things). Also on a non-devfs system an upgrade that installs a new version of the makedev package will generally want to install new device nodes (and sys-admins occasionally remove nodes they don't need or add nodes to match new hardware or drivers). On a devfs system there are only three programs that should create anything under /dev, they are init, the devfsd startup script, and devfsd itself.

Having a different type for /dev on a devfs system is one way of locking things down to prevent mknod from being run. Another way is to change the policy for device_t to prevent these things. I'm still not certain which is the best option.

Signature · 9 lines
Signatures >4 lines are rude.  If you send email to me or to a mailing list
that I am subscribed to which has >4 lines of legalistic junk at the end
then you are specifically authorizing me to do whatever I wish with the
message (the sig won't be read).

--
You have received this message because you are subscribed to the selinux list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw
Quoted 3 lines · Russell Coker

new hardware or drivers). On a devfs system there are only three programs that should create anything under /dev, they are init, the devfsd startup script, and devfsd itself.

So what happens to other programs that try to create sockets in /dev? Are they transparently redirected through devfsd?

Given the behavior you describe, it doesn't sound as though the existing file_type_auto_trans rules for runtime files in /dev would work anyway when using devfs, so perhaps it doesn't matter that you are using devfs_t.

--
Stephen D. Smalley, NAI Labs
[email protected]

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#5 lore raw
Quoted 7 lines · Stephen Smalley
Quoted 3 lines · Russell Coker

new hardware or drivers). On a devfs system there are only three programs that should create anything under /dev, they are init, the devfsd startup script, and devfsd itself.

So what happens to other programs that try to create sockets in /dev? Are they transparently redirected through devfsd?

What other programs are there? The one I've just thought of which I didn't think of before is GPM, is there anything else that's remotely common? Is this common enough that it's painful to create a new rule for every program that needs to do so?

Most such things are probably broken by design anyway.

init has a good excuse because there's not much mounted at the time it starts work, gpm has a partial excuse because it's creating a socket as a replacement for a real mouse device.

Quoted 3 lines

Given the behavior you describe, it doesn't sound as though the existing file_type_auto_trans rules for runtime files in /dev would work anyway when using devfs, so perhaps it doesn't matter that you are using devfs_t.

We'll see. With some of these things it's very difficult to guess what requirements might come up without releasing a beta. I'll write sample policy files according to my ideas, distribute them, and see what feedback I get back. If I discover horrible problems or get a lot of negative feedback then I'll go back to your ideas. ;)

Signature · 9 lines
Signatures >4 lines are rude.  If you send email to me or to a mailing list
that I am subscribed to which has >4 lines of legalistic junk at the end
then you are specifically authorizing me to do whatever I wish with the
message (the sig won't be read).

--
You have received this message because you are subscribed to the selinux list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.