CWE-274, Improper Handling of Insufficient Privileges, covers a product that does not handle, or mishandles, the case where it lacks the privileges to do an operation. The result is a secondary weakness somewhere else in the program.
Anyone who writes code that touches files, sockets, processes, or system calls can hit it.
How it happens
Developers write for the case where the call succeeds. When an operation fails with a permission error, the code often continues anyway, swallows the error, or falls into a path nobody tested.
MITRE's observed examples show the range. In CVE-2001-1564 (Gold), system limits are not properly enforced after privileges are dropped. In CVE-2005-3286 (Gold), a firewall crashes when it cannot read a critical memory block that a malicious process had protected.
// Vulnerable pattern: error ignored, program carries on
int fd = open("/etc/app/limits.conf", O_RDONLY);
// fd may be -1 here, and the code uses it anyway
read(fd, buf, sizeof(buf));
What an attacker gains
MITRE lists the consequence as an altered execution logic. The attacker does not need to be the one with privileges. Denying the program a permission can steer it into a failure path that skips a check or crashes a security service.
How to find it
- Search for calls to privileged operations whose return values are not checked.
- Review error handlers for catch blocks that do nothing.
- Static analysis can find some instances by examining source code.
- Test by running the program as a low privilege user and as a user with files made unreadable.
How to fix it
int fd = open("/etc/app/limits.conf", O_RDONLY);
if (fd < 0) {
perror("cannot read limits");
exit(EXIT_FAILURE); // fail closed
}
Check every result, decide on a safe default, and fail closed when a security relevant operation cannot complete.
Quick check
Why is failing closed the safer default?
If a privileged operation fails and the program continues, it may run without the protection that operation was meant to provide. Stopping or denying access keeps the failure from becoming an exposure.
Sources
- MITRE CWE-274: https://cwe.mitre.org/data/definitions/274.html
- Safeguard Gold entry: https://gold.safeguard.sh/cwe/CWE-274