Skip to contentSkip to conversation

USB device labelling

DISCUSSION Russell Coker 2 participants 2 messages Feb 9, 2002 – Feb 11, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

I have been talking with Brad Hards regarding SE Linux device labelling for USB devices.

A file system of type usbdevfs is mounted somewhere suitable (usually /proc/bus/usb - many programs won't work if you mount elsewhere). Here are an example of the files in this file system:
./devices
./drivers
./001
./001/001

The ./devices and ./drivers files always exist and should probably be of system_u:object_r:sysctl_t.

The directory ./001 represents the USB controller hardware in my computer, the file ./001/001 is a USB device attached to the USB controller (which happens to be a USB hub). When I plug a USB device (EG a mouse) into this hub then a new file ./001/002 will be created.

We want to change the security context BEFORE a user-space program can get access to the file.

Firstly we want HID type devices (Human Interface - keyboard, mouse, and UPS) to have very restrictive permissions because they also get device nodes which can be assigned permissions through "make relabel" or through devfs depending on whether you use devfs or not.

Setting the rest of the files is more difficult.

One way of doing this would make all files default to restrictive permissions and then allow /sbin/hotplug to change them back to more usable permissions. /sbin/hotplug is run every time a device node is installed anyway, giving it permission to relabel files from usb_unlabeled_t to something else and changing it's code so it knows how to do so.

Another way of doing it would be to have the kernel assign the permissions. When you compile a kernel with USB device drivers as modules the depmod program will build a map file of device IDs to device driver names. We could then have a configuration file specifying a match between device driver names and security contexts. Then checkpolicy can take this file as well as a copy of modules.usbmap (NOT the one on the running kernel - the running kernel may have the USB device drivers statically linked not as modules) as part of it's input towards generating policy.conf.

What do you think?

Signature · 9 lines
http://www.coker.com.au/bonnie++/     Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/       Postal SMTP/POP benchmark
http://www.coker.com.au/projects.html Projects I am working on
http://www.coker.com.au/~russell/     My home page

--
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.
#1 lore raw
Quoted 2 lines · Russell Coker

The ./devices and ./drivers files always exist and should probably be of system_u:object_r:sysctl_t.

If these files are merely exporting system information that should be generally readable, then we might want to use the system_u:object_r:proc_t security context.

Quoted 4 lines

The directory ./001 represents the USB controller hardware in my computer, the file ./001/001 is a USB device attached to the USB controller (which happens to be a USB hub). When I plug a USB device (EG a mouse) into this hub then a new file ./001/002 will be created.

Is there any reason to restrict access to the directory, or should it be generally readable/searchable? Are the files in this directory actually device special files that permit read/write access to the device, or are they something else? How do they differ from entries in /dev or devfs?

Quoted 5 lines

One way of doing this would make all files default to restrictive permissions and then allow /sbin/hotplug to change them back to more usable permissions. /sbin/hotplug is run every time a device node is installed anyway, giving it permission to relabel files from usb_unlabeled_t to something else and changing it's code so it knows how to do so.

The kernel support for this approach would be very straightforward. We would simply define an initial SID for this purpose and specify a context for it in the initial_sid_contexts file. Every usbdevfs device node could then be assigned this SID, and we can grant the appropriate permissions to kmod_t for hotplug to relabel from this SID.

--
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.