1.1.2.1.1 Ensure /tmp is a separate partition

Information

The /tmp directory is a world-writable directory used for temporary storage by all users and some applications.

/tmp can be configured to use tmpfs.

tmpfs puts everything into the kernel internal caches and grows and shrinks to accommodate the files it contains and is able to swap unneeded pages out to swap space. It has maximum size limits which can be adjusted on the fly via mount -o remount.

Since tmpfs lives completely in the page cache and on swap, all tmpfs pages will be shown as "Shared" in free . Notice that these counters also include shared memory. The most reliable way to get the count is using df and du.

tmpfs has two mount options for sizing:

- size : Specifies the total file system size in bytes. If zero (the default) or a value larger than SIZE_MAX - PAGE_SIZE is given, the available amount of memory (including main memory and swap space) will be used.
- inodes : Specifies the maximum number of nodes available to the file system. If not specified, the file system chooses a reasonable maximum based on the file system size, which can be limited with the size option.

These parameters accept a suffix k, m, g, t, or p, which denote byte, kilobyte, megabyte, gigabyte, terabyte and petabyte respectively and can be changed on remount.

Making /tmp its own file system allows an administrator to set additional mount options such as the noexec option on the mount, making /tmp useless for an attacker to install executable code. It would also prevent an attacker from establishing a hard link to a system setuid program and wait for it to be updated. Once the program was updated, the hard link would be broken and attackers would have their own copy of the program. If the program happened to have a security vulnerability, the attackers could continue to exploit the known flaw.

This can be accomplished by either mounting tmpfs to /tmp, or creating a separate partition for /tmp.

Solution

-If- tmpfs is being used First ensure that system will create a tmpfs file system at startup.

# sysrc tmpmfs="YES"
# sysrc tmpsize="2g"

For specific configuration requirements of the /tmp mount for your environment, modify /etc/fstab rather than utilizing sysrc.

Example of using tmpfs with specific mount options:

tmpfs /tmp tmpfs rw,nosuid,noatime,size=2g 0 0

Note: the size=2g is an example of setting a specific size for tmpfs.

Example of using a volume or disk with specific mount options. The source location of the volume or disk will vary depending on your environment:

<device> /tmp <fstype> rw,nosuid,noatime 0 0

Impact:

By design files saved to /tmp should have no expectation of surviving a reboot of the system. tmpfs is ram based and all files stored to tmpfs will be lost when the system is rebooted.

If files need to be persistent through a reboot, they should be saved to /var/tmp not /tmp.

Since the /tmp directory is intended to be world-writable, there is a risk of resource exhaustion if it is not bound to tmpfs or a separate partition.

Running out of /tmp space is a problem regardless of what kind of filesystem lies under it, but in a configuration where /tmp is not a separate file system it will essentially have the whole disk available, as the default installation only creates a single / partition. On the other hand, a RAM-based /tmp (as with tmpfs ) will almost certainly be much smaller, which can lead to applications filling up the filesystem much more easily. Another alternative is to create a dedicated partition for /tmp from a separate volume or disk. One of the downsides of a disk-based dedicated partition is that it will be slower than tmpfs which is RAM-based.

See Also

https://workbench.cisecurity.org/benchmarks/19044

Item Details

Category: CONFIGURATION MANAGEMENT

References: 800-53|CM-6, 800-53|CM-7, CSCv7|9.2

Plugin: Unix

Control ID: 9d3841c2fbd1795fb3ba4bc0aa22e9a5cdc40f9f1d35a9f504704cc3f5a20b3e