]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/setfsuid.2
_syscall.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres...
[thirdparty/man-pages.git] / man2 / setfsuid.2
1 .\" Copyright (C) 1995, Thomas K. Dyas <tdyas@eden.rutgers.edu>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Created 1995-08-06 Thomas K. Dyas <tdyas@eden.rutgers.edu>
26 .\" Modified 2000-07-01 aeb
27 .\" Modified 2002-07-23 aeb
28 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Added notes on capability requirements
30 .\"
31 .TH SETFSUID 2 2016-07-17 "Linux" "Linux Programmer's Manual"
32 .SH NAME
33 setfsuid \- set user identity used for filesystem checks
34 .SH SYNOPSIS
35 .B #include <sys/fsuid.h>
36 .PP
37 .BI "int setfsuid(uid_t " fsuid );
38 .SH DESCRIPTION
39 The system call
40 .BR setfsuid ()
41 changes the value of the caller's filesystem user ID\(emthe
42 user ID that the Linux kernel uses to check for all accesses
43 to the filesystem.
44 Normally, the value of
45 the filesystem user ID
46 will shadow the value of the effective user ID.
47 In fact, whenever the
48 effective user ID is changed,
49 the filesystem user ID
50 will also be changed to the new value of the effective user ID.
51 .PP
52 Explicit calls to
53 .BR setfsuid ()
54 and
55 .BR setfsgid (2)
56 are usually used only by programs such as the Linux NFS server that
57 need to change what user and group ID is used for file access without a
58 corresponding change in the real and effective user and group IDs.
59 A change in the normal user IDs for a program such as the NFS server
60 is a security hole that can expose it to unwanted signals.
61 (But see below.)
62 .PP
63 .BR setfsuid ()
64 will succeed only if the caller is the superuser or if
65 .I fsuid
66 matches either the caller's real user ID, effective user ID,
67 saved set-user-ID, or current filesystem user ID.
68 .SH RETURN VALUE
69 On both success and failure,
70 this call returns the previous filesystem user ID of the caller.
71 .SH VERSIONS
72 This system call is present in Linux since version 1.2.
73 .\" This system call is present since Linux 1.1.44
74 .\" and in libc since libc 4.7.6.
75 .SH CONFORMING TO
76 .BR setfsuid ()
77 is Linux-specific and should not be used in programs intended
78 to be portable.
79 .SH NOTES
80 At the time when this system call was introduced, one process
81 could send a signal to another process with the same effective user ID.
82 This meant that if a privileged process changed its effective user ID
83 for the purpose of file permission checking,
84 then it could become vulnerable to receiving signals
85 sent by another (unprivileged) process with the same user ID.
86 The filesystem user ID attribute was thus added to allow a process to
87 change its user ID for the purposes of file permission checking without
88 at the same time becoming vulnerable to receiving unwanted signals.
89 Since Linux 2.0, signal permission handling is different (see
90 .BR kill (2)),
91 with the result that a process change can change its effective user ID
92 without being vulnerable to receiving signals from unwanted processes.
93 Thus,
94 .BR setfsuid ()
95 is nowadays unneeded and should be avoided in new applications
96 (likewise for
97 .BR setfsgid (2)).
98 .PP
99 The original Linux
100 .BR setfsuid ()
101 system call supported only 16-bit user IDs.
102 Subsequently, Linux 2.4 added
103 .BR setfsuid32 ()
104 supporting 32-bit IDs.
105 The glibc
106 .BR setfsuid ()
107 wrapper function transparently deals with the variation across kernel versions.
108 .SS C library/kernel differences
109 In glibc 2.15 and earlier,
110 when the wrapper for this system call determines that the argument can't be
111 passed to the kernel without integer truncation (because the kernel
112 is old and does not support 32-bit user IDs),
113 they will return \-1 and set \fIerrno\fP to
114 .B EINVAL
115 without attempting
116 the system call.
117 .SH BUGS
118 No error indications of any kind are returned to the caller,
119 and the fact that both successful and unsuccessful calls return
120 the same value makes it impossible to directly determine
121 whether the call succeeded or failed.
122 Instead, the caller must resort to looking at the return value
123 from a further call such as
124 .IR setfsuid(\-1)
125 (which will always fail), in order to determine if a preceding call to
126 .BR setfsuid ()
127 changed the filesystem user ID.
128 At the very
129 least,
130 .B EPERM
131 should be returned when the call fails (because the caller lacks the
132 .B CAP_SETUID
133 capability).
134 .SH SEE ALSO
135 .BR kill (2),
136 .BR setfsgid (2),
137 .BR capabilities (7),
138 .BR credentials (7)