Behavioral Characteristics and Permission Design of Linux Special Permissions (SUID, SGID, Sticky Bit)

Summarizes the kernel-level behavior of SUID, SGID, and Sticky Bit, the differences between uppercase and lowercase notation, security auditing methods using the find command, and practical steps for privilege escalation mitigation using nosuid mounts.

In multi-tenant environments or Linux infrastructures where multiple processes operate collaboratively, standard POSIX access controls (read, write, and execute permissions for owner, group, and others) are sometimes insufficient to meet operational requirements. Examples include requirements to allow unprivileged users to change their own passwords while maintaining the security of the privileged configuration file (/etc/shadow), to unify group ownership of artifacts created by multiple engineers in a shared directory, or to prevent unauthorized deletion or tampering of others’ files in a shared workspace such as /tmp.

To meet these demands, the Linux kernel implements “Special Permissions” above the standard access permission bits. However, misconfigured special permissions can become a major privilege escalation attack vector, making it essential to precisely understand their detailed runtime behavior and auditing techniques.

Architecture and Execution Context of Special Permissions

Special permissions in the Linux file system consist of the following three bits:

1. Set User ID (SUID) — Octal Bit: 4000

When a user executes an executable binary with the SUID bit set, the effective user ID (EUID) of the process temporarily switches from the executing user to the “owner of the binary (typically root)”.

A primary example is /usr/bin/passwd. The /etc/shadow file, which stores password hashes for unprivileged users, normally has permissions set to 0000 or 0600 (owned by root), preventing direct viewing or modification by unprivileged users. Because SUID is set on /usr/bin/passwd, it runs with root privileges only during execution, enabling file updates.

2. Set Group ID (SGID) — Octal Bit: 2000

SGID behaves differently for files and directories.

  • For executable files: Regardless of the primary group of the executing user, the effective group ID (EGID) of the process switches to the “owning group of the file”.
  • For directories: All new files and subdirectories created within that directory automatically inherit the “owning group of the parent directory” rather than the primary group of the creator. This configuration is essential when setting up shared directories for development teams, etc.

3. Sticky Bit — Octal Bit: 1000

A special permission configured on directories. In a directory with the Sticky Bit enabled, even if the directory permissions are set to 777 (world-writable), deletion and renaming of files are restricted exclusively to the “owner of the file” or the “root superuser”. It is applied to the /tmp directory where an unspecified number of users or services write temporary files.

Interpretation of Permission Notation (s/S and t/T)

In ls -l output, special permissions are displayed in the position of the execute permission bits. The case of the characters displayed here indicates the presence or absence of the underlying standard execute permission (x).

NotationPermission TypeStandard Execute Permission (x) StatusSystem Behavior Interpretation
rwsSUID / SGIDEnabledStandard state where SUID/SGID functions normally
rwSSUID / SGIDDisabledInconsistent state where special permission is set but execute permission is missing
rwtSticky BitEnabledStandard state where Sticky Bit functions normally
rwTSticky BitDisabledState where Sticky Bit is set but execute permission for Others is missing

If an uppercase S or T is displayed, there is a high probability that consistency between the intended permission settings and the execution flags is broken, requiring a review of the configuration.

Configuration Procedure: Numeric (Octal) and Symbolic Notation

The chmod command is used to grant or revoke special permissions.

Configuration via Octal Mode

Specify a 4-digit number where the sum of the special permission values is prepended to the standard 3-digit permission.

# Set SUID (4000 + 0755 = 4755)
chmod 4755 /usr/local/bin/custom-exec

# Set SGID (2000 + 0775 = 2775)
chmod 2775 /shared/devteam

# Set Sticky Bit (1000 + 0777 = 1777)
chmod 1777 /tmp/scratch

# Completely remove special permissions (set leading digit to 0)
chmod 0755 /usr/local/bin/custom-exec

Configuration via Symbolic Mode

Specify the s or t flag for the target (u: owner, g: group, o: others).

# Adding and removing SUID
chmod u+s /usr/local/bin/custom-exec
chmod u-s /usr/local/bin/custom-exec

