1 .\" Copyright (c) 2006, 2014, Michael Kerrisk
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH FEXECVE 3 2021-03-22 "Linux" "Linux Programmer's Manual"
27 fexecve \- execute program specified via file descriptor
30 .B #include <unistd.h>
32 .BI "int fexecve(int " fd ", char *const " argv "[], char *const " envp []);
36 Feature Test Macro Requirements for glibc (see
37 .BR feature_test_macros (7)):
43 _POSIX_C_SOURCE >= 200809L
49 performs the same task as
51 with the difference that the file to be executed
52 is specified via a file descriptor,
54 rather than via a pathname.
57 must be opened read-only
62 and the caller must have permission to execute the file that it refers to.
67 On error, the function does return, with a result value of \-1, and
69 is set to indicate the error.
73 with the following additions:
77 is not a valid file descriptor, or
84 The close-on-exec flag is set on
92 The kernel does not provide the
96 filesystem could not be accessed.
99 is implemented since glibc 2.3.2.
101 For an explanation of the terms used in this section, see
109 Interface Attribute Value
112 T} Thread safety MT-Safe
119 This function is not specified in POSIX.1-2001,
120 and is not widely available on other systems.
121 It is specified in POSIX.1-2008.
123 On Linux with glibc versions 2.26 and earlier,
125 is implemented using the
129 needs to be mounted and available at the time of the call.
131 .\" glibc commit 43ffc53a352a67672210c9dd4959f6c6b7407e60
132 if the underlying kernel supports the
136 is implemented using that system call, with the benefit that
138 does not need to be mounted.
142 is to allow the caller to verify (checksum) the contents of
143 an executable before executing it.
144 Simply opening the file, checksumming the contents, and then doing an
146 would not suffice, since, between the two steps, the filename,
147 or a directory prefix of the pathname, could have been exchanged
148 (by, for example, modifying the target of a symbolic link).
150 does not mitigate the problem that the
152 of a file could be changed between the checksumming and the call to
154 for that, the solution is to ensure that the permissions on the file
155 prevent it from being modified by malicious users.
157 The natural idiom when using
159 is to set the close-on-exec flag on
161 so that the file descriptor does not leak through to the program
163 This approach is natural for two reasons.
164 First, it prevents file descriptors being consumed unnecessarily.
165 (The executed program normally has no need of a file descriptor
166 that refers to the program itself.)
170 employing the close-on-exec flag prevents the file descriptor exhaustion
171 that would result from the fact that each step in the recursion would
172 cause one more file descriptor to be passed to the new program.
177 refers to a script (i.e., it is an executable text file that names
178 a script interpreter with a first line that begins with the characters
180 and the close-on-exec flag has been set for
186 This error occurs because,
187 by the time the script interpreter is executed,
189 has already been closed because of the close-on-exec flag.
190 Thus, the close-on-exec flag can't be set on
192 if it refers to a script, leading to the problems described in NOTES.