]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/setfsuid.2
mlock.2: tfix
[thirdparty/man-pages.git] / man2 / setfsuid.2
CommitLineData
fea681da
MK
1.\" Copyright (C) 1995, Thomas K. Dyas <tdyas@eden.rutgers.edu>
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
c13182ef 12.\"
fea681da
MK
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.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
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
c11b1abf 28.\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
29.\" Added notes on capability requirements
30.\"
4b8c67d9 31.TH SETFSUID 2 2017-09-15 "Linux" "Linux Programmer's Manual"
fea681da 32.SH NAME
9ee4a2b6 33setfsuid \- set user identity used for filesystem checks
fea681da 34.SH SYNOPSIS
68f2e81e 35.B #include <sys/fsuid.h>
68e4db0a 36.PP
fea681da
MK
37.BI "int setfsuid(uid_t " fsuid );
38.SH DESCRIPTION
39The system call
e511ffb6 40.BR setfsuid ()
2ec26c2b
MK
41changes the value of the caller's filesystem user ID\(emthe
42user ID that the Linux kernel uses to check for all accesses
9ee4a2b6 43to the filesystem.
c13182ef 44Normally, the value of
2ec26c2b 45the filesystem user ID
c13182ef
MK
46will shadow the value of the effective user ID.
47In fact, whenever the
fea681da 48effective user ID is changed,
2ec26c2b 49the filesystem user ID
fea681da 50will also be changed to the new value of the effective user ID.
efeece04 51.PP
fea681da 52Explicit calls to
e511ffb6 53.BR setfsuid ()
fea681da 54and
0bfa087b 55.BR setfsgid (2)
33a0ccb2 56are usually used only by programs such as the Linux NFS server that
fea681da
MK
57need to change what user and group ID is used for file access without a
58corresponding change in the real and effective user and group IDs.
59A change in the normal user IDs for a program such as the NFS server
6387216b
MK
60is a security hole that can expose it to unwanted signals.
61(But see below.)
efeece04 62.PP
e511ffb6 63.BR setfsuid ()
33a0ccb2 64will succeed only if the caller is the superuser or if
fea681da 65.I fsuid
2ec26c2b
MK
66matches either the caller's real user ID, effective user ID,
67saved set-user-ID, or current filesystem user ID.
47297adb 68.SH RETURN VALUE
06e43089
MK
69On both success and failure,
70this call returns the previous filesystem user ID of the caller.
a3680fde
MK
71.SH VERSIONS
72This 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.
47297adb 75.SH CONFORMING TO
e511ffb6 76.BR setfsuid ()
8382f16d 77is Linux-specific and should not be used in programs intended
97c1eac8 78to be portable.
fea681da 79.SH NOTES
18cc6597
MK
80At the time when this system call was introduced, one process
81could send a signal to another process with the same effective user ID.
86f1f045 82This meant that if a privileged process changed its effective user ID
18cc6597
MK
83for the purpose of file permission checking,
84then it could become vulnerable to receiving signals
85sent by another (unprivileged) process with the same user ID.
86The filesystem user ID attribute was thus added to allow a process to
87change its user ID for the purposes of file permission checking without
88at the same time becoming vulnerable to receiving unwanted signals.
89Since Linux 2.0, signal permission handling is different (see
11256884 90.BR kill (2)),
18cc6597
MK
91with the result that a process change can change its effective user ID
92without being vulnerable to receiving signals from unwanted processes.
93Thus,
94.BR setfsuid ()
95is nowadays unneeded and should be avoided in new applications
96(likewise for
97.BR setfsgid (2)).
efeece04 98.PP
ae67a2cd
MK
99The original Linux
100.BR setfsuid ()
101system call supported only 16-bit user IDs.
c5662d5d 102Subsequently, Linux 2.4 added
ae67a2cd
MK
103.BR setfsuid32 ()
104supporting 32-bit IDs.
105The glibc
106.BR setfsuid ()
107wrapper function transparently deals with the variation across kernel versions.
dc439d82 108.SS C library/kernel differences
659cc17f
MK
109In glibc 2.15 and earlier,
110when the wrapper for this system call determines that the argument can't be
dc439d82
MK
111passed to the kernel without integer truncation (because the kernel
112is old and does not support 32-bit user IDs),
3cc069d5 113it will return \-1 and set \fIerrno\fP to
dc439d82
MK
114.B EINVAL
115without attempting
116the system call.
2dd578fd 117.SH BUGS
06e43089
MK
118No error indications of any kind are returned to the caller,
119and the fact that both successful and unsuccessful calls return
120the same value makes it impossible to directly determine
121whether the call succeeded or failed.
122Instead, the caller must resort to looking at the return value
123from 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 ()
127changed the filesystem user ID.
2dd578fd
MK
128At the very
129least,
130.B EPERM
131should be returned when the call fails (because the caller lacks the
132.B CAP_SETUID
133capability).
47297adb 134.SH SEE ALSO
fea681da
MK
135.BR kill (2),
136.BR setfsgid (2),
53a1443c
MK
137.BR capabilities (7),
138.BR credentials (7)