Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set*id() syscalls' return values not checked #394

Open
jeffbencteux opened this issue Jul 24, 2023 · 0 comments
Open

set*id() syscalls' return values not checked #394

jeffbencteux opened this issue Jul 24, 2023 · 0 comments

Comments

@jeffbencteux
Copy link

Instances of set*id() functions' return values are not checked in the project source code:

set*id() functions are widely used in SUID/SGID binaries to drop privileges. Below is an example with setuid():

setuid(getuid())

If the above call is successful, then the effective UID of the process would have the value of the real UID, hence "cancelling" the SUID bits given to the binary.

Return value of this call from the man states that there exists security issues when that value is not checked:

RETURN VALUE

  On success, zero is returned.  On error, -1 is returned, and
  _[errno](https://man7.org/linux/man-pages/man3/errno.3.html)_ is set to indicate the error.
  
  _Note_: there are cases where **setuid**() can fail even when the
  caller is UID 0; it is a grave security error to omit checking
  for a failure return from **setuid**().

If the previous setuid() call fails and its return value is not checked, a SUID binary doing such a call would then end up not dropping its privileges while believing it did, allowing for potential privilege escalations in the rest of the execution.

I suggest checking the return values of the set*id() function in a manner like the following:

if (setuid(getuid()) == -1)
{
	// error handling
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant