Ensure SUID and SGID files are reviewed
suid-sgid-files-reviewed · RHEL ≥ 8 · 1 impl
Description
SUID and SGID files must be limited to a reviewed, legitimate set. Two things are checked. No such file may be world-writable or sit in a user-writable directory (/tmp, /var/tmp, /home, /dev/shm), which is an unambiguous privilege-escalation risk on any host. And the full inventory must match the baseline the site declared in suid_sgid_baseline, because which of these binaries a system needs is a statement about that system.
Rationale
A SUID or SGID binary runs with privileges its caller does not have, so the set of them is the local privilege-escalation surface. The world-writable case is wrong everywhere and needs no site input. The rest cannot be judged without one: a host legitimately carries fifteen to twenty of these, and which ones is a property of what the host does. Comparing the inventory against a declared baseline is what turns "review these periodically" into something that fails when a new one appears. A package list would be the obvious alternative and is a bad one. A base install carries over six hundred packages and the set changes on every patch, so a declared list is stale within a cycle and produces failures nobody reads. The SUID inventory is around twenty entries and barely moves, which is what makes a baseline worth keeping accurate.
Check → Remediate
- 1. command:
- run=# Unambiguous findings: SUID/SGID files that are world-writable or # sit in a user-writable directory. True everywhere, no site input. risky=$(find / -xdev -type f \( -perm -4000 -o -perm -2000 \) \ \( -perm -0002 -o -path '/tmp/*' -o -path '/var/tmp/*' \ -o -path '/home/*' -o -path '/dev/shm/*' \) 2>/dev/null | head -5) if [ -n "$risky" ]; then echo "FAIL: SUID/SGID files world-writable or in user-writable paths:"; echo "$risky"; exit 1 fi echo "OK: no world-writable or user-path SUID/SGID files" expected_exit=0
- 2. set_compare:
- observed_command=find /usr/bin /usr/sbin /bin /sbin -xdev -type f \( -perm -4000 -o -perm -2000 \) 2>/dev/null | sort authorized={{ suid_sgid_baseline }}
- note:
- For a world-writable or user-path finding, remove the SUID/SGID bit or move the file; that case is wrong regardless of the baseline. For a file reported as not in the baseline, decide which side is wrong: drop the bit with chmod u-s (or g-s) if the binary does not need it, or add the path to suid_sgid_baseline if it does. Kensa does not clear the bit automatically, because removing it from something like sudo or su locks the host's own administrators out.
Framework references
CIS
NIST 800-53
NIST 800-171
CMMC Level 2