Skip to content

add support for setreuid/setregid and exculde a false positive #18

@9iang22

Description

@9iang22

I found that the following case will be reported by raptor-incorrect-order-setuid-setgid, the root cause is that the rule only has a whitelist for the pattern to recover the root privilege with seteuid(0).

void temp_priv_drop_safe()
{
	uid_t saved_uid;
	struct passwd *pwd;

	// ok: raptor-incorrect-order-setuid-setgid
	saved_uid = geteuid();
	pwd = getpwnam("nobody");
	if (pwd != NULL) {
		(void)seteuid(pwd->pw_uid);
		/* do unprivileged work */
		FILE *fp = fopen("/tmp/unpriv_file.txt", "r");
		if (fp) fclose(fp);
		/* restore original privileges */
		(void)seteuid(saved_uid);
	}
}

The following pattern will help:

          - pattern-not-inside: |
              $UID = geteuid();
              ...
              <... seteuid($UID) ...>;

Also, the rule now does not support the setreuid/setregid order reverse.

I'd like to open a pr for these if you think they should be improved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions