Skip to content

Incorrect Order of setuid and setgid Calls

Description

A compromised process might be able to regain elevated group privileges if set(e)gid() is called after set(e)uid(). This can occur when privileges are temporarily dropped with seteuid() and then setuid() or seteuid() are called while under an unprivileged user.

Examples

Insecure Code

c
setuid(getuid());
setgid(getgid());

Secure Code

c
setgid(getgid());
setuid(getuid());

Remediation

Ensure that set(e)gid() is called before set(e)uid() to prevent a compromised process from regaining elevated group privileges.

Rule Details

FieldValue
IDCODE-0473
CategoryAccessControl
SeverityHIGH
CWECWE-696
ConfidenceMEDIUM
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsprivilege escalation, setuid, setgid
OWASPN/A

References