|
Packit |
7cfc04 |
.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
|
|
Packit |
7cfc04 |
.\" and Copyright (c) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_START(VERBATIM)
|
|
Packit |
7cfc04 |
.\" Permission is granted to make and distribute verbatim copies of this
|
|
Packit |
7cfc04 |
.\" manual provided the copyright notice and this permission notice are
|
|
Packit |
7cfc04 |
.\" preserved on all copies.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Permission is granted to copy and distribute modified versions of this
|
|
Packit |
7cfc04 |
.\" manual under the conditions for verbatim copying, provided that the
|
|
Packit |
7cfc04 |
.\" entire resulting derived work is distributed under the terms of a
|
|
Packit |
7cfc04 |
.\" permission notice identical to this one.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
Packit |
7cfc04 |
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
Packit |
7cfc04 |
.\" responsibility for errors or omissions, or for damages resulting from
|
|
Packit |
7cfc04 |
.\" the use of the information contained herein. The author(s) may not
|
|
Packit |
7cfc04 |
.\" have taken the same level of care in the production of this manual,
|
|
Packit |
7cfc04 |
.\" which is licensed free of charge, as they might when working
|
|
Packit |
7cfc04 |
.\" professionally.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
Packit |
7cfc04 |
.\" the source, must acknowledge the copyright and authors of this work.
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_END
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Modified by Michael Haardt <michael@moria.de>
|
|
Packit |
7cfc04 |
.\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
|
|
Packit |
7cfc04 |
.\" Modified 1994-08-21 by Michael Chastain <mec@shell.portal.com>:
|
|
Packit |
7cfc04 |
.\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
|
|
Packit |
7cfc04 |
.\" Modified 1999-11-12 by Urs Thuermann <urs@isnogud.escape.de>
|
|
Packit |
7cfc04 |
.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
|
|
Packit |
7cfc04 |
.\" 2006-09-04 Michael Kerrisk <mtk.manpages@gmail.com>
|
|
Packit |
7cfc04 |
.\" Added list of process attributes that are not preserved on exec().
|
|
Packit |
7cfc04 |
.\" 2007-09-14 Ollie Wild <aaw@google.com>, mtk
|
|
Packit |
7cfc04 |
.\" Add text describing limits on command-line arguments + environment
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.TH EXECVE 2 2017-09-15 "Linux" "Linux Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
execve \- execute program
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.B #include <unistd.h>
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BI "int execve(const char *" filename ", char *const " argv "[], "
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
.BI " char *const " envp []);
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
executes the program pointed to by \fIfilename\fP.
|
|
Packit |
7cfc04 |
\fIfilename\fP must be either a binary executable, or a script
|
|
Packit |
7cfc04 |
starting with a line of the form:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
\fB#!\fP \fIinterpreter \fP[optional-arg]
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
For details of the latter case, see "Interpreter scripts" below.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
\fIargv\fP is an array of argument strings passed to the new program.
|
|
Packit |
7cfc04 |
By convention, the first of these strings (i.e.,
|
|
Packit |
7cfc04 |
.IR argv[0] )
|
|
Packit |
7cfc04 |
should contain the filename associated with the file being executed.
|
|
Packit |
7cfc04 |
\fIenvp\fP is an array of strings, conventionally of the form
|
|
Packit |
7cfc04 |
\fBkey=value\fP, which are passed as environment to the new program.
|
|
Packit |
7cfc04 |
The \fIargv\fP and \fIenvp\fP arrays must each include a null pointer
|
|
Packit |
7cfc04 |
at the end of the array.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The argument vector and environment can be accessed by the
|
|
Packit |
7cfc04 |
called program's main function, when it is defined as:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
int main(int argc, char *argv[], char *envp[])
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Note, however, that the use of a third argument to the main function
|
|
Packit |
7cfc04 |
is not specified in POSIX.1;
|
|
Packit |
7cfc04 |
according to POSIX.1,
|
|
Packit |
7cfc04 |
the environment should be accessed via the external variable
|
|
Packit |
7cfc04 |
.BR environ (7).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
does not return on success, and the text, initialized data,
|
|
Packit |
7cfc04 |
uninitialized data (bss), and stack of the calling process are overwritten
|
|
Packit |
7cfc04 |
according to the contents of the newly loaded program.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
If the current program is being ptraced, a \fBSIGTRAP\fP signal is sent to it
|
|
Packit |
7cfc04 |
after a successful
|
|
Packit |
7cfc04 |
.BR execve ().
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
If the set-user-ID bit is set on the program file pointed to by
|
|
Packit |
7cfc04 |
\fIfilename\fP,
|
|
Packit |
7cfc04 |
then the effective user ID of the calling process is changed
|
|
Packit |
7cfc04 |
to that of the owner of the program file.
|
|
Packit |
7cfc04 |
Similarly, when the set-group-ID
|
|
Packit |
7cfc04 |
bit of the program file is set the effective group ID of the calling
|
|
Packit |
7cfc04 |
process is set to the group of the program file.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The aforementioned transformations of the effective IDs are
|
|
Packit |
7cfc04 |
.I not
|
|
Packit |
7cfc04 |
performed (i.e., the set-user-ID and set-group-ID bits are ignored)
|
|
Packit |
7cfc04 |
if any of the following is true:
|
|
Packit |
7cfc04 |
.IP * 3
|
|
Packit |
7cfc04 |
the
|
|
Packit |
7cfc04 |
.I no_new_privs
|
|
Packit |
7cfc04 |
attribute is set for the calling thread (see
|
|
Packit |
7cfc04 |
.BR prctl (2));
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
the underlying filesystem is mounted
|
|
Packit |
7cfc04 |
.I nosuid
|
|
Packit |
7cfc04 |
(the
|
|
Packit |
7cfc04 |
.B MS_NOSUID
|
|
Packit |
7cfc04 |
flag for
|
|
Packit |
7cfc04 |
.BR mount (2));
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
the calling process is being ptraced.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The capabilities of the program file (see
|
|
Packit |
7cfc04 |
.BR capabilities (7))
|
|
Packit |
7cfc04 |
are also ignored if any of the above are true.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The effective user ID of the process is copied to the saved set-user-ID;
|
|
Packit |
7cfc04 |
similarly, the effective group ID is copied to the saved set-group-ID.
|
|
Packit |
7cfc04 |
This copying takes place after any effective ID changes that occur
|
|
Packit |
7cfc04 |
because of the set-user-ID and set-group-ID mode bits.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The process's real UID and real GID, as well its supplementary group IDs,
|
|
Packit |
7cfc04 |
are unchanged by a call to
|
|
Packit |
7cfc04 |
.BR execve ().
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
If the executable is an a.out dynamically linked
|
|
Packit |
7cfc04 |
binary executable containing
|
|
Packit |
7cfc04 |
shared-library stubs, the Linux dynamic linker
|
|
Packit |
7cfc04 |
.BR ld.so (8)
|
|
Packit |
7cfc04 |
is called at the start of execution to bring
|
|
Packit |
7cfc04 |
needed shared objects into memory
|
|
Packit |
7cfc04 |
and link the executable with them.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
If the executable is a dynamically linked ELF executable, the
|
|
Packit |
7cfc04 |
interpreter named in the PT_INTERP segment is used to load the needed
|
|
Packit |
7cfc04 |
shared objects.
|
|
Packit |
7cfc04 |
This interpreter is typically
|
|
Packit |
7cfc04 |
.I /lib/ld-linux.so.2
|
|
Packit |
7cfc04 |
for binaries linked with glibc (see
|
|
Packit |
7cfc04 |
.BR ld-linux.so (8)).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
All process attributes are preserved during an
|
|
Packit |
7cfc04 |
.BR execve (),
|
|
Packit |
7cfc04 |
except the following:
|
|
Packit |
7cfc04 |
.IP * 3
|
|
Packit |
7cfc04 |
The dispositions of any signals that are being caught are
|
|
Packit |
7cfc04 |
reset to the default
|
|
Packit |
7cfc04 |
.RB ( signal (7)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
Any alternate signal stack is not preserved
|
|
Packit |
7cfc04 |
.RB ( sigaltstack (2)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
Memory mappings are not preserved
|
|
Packit |
7cfc04 |
.RB ( mmap (2)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
Attached System\ V shared memory segments are detached
|
|
Packit |
7cfc04 |
.RB ( shmat (2)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
POSIX shared memory regions are unmapped
|
|
Packit |
7cfc04 |
.RB ( shm_open (3)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
Open POSIX message queue descriptors are closed
|
|
Packit |
7cfc04 |
.RB ( mq_overview (7)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
Any open POSIX named semaphores are closed
|
|
Packit |
7cfc04 |
.RB ( sem_overview (7)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
POSIX timers are not preserved
|
|
Packit |
7cfc04 |
.RB ( timer_create (2)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
Any open directory streams are closed
|
|
Packit |
7cfc04 |
.RB ( opendir (3)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
Memory locks are not preserved
|
|
Packit |
7cfc04 |
.RB ( mlock (2),
|
|
Packit |
7cfc04 |
.BR mlockall (2)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
Exit handlers are not preserved
|
|
Packit |
7cfc04 |
.RB ( atexit (3),
|
|
Packit |
7cfc04 |
.BR on_exit (3)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
The floating-point environment is reset to the default (see
|
|
Packit |
7cfc04 |
.BR fenv (3)).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The process attributes in the preceding list are all specified
|
|
Packit |
7cfc04 |
in POSIX.1.
|
|
Packit |
7cfc04 |
The following Linux-specific process attributes are also
|
|
Packit |
7cfc04 |
not preserved during an
|
|
Packit |
7cfc04 |
.BR execve ():
|
|
Packit |
7cfc04 |
.IP * 3
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR prctl (2)
|
|
Packit |
7cfc04 |
.B PR_SET_DUMPABLE
|
|
Packit |
7cfc04 |
flag is set,
|
|
Packit |
7cfc04 |
unless a set-user-ID or set-group ID program is being executed,
|
|
Packit |
7cfc04 |
in which case it is cleared.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR prctl (2)
|
|
Packit |
7cfc04 |
.B PR_SET_KEEPCAPS
|
|
Packit |
7cfc04 |
flag is cleared.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
(Since Linux 2.4.36 / 2.6.23)
|
|
Packit |
7cfc04 |
If a set-user-ID or set-group-ID program is being executed,
|
|
Packit |
7cfc04 |
then the parent death signal set by
|
|
Packit |
7cfc04 |
.BR prctl (2)
|
|
Packit |
7cfc04 |
.B PR_SET_PDEATHSIG
|
|
Packit |
7cfc04 |
flag is cleared.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
The process name, as set by
|
|
Packit |
7cfc04 |
.BR prctl (2)
|
|
Packit |
7cfc04 |
.B PR_SET_NAME
|
|
Packit |
7cfc04 |
(and displayed by
|
|
Packit |
7cfc04 |
.IR "ps\ \-o comm" ),
|
|
Packit |
7cfc04 |
is reset to the name of the new executable file.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.B SECBIT_KEEP_CAPS
|
|
Packit |
7cfc04 |
.I securebits
|
|
Packit |
7cfc04 |
flag is cleared.
|
|
Packit |
7cfc04 |
See
|
|
Packit |
7cfc04 |
.BR capabilities (7).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
The termination signal is reset to
|
|
Packit |
7cfc04 |
.B SIGCHLD
|
|
Packit |
7cfc04 |
(see
|
|
Packit |
7cfc04 |
.BR clone (2)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
The file descriptor table is unshared, undoing the effect of the
|
|
Packit |
7cfc04 |
.B CLONE_FILES
|
|
Packit |
7cfc04 |
flag of
|
|
Packit |
7cfc04 |
.BR clone (2).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Note the following further points:
|
|
Packit |
7cfc04 |
.IP * 3
|
|
Packit |
7cfc04 |
All threads other than the calling thread are destroyed during an
|
|
Packit |
7cfc04 |
.BR execve ().
|
|
Packit |
7cfc04 |
Mutexes, condition variables, and other pthreads objects are not preserved.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
The equivalent of \fIsetlocale(LC_ALL, "C")\fP
|
|
Packit |
7cfc04 |
is executed at program start-up.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
POSIX.1 specifies that the dispositions of any signals that
|
|
Packit |
7cfc04 |
are ignored or set to the default are left unchanged.
|
|
Packit |
7cfc04 |
POSIX.1 specifies one exception: if
|
|
Packit |
7cfc04 |
.B SIGCHLD
|
|
Packit |
7cfc04 |
is being ignored,
|
|
Packit |
7cfc04 |
then an implementation may leave the disposition unchanged or
|
|
Packit |
7cfc04 |
reset it to the default; Linux does the former.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
Any outstanding asynchronous I/O operations are canceled
|
|
Packit |
7cfc04 |
.RB ( aio_read (3),
|
|
Packit |
7cfc04 |
.BR aio_write (3)).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
For the handling of capabilities during
|
|
Packit |
7cfc04 |
.BR execve (),
|
|
Packit |
7cfc04 |
see
|
|
Packit |
7cfc04 |
.BR capabilities (7).
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
By default, file descriptors remain open across an
|
|
Packit |
7cfc04 |
.BR execve ().
|
|
Packit |
7cfc04 |
File descriptors that are marked close-on-exec are closed;
|
|
Packit |
7cfc04 |
see the description of
|
|
Packit |
7cfc04 |
.B FD_CLOEXEC
|
|
Packit |
7cfc04 |
in
|
|
Packit |
7cfc04 |
.BR fcntl (2).
|
|
Packit |
7cfc04 |
(If a file descriptor is closed, this will cause the release
|
|
Packit |
7cfc04 |
of all record locks obtained on the underlying file by this process.
|
|
Packit |
7cfc04 |
See
|
|
Packit |
7cfc04 |
.BR fcntl (2)
|
|
Packit |
7cfc04 |
for details.)
|
|
Packit |
7cfc04 |
POSIX.1 says that if file descriptors 0, 1, and 2 would
|
|
Packit |
7cfc04 |
otherwise be closed after a successful
|
|
Packit |
7cfc04 |
.BR execve (),
|
|
Packit |
7cfc04 |
and the process would gain privilege because the set-user-ID or
|
|
Packit |
7cfc04 |
set-group_ID mode bit was set on the executed file,
|
|
Packit |
7cfc04 |
then the system may open an unspecified file for each of these
|
|
Packit |
7cfc04 |
file descriptors.
|
|
Packit |
7cfc04 |
As a general principle, no portable program, whether privileged or not,
|
|
Packit |
7cfc04 |
can assume that these three file descriptors will remain
|
|
Packit |
7cfc04 |
closed across an
|
|
Packit |
7cfc04 |
.BR execve ().
|
|
Packit |
7cfc04 |
.\" On Linux it appears that these file descriptors are
|
|
Packit |
7cfc04 |
.\" always open after an execve(), and it looks like
|
|
Packit |
7cfc04 |
.\" Solaris 8 and FreeBSD 6.1 are the same. -- mtk, 30 Apr 2007
|
|
Packit |
7cfc04 |
.SS Interpreter scripts
|
|
Packit |
7cfc04 |
An interpreter script is a text file that has execute
|
|
Packit |
7cfc04 |
permission enabled and whose first line is of the form:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
\fB#!\fP \fIinterpreter \fP[optional-arg]
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.I interpreter
|
|
Packit |
7cfc04 |
must be a valid pathname for an executable file.
|
|
Packit |
7cfc04 |
If the
|
|
Packit |
7cfc04 |
.I filename
|
|
Packit |
7cfc04 |
argument of
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
specifies an interpreter script, then
|
|
Packit |
7cfc04 |
.I interpreter
|
|
Packit |
7cfc04 |
will be invoked with the following arguments:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
\fIinterpreter\fP [optional-arg] \fIfilename\fP arg...
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
where
|
|
Packit |
7cfc04 |
.I arg...
|
|
Packit |
7cfc04 |
is the series of words pointed to by the
|
|
Packit |
7cfc04 |
.I argv
|
|
Packit |
7cfc04 |
argument of
|
|
Packit |
7cfc04 |
.BR execve (),
|
|
Packit |
7cfc04 |
starting at
|
|
Packit |
7cfc04 |
.IR argv [1].
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
For portable use,
|
|
Packit |
7cfc04 |
.I optional-arg
|
|
Packit |
7cfc04 |
should either be absent, or be specified as a single word (i.e., it
|
|
Packit |
7cfc04 |
should not contain white space); see NOTES below.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Since Linux 2.6.28,
|
|
Packit |
7cfc04 |
.\" commit bf2a9a39639b8b51377905397a5005f444e9a892
|
|
Packit |
7cfc04 |
the kernel permits the interpreter of a script to itself be a script.
|
|
Packit |
7cfc04 |
This permission is recursive, up to a limit of four recursions,
|
|
Packit |
7cfc04 |
so that the interpreter may be a script which is interpreted by a script,
|
|
Packit |
7cfc04 |
and so on.
|
|
Packit |
7cfc04 |
.SS Limits on size of arguments and environment
|
|
Packit |
7cfc04 |
Most UNIX implementations impose some limit on the total size
|
|
Packit |
7cfc04 |
of the command-line argument
|
|
Packit |
7cfc04 |
.RI ( argv )
|
|
Packit |
7cfc04 |
and environment
|
|
Packit |
7cfc04 |
.RI ( envp )
|
|
Packit |
7cfc04 |
strings that may be passed to a new program.
|
|
Packit |
7cfc04 |
POSIX.1 allows an implementation to advertise this limit using the
|
|
Packit |
7cfc04 |
.B ARG_MAX
|
|
Packit |
7cfc04 |
constant (either defined in
|
|
Packit |
7cfc04 |
.I <limits.h>
|
|
Packit |
7cfc04 |
or available at run time using the call
|
|
Packit |
7cfc04 |
.IR "sysconf(_SC_ARG_MAX)" ).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
On Linux prior to kernel 2.6.23, the memory used to store the
|
|
Packit |
7cfc04 |
environment and argument strings was limited to 32 pages
|
|
Packit |
7cfc04 |
(defined by the kernel constant
|
|
Packit |
7cfc04 |
.BR MAX_ARG_PAGES ).
|
|
Packit |
7cfc04 |
On architectures with a 4-kB page size,
|
|
Packit |
7cfc04 |
this yields a maximum size of 128\ kB.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
On kernel 2.6.23 and later, most architectures support a size limit
|
|
Packit |
7cfc04 |
derived from the soft
|
|
Packit |
7cfc04 |
.B RLIMIT_STACK
|
|
Packit |
7cfc04 |
resource limit (see
|
|
Packit |
7cfc04 |
.BR getrlimit (2))
|
|
Packit |
7cfc04 |
that is in force at the time of the
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
call.
|
|
Packit |
7cfc04 |
(Architectures with no memory management unit are excepted:
|
|
Packit |
7cfc04 |
they maintain the limit that was in effect before kernel 2.6.23.)
|
|
Packit |
7cfc04 |
This change allows programs to have a much larger
|
|
Packit |
7cfc04 |
argument and/or environment list.
|
|
Packit |
7cfc04 |
.\" For some background on the changes to ARG_MAX in kernels 2.6.23 and
|
|
Packit |
7cfc04 |
.\" 2.6.25, see:
|
|
Packit |
7cfc04 |
.\" http://sourceware.org/bugzilla/show_bug.cgi?id=5786
|
|
Packit |
7cfc04 |
.\" http://bugzilla.kernel.org/show_bug.cgi?id=10095
|
|
Packit |
7cfc04 |
.\" http://thread.gmane.org/gmane.linux.kernel/646709/focus=648101,
|
|
Packit |
7cfc04 |
.\" checked into 2.6.25 as commit a64e715fc74b1a7dcc5944f848acc38b2c4d4ee2.
|
|
Packit |
7cfc04 |
For these architectures, the total size is limited to 1/4 of the allowed
|
|
Packit |
7cfc04 |
stack size.
|
|
Packit |
7cfc04 |
(Imposing the 1/4-limit
|
|
Packit |
7cfc04 |
ensures that the new program always has some stack space.)
|
|
Packit |
7cfc04 |
.\" Ollie: That doesn't include the lists of pointers, though,
|
|
Packit |
7cfc04 |
.\" so the actual usage is a bit higher (1 pointer per argument).
|
|
Packit |
7cfc04 |
Since Linux 2.6.25,
|
|
Packit |
7cfc04 |
the kernel places a floor of 32 pages on this size limit,
|
|
Packit |
7cfc04 |
so that, even when
|
|
Packit |
7cfc04 |
.BR RLIMIT_STACK
|
|
Packit |
7cfc04 |
is set very low,
|
|
Packit |
7cfc04 |
applications are guaranteed to have at least as much argument and
|
|
Packit |
7cfc04 |
environment space as was provided by Linux 2.6.23 and earlier.
|
|
Packit |
7cfc04 |
(This guarantee was not provided in Linux 2.6.23 and 2.6.24.)
|
|
Packit |
7cfc04 |
Additionally, the limit per string is 32 pages (the kernel constant
|
|
Packit |
7cfc04 |
.BR MAX_ARG_STRLEN ),
|
|
Packit |
7cfc04 |
and the maximum number of strings is 0x7FFFFFFF.
|
|
Packit |
7cfc04 |
.SH RETURN VALUE
|
|
Packit |
7cfc04 |
On success,
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
does not return, on error \-1 is returned, and
|
|
Packit |
7cfc04 |
.I errno
|
|
Packit |
7cfc04 |
is set appropriately.
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B E2BIG
|
|
Packit |
7cfc04 |
The total number of bytes in the environment
|
|
Packit |
7cfc04 |
.RI ( envp )
|
|
Packit |
7cfc04 |
and argument list
|
|
Packit |
7cfc04 |
.RI ( argv )
|
|
Packit |
7cfc04 |
is too large.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EACCES
|
|
Packit |
7cfc04 |
Search permission is denied on a component of the path prefix of
|
|
Packit |
7cfc04 |
.I filename
|
|
Packit |
7cfc04 |
or the name of a script interpreter.
|
|
Packit |
7cfc04 |
(See also
|
|
Packit |
7cfc04 |
.BR path_resolution (7).)
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EACCES
|
|
Packit |
7cfc04 |
The file or a script interpreter is not a regular file.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EACCES
|
|
Packit |
7cfc04 |
Execute permission is denied for the file or a script or ELF interpreter.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EACCES
|
|
Packit |
7cfc04 |
The filesystem is mounted
|
|
Packit |
7cfc04 |
.IR noexec .
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EAGAIN " (since Linux 3.1)"
|
|
Packit |
7cfc04 |
.\" commit 72fa59970f8698023045ab0713d66f3f4f96945c
|
|
Packit |
7cfc04 |
Having changed its real UID using one of the
|
|
Packit |
7cfc04 |
.BR set*uid ()
|
|
Packit |
7cfc04 |
calls, the caller was\(emand is now still\(emabove its
|
|
Packit |
7cfc04 |
.BR RLIMIT_NPROC
|
|
Packit |
7cfc04 |
resource limit (see
|
|
Packit |
7cfc04 |
.BR setrlimit (2)).
|
|
Packit |
7cfc04 |
For a more detailed explanation of this error, see NOTES.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EFAULT
|
|
Packit |
7cfc04 |
.I filename
|
|
Packit |
7cfc04 |
or one of the pointers in the vectors
|
|
Packit |
7cfc04 |
.I argv
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.I envp
|
|
Packit |
7cfc04 |
points outside your accessible address space.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EINVAL
|
|
Packit |
7cfc04 |
An ELF executable had more than one PT_INTERP segment (i.e., tried to
|
|
Packit |
7cfc04 |
name more than one interpreter).
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EIO
|
|
Packit |
7cfc04 |
An I/O error occurred.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EISDIR
|
|
Packit |
7cfc04 |
An ELF interpreter was a directory.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ELIBBAD
|
|
Packit |
7cfc04 |
An ELF interpreter was not in a recognized format.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ELOOP
|
|
Packit |
7cfc04 |
Too many symbolic links were encountered in resolving
|
|
Packit |
7cfc04 |
.I filename
|
|
Packit |
7cfc04 |
or the name of a script or ELF interpreter.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ELOOP
|
|
Packit |
7cfc04 |
The maximum recursion limit was reached during recursive script
|
|
Packit |
7cfc04 |
interpretation (see "Interpreter scripts", above).
|
|
Packit |
7cfc04 |
Before Linux 3.8,
|
|
Packit |
7cfc04 |
.\" commit d740269867021faf4ce38a449353d2b986c34a67
|
|
Packit |
7cfc04 |
the error produced for this case was
|
|
Packit |
7cfc04 |
.BR ENOEXEC .
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EMFILE
|
|
Packit |
7cfc04 |
The per-process limit on the number of open file descriptors has been reached.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENAMETOOLONG
|
|
Packit |
7cfc04 |
.I filename
|
|
Packit |
7cfc04 |
is too long.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENFILE
|
|
Packit |
7cfc04 |
The system-wide limit on the total number of open files has been reached.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENOENT
|
|
Packit |
7cfc04 |
The file
|
|
Packit |
7cfc04 |
.I filename
|
|
Packit |
7cfc04 |
or a script or ELF interpreter does not exist, or a shared library
|
|
Packit |
7cfc04 |
.\" FIXME but see http://sourceware.org/bugzilla/show_bug.cgi?id=12241
|
|
Packit |
7cfc04 |
needed for the file or interpreter cannot be found.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENOEXEC
|
|
Packit |
7cfc04 |
An executable is not in a recognized format, is for the wrong
|
|
Packit |
7cfc04 |
architecture, or has some other format error that means it cannot be
|
|
Packit |
7cfc04 |
executed.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENOMEM
|
|
Packit |
7cfc04 |
Insufficient kernel memory was available.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENOTDIR
|
|
Packit |
7cfc04 |
A component of the path prefix of
|
|
Packit |
7cfc04 |
.I filename
|
|
Packit |
7cfc04 |
or a script or ELF interpreter is not a directory.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EPERM
|
|
Packit |
7cfc04 |
The filesystem is mounted
|
|
Packit |
7cfc04 |
.IR nosuid ,
|
|
Packit |
7cfc04 |
the user is not the superuser,
|
|
Packit |
7cfc04 |
and the file has the set-user-ID or set-group-ID bit set.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EPERM
|
|
Packit |
7cfc04 |
The process is being traced, the user is not the superuser and the
|
|
Packit |
7cfc04 |
file has the set-user-ID or set-group-ID bit set.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EPERM
|
|
Packit |
7cfc04 |
A "capability-dumb" applications would not obtain the full set of
|
|
Packit |
7cfc04 |
permitted capabilities granted by the executable file.
|
|
Packit |
7cfc04 |
See
|
|
Packit |
7cfc04 |
.BR capabilities (7).
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ETXTBSY
|
|
Packit |
7cfc04 |
The specified executable was open for writing by one or more processes.
|
|
Packit |
7cfc04 |
.SH CONFORMING TO
|
|
Packit |
7cfc04 |
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
|
|
Packit |
7cfc04 |
POSIX does not document the #! behavior, but it exists
|
|
Packit |
7cfc04 |
(with some variations) on other UNIX systems.
|
|
Packit |
7cfc04 |
.\" SVr4 documents additional error
|
|
Packit |
7cfc04 |
.\" conditions EAGAIN, EINTR, ELIBACC, ENOLINK, EMULTIHOP; POSIX does not
|
|
Packit |
7cfc04 |
.\" document ETXTBSY, EPERM, EFAULT, ELOOP, EIO, ENFILE, EMFILE, EINVAL,
|
|
Packit |
7cfc04 |
.\" EISDIR or ELIBBAD error conditions.
|
|
Packit |
7cfc04 |
.SH NOTES
|
|
Packit |
7cfc04 |
Set-user-ID and set-group-ID processes can not be
|
|
Packit |
7cfc04 |
.BR ptrace (2)d.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The result of mounting a filesystem
|
|
Packit |
7cfc04 |
.I nosuid
|
|
Packit |
7cfc04 |
varies across Linux kernel versions:
|
|
Packit |
7cfc04 |
some will refuse execution of set-user-ID and set-group-ID
|
|
Packit |
7cfc04 |
executables when this would
|
|
Packit |
7cfc04 |
give the user powers she did not have already (and return
|
|
Packit |
7cfc04 |
.BR EPERM ),
|
|
Packit |
7cfc04 |
some will just ignore the set-user-ID and set-group-ID bits and
|
|
Packit |
7cfc04 |
.BR exec ()
|
|
Packit |
7cfc04 |
successfully.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
On Linux,
|
|
Packit |
7cfc04 |
.I argv
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.I envp
|
|
Packit |
7cfc04 |
can be specified as NULL.
|
|
Packit |
7cfc04 |
In both cases, this has the same effect as specifying the argument
|
|
Packit |
7cfc04 |
as a pointer to a list containing a single null pointer.
|
|
Packit |
7cfc04 |
.B "Do not take advantage of this nonstandard and nonportable misfeature!"
|
|
Packit |
7cfc04 |
On many other UNIX systems, specifying
|
|
Packit |
7cfc04 |
.I argv
|
|
Packit |
7cfc04 |
as NULL will result in an error
|
|
Packit |
7cfc04 |
.RB ( EFAULT ).
|
|
Packit |
7cfc04 |
.I Some
|
|
Packit |
7cfc04 |
other UNIX systems treat the
|
|
Packit |
7cfc04 |
.I envp==NULL
|
|
Packit |
7cfc04 |
case the same as Linux.
|
|
Packit |
7cfc04 |
.\" e.g., EFAULT on Solaris 8 and FreeBSD 6.1; but
|
|
Packit |
7cfc04 |
.\" HP-UX 11 is like Linux -- mtk, Apr 2007
|
|
Packit |
7cfc04 |
.\" Bug filed 30 Apr 2007: http://bugzilla.kernel.org/show_bug.cgi?id=8408
|
|
Packit |
7cfc04 |
.\" Bug rejected (because fix would constitute an ABI change).
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
POSIX.1 says that values returned by
|
|
Packit |
7cfc04 |
.BR sysconf (3)
|
|
Packit |
7cfc04 |
should be invariant over the lifetime of a process.
|
|
Packit |
7cfc04 |
However, since Linux 2.6.23, if the
|
|
Packit |
7cfc04 |
.BR RLIMIT_STACK
|
|
Packit |
7cfc04 |
resource limit changes, then the value reported by
|
|
Packit |
7cfc04 |
.B _SC_ARG_MAX
|
|
Packit |
7cfc04 |
will also change,
|
|
Packit |
7cfc04 |
to reflect the fact that the limit on space for holding
|
|
Packit |
7cfc04 |
command-line arguments and environment variables has changed.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
In most cases where
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
fails, control returns to the original executable image,
|
|
Packit |
7cfc04 |
and the caller of
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
can then handle the error.
|
|
Packit |
7cfc04 |
However, in (rare) cases (typically caused by resource exhaustion),
|
|
Packit |
7cfc04 |
failure may occur past the point of no return:
|
|
Packit |
7cfc04 |
the original executable image has been torn down,
|
|
Packit |
7cfc04 |
but the new image could not be completely built.
|
|
Packit |
7cfc04 |
In such cases, the kernel kills the process with a
|
|
Packit |
7cfc04 |
.BR SIGKILL
|
|
Packit |
7cfc04 |
signal.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.SS Interpreter scripts
|
|
Packit |
7cfc04 |
A maximum line length of 127 characters is allowed for the first line in
|
|
Packit |
7cfc04 |
an interpreter script.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The semantics of the
|
|
Packit |
7cfc04 |
.I optional-arg
|
|
Packit |
7cfc04 |
argument of an interpreter script vary across implementations.
|
|
Packit |
7cfc04 |
On Linux, the entire string following the
|
|
Packit |
7cfc04 |
.I interpreter
|
|
Packit |
7cfc04 |
name is passed as a single argument to the interpreter,
|
|
Packit |
7cfc04 |
and this string can include white space.
|
|
Packit |
7cfc04 |
However, behavior differs on some other systems.
|
|
Packit |
7cfc04 |
Some systems
|
|
Packit |
7cfc04 |
.\" e.g., Solaris 8
|
|
Packit |
7cfc04 |
use the first white space to terminate
|
|
Packit |
7cfc04 |
.IR optional-arg .
|
|
Packit |
7cfc04 |
On some systems,
|
|
Packit |
7cfc04 |
.\" e.g., FreeBSD before 6.0, but not FreeBSD 6.0 onward
|
|
Packit |
7cfc04 |
an interpreter script can have multiple arguments,
|
|
Packit |
7cfc04 |
and white spaces in
|
|
Packit |
7cfc04 |
.I optional-arg
|
|
Packit |
7cfc04 |
are used to delimit the arguments.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Linux ignores the set-user-ID and set-group-ID bits on scripts.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" .SH BUGS
|
|
Packit |
7cfc04 |
.\" Some Linux versions have failed to check permissions on ELF
|
|
Packit |
7cfc04 |
.\" interpreters. This is a security hole, because it allows users to
|
|
Packit |
7cfc04 |
.\" open any file, such as a rewinding tape device, for reading. Some
|
|
Packit |
7cfc04 |
.\" Linux versions have also had other security holes in
|
|
Packit |
7cfc04 |
.\" .BR execve ()
|
|
Packit |
7cfc04 |
.\" that could be exploited for denial of service by a suitably crafted
|
|
Packit |
7cfc04 |
.\" ELF binary. There are no known problems with 2.0.34 or 2.2.15.
|
|
Packit |
7cfc04 |
.SS execve() and EAGAIN
|
|
Packit |
7cfc04 |
A more detailed explanation of the
|
|
Packit |
7cfc04 |
.BR EAGAIN
|
|
Packit |
7cfc04 |
error that can occur (since Linux 3.1) when calling
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
is as follows.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR EAGAIN
|
|
Packit |
7cfc04 |
error can occur when a
|
|
Packit |
7cfc04 |
.I preceding
|
|
Packit |
7cfc04 |
call to
|
|
Packit |
7cfc04 |
.BR setuid (2),
|
|
Packit |
7cfc04 |
.BR setreuid (2),
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.BR setresuid (2)
|
|
Packit |
7cfc04 |
caused the real user ID of the process to change,
|
|
Packit |
7cfc04 |
and that change caused the process to exceed its
|
|
Packit |
7cfc04 |
.BR RLIMIT_NPROC
|
|
Packit |
7cfc04 |
resource limit (i.e., the number of processes belonging
|
|
Packit |
7cfc04 |
to the new real UID exceeds the resource limit).
|
|
Packit |
7cfc04 |
From Linux 2.6.0 to 3.0, this caused the
|
|
Packit |
7cfc04 |
.BR set*uid ()
|
|
Packit |
7cfc04 |
call to fail.
|
|
Packit |
7cfc04 |
(Prior to 2.6,
|
|
Packit |
7cfc04 |
.\" commit 909cc4ae86f3380152a18e2a3c44523893ee11c4
|
|
Packit |
7cfc04 |
the resource limit was not imposed on processes that
|
|
Packit |
7cfc04 |
changed their user IDs.)
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Since Linux 3.1, the scenario just described no longer causes the
|
|
Packit |
7cfc04 |
.BR set*uid ()
|
|
Packit |
7cfc04 |
call to fail,
|
|
Packit |
7cfc04 |
because it too often led to security holes where buggy applications
|
|
Packit |
7cfc04 |
didn't check the return status and assumed
|
|
Packit |
7cfc04 |
that\(emif the caller had root privileges\(emthe call would always succeed.
|
|
Packit |
7cfc04 |
Instead, the
|
|
Packit |
7cfc04 |
.BR set*uid ()
|
|
Packit |
7cfc04 |
calls now successfully change the real UID,
|
|
Packit |
7cfc04 |
but the kernel sets an internal flag, named
|
|
Packit |
7cfc04 |
.BR PF_NPROC_EXCEEDED ,
|
|
Packit |
7cfc04 |
to note that the
|
|
Packit |
7cfc04 |
.BR RLIMIT_NPROC
|
|
Packit |
7cfc04 |
resource limit has been exceeded.
|
|
Packit |
7cfc04 |
If the
|
|
Packit |
7cfc04 |
.BR PF_NPROC_EXCEEDED
|
|
Packit |
7cfc04 |
flag is set and the resource limit is still
|
|
Packit |
7cfc04 |
exceeded at the time of a subsequent
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
call, that call fails with the error
|
|
Packit |
7cfc04 |
.BR EAGAIN .
|
|
Packit |
7cfc04 |
This kernel logic ensures that the
|
|
Packit |
7cfc04 |
.BR RLIMIT_NPROC
|
|
Packit |
7cfc04 |
resource limit is still enforced for the
|
|
Packit |
7cfc04 |
common privileged daemon workflow\(emnamely,
|
|
Packit |
7cfc04 |
.BR fork (2)
|
|
Packit |
7cfc04 |
+
|
|
Packit |
7cfc04 |
.BR set*uid ()
|
|
Packit |
7cfc04 |
+
|
|
Packit |
7cfc04 |
.BR execve ().
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
If the resource limit was not still exceeded at the time of the
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
call
|
|
Packit |
7cfc04 |
(because other processes belonging to this real UID terminated between the
|
|
Packit |
7cfc04 |
.BR set*uid ()
|
|
Packit |
7cfc04 |
call and the
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
call), then the
|
|
Packit |
7cfc04 |
.BR execve ()
|
|
Packit |
7cfc04 |
call succeeds and the kernel clears the
|
|
Packit |
7cfc04 |
.BR PF_NPROC_EXCEEDED
|
|
Packit |
7cfc04 |
process flag.
|
|
Packit |
7cfc04 |
The flag is also cleared if a subsequent call to
|
|
Packit |
7cfc04 |
.BR fork (2)
|
|
Packit |
7cfc04 |
by this process succeeds.
|
|
Packit |
7cfc04 |
.SS Historical
|
|
Packit |
7cfc04 |
With UNIX\ V6, the argument list of an
|
|
Packit |
7cfc04 |
.BR exec ()
|
|
Packit |
7cfc04 |
call was ended by 0,
|
|
Packit |
7cfc04 |
while the argument list of
|
|
Packit |
7cfc04 |
.I main
|
|
Packit |
7cfc04 |
was ended by \-1.
|
|
Packit |
7cfc04 |
Thus, this argument list was not directly usable in a further
|
|
Packit |
7cfc04 |
.BR exec ()
|
|
Packit |
7cfc04 |
call.
|
|
Packit |
7cfc04 |
Since UNIX\ V7, both are NULL.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" .SH BUGS
|
|
Packit |
7cfc04 |
.\" Some Linux versions have failed to check permissions on ELF
|
|
Packit |
7cfc04 |
.\" interpreters. This is a security hole, because it allows users to
|
|
Packit |
7cfc04 |
.\" open any file, such as a rewinding tape device, for reading. Some
|
|
Packit |
7cfc04 |
.\" Linux versions have also had other security holes in
|
|
Packit |
7cfc04 |
.\" .BR execve ()
|
|
Packit |
7cfc04 |
.\" that could be exploited for denial of service by a suitably crafted
|
|
Packit |
7cfc04 |
.\" ELF binary. There are no known problems with 2.0.34 or 2.2.15.
|
|
Packit |
7cfc04 |
.SH EXAMPLE
|
|
Packit |
7cfc04 |
The following program is designed to be execed by the second program below.
|
|
Packit |
7cfc04 |
It just echoes its command-line arguments, one per line.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
/* myecho.c */
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
#include <stdio.h>
|
|
Packit |
7cfc04 |
#include <stdlib.h>
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
int
|
|
Packit |
7cfc04 |
main(int argc, char *argv[])
|
|
Packit |
7cfc04 |
{
|
|
Packit |
7cfc04 |
int j;
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
for (j = 0; j < argc; j++)
|
|
Packit |
7cfc04 |
printf("argv[%d]: %s\\n", j, argv[j]);
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
exit(EXIT_SUCCESS);
|
|
Packit |
7cfc04 |
}
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
This program can be used to exec the program named in its command-line
|
|
Packit |
7cfc04 |
argument:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
/* execve.c */
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
#include <stdio.h>
|
|
Packit |
7cfc04 |
#include <stdlib.h>
|
|
Packit |
7cfc04 |
#include <unistd.h>
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
int
|
|
Packit |
7cfc04 |
main(int argc, char *argv[])
|
|
Packit |
7cfc04 |
{
|
|
Packit |
7cfc04 |
char *newargv[] = { NULL, "hello", "world", NULL };
|
|
Packit |
7cfc04 |
char *newenviron[] = { NULL };
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
if (argc != 2) {
|
|
Packit |
7cfc04 |
fprintf(stderr, "Usage: %s <file\-to\-exec>\\n", argv[0]);
|
|
Packit |
7cfc04 |
exit(EXIT_FAILURE);
|
|
Packit |
7cfc04 |
}
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
newargv[0] = argv[1];
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
execve(argv[1], newargv, newenviron);
|
|
Packit |
7cfc04 |
perror("execve"); /* execve() returns only on error */
|
|
Packit |
7cfc04 |
exit(EXIT_FAILURE);
|
|
Packit |
7cfc04 |
}
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
We can use the second program to exec the first as follows:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
.RB "$" " cc myecho.c \-o myecho"
|
|
Packit |
7cfc04 |
.RB "$" " cc execve.c \-o execve"
|
|
Packit |
7cfc04 |
.RB "$" " ./execve ./myecho"
|
|
Packit |
7cfc04 |
argv[0]: ./myecho
|
|
Packit |
7cfc04 |
argv[1]: hello
|
|
Packit |
7cfc04 |
argv[2]: world
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
We can also use these programs to demonstrate the use of a script
|
|
Packit |
7cfc04 |
interpreter.
|
|
Packit |
7cfc04 |
To do this we create a script whose "interpreter" is our
|
|
Packit |
7cfc04 |
.I myecho
|
|
Packit |
7cfc04 |
program:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
.RB "$" " cat > script"
|
|
Packit |
7cfc04 |
.B #!./myecho script-arg
|
|
Packit |
7cfc04 |
.B ^D
|
|
Packit |
7cfc04 |
.RB "$" " chmod +x script"
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
We can then use our program to exec the script:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
.RB "$" " ./execve ./script"
|
|
Packit |
7cfc04 |
argv[0]: ./myecho
|
|
Packit |
7cfc04 |
argv[1]: script-arg
|
|
Packit |
7cfc04 |
argv[2]: ./script
|
|
Packit |
7cfc04 |
argv[3]: hello
|
|
Packit |
7cfc04 |
argv[4]: world
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.SH SEE ALSO
|
|
Packit |
7cfc04 |
.BR chmod (2),
|
|
Packit |
7cfc04 |
.BR execveat (2),
|
|
Packit |
7cfc04 |
.BR fork (2),
|
|
Packit |
7cfc04 |
.BR get_robust_list (2),
|
|
Packit |
7cfc04 |
.BR ptrace (2),
|
|
Packit |
7cfc04 |
.BR execl (3),
|
|
Packit |
7cfc04 |
.BR fexecve (3),
|
|
Packit |
7cfc04 |
.BR getopt (3),
|
|
Packit |
7cfc04 |
.BR system (3),
|
|
Packit |
7cfc04 |
.BR credentials (7),
|
|
Packit |
7cfc04 |
.BR environ (7),
|
|
Packit |
7cfc04 |
.BR path_resolution (7),
|
|
Packit |
7cfc04 |
.BR ld.so (8)
|
|
Packit |
7cfc04 |
.SH COLOPHON
|
|
Packit |
7cfc04 |
This page is part of release 4.15 of the Linux
|
|
Packit |
7cfc04 |
.I man-pages
|
|
Packit |
7cfc04 |
project.
|
|
Packit |
7cfc04 |
A description of the project,
|
|
Packit |
7cfc04 |
information about reporting bugs,
|
|
Packit |
7cfc04 |
and the latest version of this page,
|
|
Packit |
7cfc04 |
can be found at
|
|
Packit |
7cfc04 |
\%https://www.kernel.org/doc/man\-pages/.
|