9.10. Securing Device Special Files

Problem

You want to check for potentially insecure device special files.

Solution

To list all device special files (block or character):

$ find /dir -xdev \( -type b -o -type c \) -ls

To list any regular files in /dev (except the MAKEDEV program):

$ find /dev -type f ! -name MAKEDEV -print

To prohibit device special files on a filesystem, use mount -o nodev or add the nodev option to entries in /etc/fstab.

Be aware of the important options and limitations of find, so you don’t inadvertently overlook important files. [Recipe 9.8]

Discussion

Device special files are objects that allow direct access to devices (either real or virtual) via the filesystem. For the security of your system, you must carefully control this access by maintaining appropriate permissions on these special files. An intruder who hides extra copies of important device special files can use them as backdoors to read—or even modify—kernel memory, disk drives, and other critical devices.

Conventionally, device special files are installed only in the /dev directory, but they can live anywhere in the filesystem, so don’t limit your searches to /dev. Our recipe looks for the two flavors of device special files: block and character (using -type b and -type c, respectively). We use the more verbose -ls (instead of -print) to list the major and minor device numbers for any that are found: these can be compared to the output from ls -l /dev to determine the actual device (the filename is ...

Get Linux Security Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.