Debian Codegraph @

upstream/debian-unstable/man2/setfsuid.2

raw
1 .\" Copyright 1995, Thomas K. Dyas <[email protected]>
2 .\" Copyright 2013-2019, Michael Kerrisk <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH setfsuid 2 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 setfsuid \- set user identity used for filesystem checks
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <sys/fsuid.h>
16 .P
17 .BI "[[deprecated]] int setfsuid(uid_t " fsuid );
18 .fi
19 .SH DESCRIPTION
20 On Linux, a process has both a filesystem user ID and an effective user ID.
21 The (Linux-specific) filesystem user ID is used
22 for permissions checking when accessing filesystem objects,
23 while the effective user ID is used for various other kinds
24 of permissions checks (see
25 .BR credentials (7)).
26 .P
27 Normally, the value of the process's filesystem user ID
28 is the same as the value of its effective user ID.
29 This is so, because whenever a process's effective user ID is changed,
30 the kernel also changes the filesystem user ID to be the same as
31 the new value of the effective user ID.
32 A process can cause the value of its filesystem user ID to diverge
33 from its effective user ID by using
34 .BR setfsuid ()
35 to change its filesystem user ID to the value given in
36 .IR fsuid .
37 .P
38 Explicit calls to
39 .BR setfsuid ()
40 and
41 .BR setfsgid (2)
42 are (were) usually used only by programs such as the Linux NFS server that
43 need to change what user and group ID is used for file access without a
44 corresponding change in the real and effective user and group IDs.
45 A change in the normal user IDs for a program such as the NFS server
46 is (was) a security hole that can expose it to unwanted signals.
47 (However,
48 this issue is historical;
49 see below.)
50 .P
51 .BR setfsuid ()
52 will succeed only if the caller is the superuser or if
53 .I fsuid
54 matches either the caller's real user ID, effective user ID,
55 saved set-user-ID, or current filesystem user ID.
56 .SH RETURN VALUE
57 On both success and failure,
58 this call returns the previous filesystem user ID of the caller.
59 .SH STANDARDS
60 Linux.
61 .SH HISTORY
62 Linux 1.2.
63 .\" Linux 1.1.44
64 .\" and in libc since libc 4.7.6.
65 .P
66 At the time when this system call was introduced, one process
67 could send a signal to another process with the same effective user ID.
68 This meant that if a privileged process changed its effective user ID
69 for the purpose of file permission checking,
70 then it could become vulnerable to receiving signals
71 sent by another (unprivileged) process with the same user ID.
72 The filesystem user ID attribute was thus added to allow a process to
73 change its user ID for the purposes of file permission checking without
74 at the same time becoming vulnerable to receiving unwanted signals.
75 Since Linux 2.0, signal permission handling is different (see
76 .BR kill (2)),
77 with the result that a process can change its effective user ID
78 without being vulnerable to receiving signals from unwanted processes.
79 Thus,
80 .BR setfsuid ()
81 is nowadays unneeded and should be avoided in new applications
82 (likewise for
83 .BR setfsgid (2)).
84 .P
85 The original Linux
86 .BR setfsuid ()
87 system call supported only 16-bit user IDs.
88 Subsequently, Linux 2.4 added
89 .BR setfsuid32 ()
90 supporting 32-bit IDs.
91 The glibc
92 .BR setfsuid ()
93 wrapper function transparently deals with the variation across kernel versions.
94 .SS C library/kernel differences
95 In glibc 2.15 and earlier,
96 when the wrapper for this system call determines that the argument can't be
97 passed to the kernel without integer truncation (because the kernel
98 is old and does not support 32-bit user IDs),
99 it will return \-1 and set
100 .I errno
101 to
102 .B EINVAL
103 without attempting
104 the system call.
105 .SH BUGS
106 No error indications of any kind are returned to the caller,
107 and the fact that both successful and unsuccessful calls return
108 the same value makes it impossible to directly determine
109 whether the call succeeded or failed.
110 Instead, the caller must resort to looking at the return value
111 from a further call such as
112 .I setfsuid(\-1)
113 (which will always fail), in order to determine if a preceding call to
114 .BR setfsuid ()
115 changed the filesystem user ID.
116 At the very
117 least,
118 .B EPERM
119 should be returned when the call fails (because the caller lacks the
120 .B CAP_SETUID
121 capability).
122 .SH SEE ALSO
123 .BR kill (2),
124 .BR setfsgid (2),
125 .BR capabilities (7),
126 .BR credentials (7)