Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Multiuser systems allow multiple users with different privileges to share a file system. Each user, in such an environment, must be able to determine which files are shared and which are private, and each user must be able to enforce these decisions.

...

There are a number of file system properties and capabilities that can be exploited by an attacker, including file links, device files, and shared file access.

...

Many operating systems support file links, including symbolic (soft) links, hard links, short cuts, shadows, aliases, and junctions. Symbolic links can be created in POSIX using the ln -s command , and hard links using the ln command. Hard links are indistinguishable from normal files on POSIX systems.

...

Wiki Markup
On many systems, filefiles can be be simultaneously accessed by concurrent processes.  Exclusive access grants unrestricted file access to the locking process while denying access to all other processes, eliminating the potential for a race condition on the locked region. The {{java.nio.channels.FileLock}} class facilitates file locking. According to the Java API \[[API 2006|AA. Bibliography#API 06]\] documentation,

A file lock is either exclusive or shared. A shared lock prevents other concurrently-running programs from acquiring an overlapping exclusive lock, but does allow them to acquire overlapping shared locks. An exclusive lock prevents other programs from acquiring an overlapping lock of either type. Once it is released, a lock has no further effect on the locks that may be acquired by other programs.

...

Linux implements both mandatory locks and advisory locks. Advisory locks are not enforced by the operating system, which diminishes their value from a security perspective. Unfortunately, the mandatory file lock in Linux is generally impractical because:

  • Mandatory locking is only supported by certain network file systems.
  • File systems must be mounted with support for mandatory locking, and this is disabled by default.
  • Locking relies on the group ID bit, which can be turned off by another process (thereby defeating the lock).
  • The lock is implicitly dropped if the holding process closes any descriptor of the file.

...

This noncompliant code example performs necessary checks and then opens the file. After opening the file, it performs a second check to make sure that the file has not been moved , and that the file it opened is the same one it checked. This reduces the chance that an attacker has changed the file between checking and opening the file. In both checks, the file's fileKey attribute is examined. This serves as a unique key for identifying files , and is a more reliable indicator of a file's identity than its path name.

...

  • A TOCTOU race condition exists between the first check and open. During this race window, an attacker can replace the regular file with a symbolic link or other non-regular file. The second check detects this race condition but does not eliminate it; an attacker can still cause the system to block when opening the file.
  • An attacker could subvert this code by letting the check operate on a normal file, substituting the non-normal file for the open, and then resubstitute resubstituting the normal file to circumvent the second check. This vulnerability exists because Java lacks any mechanism to obtain file attributes from a file by any means other than the file name, and the binding of the file name to a file object is reasserted every time the file name is used in an operation. Consequently, an attacker can still switch out a file for a nefarious file, such as a symbolic link.
  • A system with hard links allows an attacker to construct a malicious file that is a hard link to a sensitive file. Hard links cannot be reliably detected by a program , and serve as a foil to canonicalization attempts, which are prescribed by IDS02-J. Canonicalize path names before validating them.

...

Because of the potential for race conditions , and the inherent accessibility of shared directories, files must only be operated upon in secure directories. Because programs may run with reduced privileges and lack the facilities to construct a secure directory, a program may need to throw an exception if it can determine that a given path name is not in a secure directory.

...

This compliant solution uses the isInSecureDir() method to ensure that an attacker can not cannot tamper with the file to be opened and subsequently removed. Note that once the path name of a directory has been checked using isInSecureDir(), all further file operations on that directory must be performed using the same path.

...

Programs with elevated privileges may need to write files to directories owned by unprivileged users. One example would be a mail daemon that reads a mail message from one user , and places it in a directory owned by another user. In such cases, the proper course of action is to assume the privileges of a user when reading or writing files on behalf of that user, in which case all file access should occur in secure directories relative to that user. If a program with elevated privileges must write files on it's its own behalf, then these files should be in secure directories relative to the privileges of the program (such as directories accessible only by the superuser).

...

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9626c572781ab619-a2ef83b0-4e25445b-88c4b7c3-8868596936377e802325b749"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

Class File, methods createTempFile, delete, deleteOnExit

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b6d7315fbff7377c-2b36fdc9-48a84b13-a314b3ff-c67d67ea742cfdf936cf8f7f"><ac:plain-text-body><![CDATA[

[[CVE 2008

AA. Bibliography#CVE 08]]

[CVE-2008-5354

http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5354]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ef8b31b1799703c7-d88e1306-405441f1-aeef94a7-74ebf7184bea7c8a6f01b7b0"><ac:plain-text-body><![CDATA[

[[Darwin 2004

AA. Bibliography#Darwin 04]]

11.5 Creating a Transient File

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e3ab2b744313b220-1f84361d-4a1c43c8-83a39cc2-27b2db56e1f075d685124f69"><ac:plain-text-body><![CDATA[

[[Garfinkel 1996

AA. Bibliography#Garfinkel 96]]

Section 5.6, "Device Files"

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="41d2659890256199-17f3cdf4-4d18444c-85f2b1b0-dda819efed0d6d2e992178a8"><ac:plain-text-body><![CDATA[

[[Howard 2002

AA. Bibliography#Howard 02]]

Chapter 11, "Canonical Representation Issues"

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="97f985de86461bfd-16d5d9ab-408f455b-9dc7be78-2b1922f6e920c9f41cd8df6d"><ac:plain-text-body><![CDATA[

[[J2SE 2011

AA. Bibliography#J2SE 11]]

The try-with-resources Statement

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="70136d43cb73e11c-112e2e7b-4faa452b-98a382a1-768091f05d7b9cd49f90bd77"><ac:plain-text-body><![CDATA[

[[Open Group 2004

AA. Bibliography#Open Group 04]]

[open()

http://www.opengroup.org/onlinepubs/009695399/functions/open.html]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6df971304b5f1b38-45c409c3-4ff44c5f-a294a011-aaa2ea0326ff019012474070"><ac:plain-text-body><![CDATA[

[[SDN 2008

AA. Bibliography#SDN 08]]

Bug IDs: 4171239, 4405521, 4635827, 4631820

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="67bf74d48000d181-c91f0578-48124bbc-b5cda2ef-203811a3242d9c21fb0149d5"><ac:plain-text-body><![CDATA[

[[Secunia 2008

AA. Bibliography#Secunia 08]]

[Secunia Advisory 20132

http://secunia.com/advisories/20132/]

]]></ac:plain-text-body></ac:structured-macro>

...