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