Changes.old: tfix
[man-pages.git] / man2 / setfsuid.2
blobc6e75dafabeb03bc79ec089d15159a952fcf3d4c
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 (date) "Linux man-pages (unreleased)"
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>
22 .BI "[[deprecated]] 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)).
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 .
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.)
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 STANDARDS
63 Linux.
64 .SH HISTORY
65 Linux 1.2.
66 .\" Linux 1.1.44
67 .\" and in libc since libc 4.7.6.
69 At the time when this system call was introduced, one process
70 could send a signal to another process with the same effective user ID.
71 This meant that if a privileged process changed its effective user ID
72 for the purpose of file permission checking,
73 then it could become vulnerable to receiving signals
74 sent by another (unprivileged) process with the same user ID.
75 The filesystem user ID attribute was thus added to allow a process to
76 change its user ID for the purposes of file permission checking without
77 at the same time becoming vulnerable to receiving unwanted signals.
78 Since Linux 2.0, signal permission handling is different (see
79 .BR kill (2)),
80 with the result that a process can change its effective user ID
81 without being vulnerable to receiving signals from unwanted processes.
82 Thus,
83 .BR setfsuid ()
84 is nowadays unneeded and should be avoided in new applications
85 (likewise for
86 .BR setfsgid (2)).
88 The original Linux
89 .BR setfsuid ()
90 system call supported only 16-bit user IDs.
91 Subsequently, Linux 2.4 added
92 .BR setfsuid32 ()
93 supporting 32-bit IDs.
94 The glibc
95 .BR setfsuid ()
96 wrapper function transparently deals with the variation across kernel versions.
97 .SS C library/kernel differences
98 In glibc 2.15 and earlier,
99 when the wrapper for this system call determines that the argument can't be
100 passed to the kernel without integer truncation (because the kernel
101 is old and does not support 32-bit user IDs),
102 it will return \-1 and set \fIerrno\fP to
103 .B EINVAL
104 without attempting
105 the system call.
106 .SH BUGS
107 No error indications of any kind are returned to the caller,
108 and the fact that both successful and unsuccessful calls return
109 the same value makes it impossible to directly determine
110 whether the call succeeded or failed.
111 Instead, the caller must resort to looking at the return value
112 from a further call such as
113 .I setfsuid(\-1)
114 (which will always fail), in order to determine if a preceding call to
115 .BR setfsuid ()
116 changed the filesystem user ID.
117 At the very
118 least,
119 .B EPERM
120 should be returned when the call fails (because the caller lacks the
121 .B CAP_SETUID
122 capability).
123 .SH SEE ALSO
124 .BR kill (2),
125 .BR setfsgid (2),
126 .BR capabilities (7),
127 .BR credentials (7)