# Adding and removing SGID
chmod g+s /shared/devteam
chmod g-s /shared/devteam

# Adding and removing the Sticky Bit
chmod o+t /tmp/scratch
chmod o-t /tmp/scratch

System Auditing and Search Pipeline

To mitigate the risk of privilege escalation attacks, security audits require periodic detection of unnecessary SUID/SGID files. Audit the entire file system using the find command.

# Comprehensive search for SUID binaries
find / -perm -4000 -type f 2>/dev/null

# Search for SGID binaries and files
find / -perm -2000 -type f 2>/dev/null

# Search for directories with the Sticky Bit set
find / -perm -1000 -type d 2>/dev/null

# Search for files with either SUID or SGID set (4000 + 2000 = 6000)
find / -perm -6000 -type f 2>/dev/null

-perm -4000 evaluates whether all specified bits are set. To prevent permission errors from cluttering the screen, standard error is redirected to /dev/null.

Troubleshooting

1. “Permission denied” and Uppercase S Notation When Executing SUID Binary

Symptom: When an unprivileged user attempts to execute a binary with SUID set, execution fails with bash: ./binary: Permission denied. Checking ls -l reveals an uppercase S displayed, such as -rwSr-xr-x.

Cause: SUID (u+s or 4xxx) was configured without granting execute permission (x) to the file owner, causing the kernel to reject execution.

Resolution Workflow: Granting execute permission changes the notation to a lowercase s, allowing execution to succeed.

chmod u+x /path/to/binary

2. Group Ownership Inconsistency in Shared Directories

Symptom: In a directory co-edited by multiple users, new files created by a specific user inherit that user’s primary group, preventing other members from editing them.

Cause: If SGID is not set on the target directory, the group of created files defaults to the creator’s primary group.

Resolution Workflow: Change the target directory’s group ownership to the shared group, then set SGID.

chown -R :sharedgroup /shared/workspace
chmod 2775 /shared/workspace

3. Structural Elimination of Privilege Escalation Risks via SUID (nosuid)

Symptom / Problem: If a malicious SUID binary is placed in shared storage (NFS) or user-writable locations (/tmp, /home), it can serve as a foothold for local privilege escalation.

Resolution Workflow: Explicitly specify nosuid in mount options. This disables kernel-level interpretation of SUID and SGID bits on the corresponding file system.

/etc/fstab configuration example:

UUID=xxxx-xxxx /home ext4 defaults,nosuid,nodev 0 2
UUID=yyyy-yyyy /tmp  ext4 defaults,nosuid,noexec,nodev 0 2

Verification Procedure and Execution Logs

Verification logs for permission states and file system behavior after configuration.

# Check SUID binary
$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 68248 Mar 23  2024 /usr/bin/passwd

# Check Sticky Bit directory
$ ls -ld /tmp
drwxrwxrwt 15 root root 4096 Nov 25 10:00 /tmp

# Example of extracting system files with SUID set
$ find /usr/bin -perm -4000 -type f 2>/dev/null
/usr/bin/chfn
/usr/bin/chsh
/usr/bin/passwd
/usr/bin/newgrp
/usr/bin/sudo
/usr/bin/su

# Check nosuid mount status
$ mount | grep nosuid
/dev/nvme0n1p3 on /home type ext4 (rw,nosuid,nodev,relatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev)

Operational Notes

  1. Principle of Least Privilege: Avoid granting SUID to custom scripts or binaries whenever possible. Consider controlling command execution via sudo or granting fine-grained privileges using Linux capabilities (setcap).
  2. Disabling on Scripts: In standard Linux distributions, the SUID bit on shell scripts or interpreted language scripts is ignored at the kernel level for security reasons (mitigating environment variable injection and race conditions).
  3. Periodic Consistency Scanning: On production hosts, it is recommended to maintain a configuration that periodically collects search logs via CI/CD pipelines or monitoring agents to verify that SUID/SGID bits are not assigned to unexpected files.
Built with Hugo
Theme Stack designed by Jimmy
Privacy Policy Disclaimer Contact