1 .\" Copyright (C) 1995, Thomas K. Dyas <tdyas@eden.rutgers.edu>
2 .\" and Copyright (C) 2013, 2019, Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
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
12 .TH SETFSUID 2 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
14 setfsuid \- set user identity used for filesystem checks
17 .RI ( libc ", " \-lc )
20 .B #include <sys/fsuid.h>
22 .BI "int setfsuid(uid_t " fsuid );
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
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
40 to change its filesystem user ID to the value given in
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.)
55 will succeed only if the caller is the superuser or if
57 matches either the caller's real user ID, effective user ID,
58 saved set-user-ID, or current filesystem user ID.
60 On both success and failure,
61 this call returns the previous filesystem user ID of the caller.
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.
68 is Linux-specific and should not be used in programs intended
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
82 with the result that a process can change its effective user ID
83 without being vulnerable to receiving signals from unwanted processes.
86 is nowadays unneeded and should be avoided in new applications
92 system call supported only 16-bit user IDs.
93 Subsequently, Linux 2.4 added
95 supporting 32-bit IDs.
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
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
116 (which will always fail), in order to determine if a preceding call to
118 changed the filesystem user ID.
122 should be returned when the call fails (because the caller lacks the
128 .BR capabilities (7),