1setresuid(2) System Calls Manual setresuid(2)
2
3
4
6 setresuid, setresgid - set real, effective, and saved user or group ID
7
9 Standard C library (libc, -lc)
10
12 #define _GNU_SOURCE /* See feature_test_macros(7) */
13 #include <unistd.h>
14
15 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
16 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
17
19 setresuid() sets the real user ID, the effective user ID, and the saved
20 set-user-ID of the calling process.
21
22 An unprivileged process may change its real UID, effective UID, and
23 saved set-user-ID, each to one of: the current real UID, the current
24 effective UID, or the current saved set-user-ID.
25
26 A privileged process (on Linux, one having the CAP_SETUID capability)
27 may set its real UID, effective UID, and saved set-user-ID to arbitrary
28 values.
29
30 If one of the arguments equals -1, the corresponding value is not
31 changed.
32
33 Regardless of what changes are made to the real UID, effective UID, and
34 saved set-user-ID, the filesystem UID is always set to the same value
35 as the (possibly new) effective UID.
36
37 Completely analogously, setresgid() sets the real GID, effective GID,
38 and saved set-group-ID of the calling process (and always modifies the
39 filesystem GID to be the same as the effective GID), with the same re‐
40 strictions for unprivileged processes.
41
43 On success, zero is returned. On error, -1 is returned, and errno is
44 set to indicate the error.
45
46 Note: there are cases where setresuid() can fail even when the caller
47 is UID 0; it is a grave security error to omit checking for a failure
48 return from setresuid().
49
51 EAGAIN The call would change the caller's real UID (i.e., ruid does not
52 match the caller's real UID), but there was a temporary failure
53 allocating the necessary kernel data structures.
54
55 EAGAIN ruid does not match the caller's real UID and this call would
56 bring the number of processes belonging to the real user ID ruid
57 over the caller's RLIMIT_NPROC resource limit. Since Linux 3.1,
58 this error case no longer occurs (but robust applications should
59 check for this error); see the description of EAGAIN in ex‐
60 ecve(2).
61
62 EINVAL One or more of the target user or group IDs is not valid in this
63 user namespace.
64
65 EPERM The calling process is not privileged (did not have the neces‐
66 sary capability in its user namespace) and tried to change the
67 IDs to values that are not permitted. For setresuid(), the nec‐
68 essary capability is CAP_SETUID; for setresgid(), it is CAP_SET‐
69 GID.
70
72 C library/kernel differences
73 At the kernel level, user IDs and group IDs are a per-thread attribute.
74 However, POSIX requires that all threads in a process share the same
75 credentials. The NPTL threading implementation handles the POSIX re‐
76 quirements by providing wrapper functions for the various system calls
77 that change process UIDs and GIDs. These wrapper functions (including
78 those for setresuid() and setresgid()) employ a signal-based technique
79 to ensure that when one thread changes credentials, all of the other
80 threads in the process also change their credentials. For details, see
81 nptl(7).
82
84 None.
85
87 Linux 2.1.44, glibc 2.3.2. HP-UX, FreeBSD.
88
89 The original Linux setresuid() and setresgid() system calls supported
90 only 16-bit user and group IDs. Subsequently, Linux 2.4 added setre‐
91 suid32() and setresgid32(), supporting 32-bit IDs. The glibc setre‐
92 suid() and setresgid() wrapper functions transparently deal with the
93 variations across kernel versions.
94
96 getresuid(2), getuid(2), setfsgid(2), setfsuid(2), setreuid(2), se‐
97 tuid(2), capabilities(7), credentials(7), user_namespaces(7)
98
99
100
101Linux man-pages 6.04 2023-03-30 setresuid(2)