PERLSEC(1) User Contributed Perl Documentation PERLSEC(1)
NNNNAAAAMMMMEEEE
perlsec - Perl security
DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
Perl is designed to make it easy to write secure setuid
and setgid scripts. Unlike shells, which are based on
multiple substitution passes on each line of the script,
Perl uses a more conventional evaluation scheme with fewer
hidden "gotchas". Additionally, since the language has
more built-in functionality, it has to rely less upon
external (and possibly untrustworthy) programs to
accomplish its purposes.
Beyond the obvious problems that stem from giving special
privileges to such flexible systems as scripts, on many
operating systems, setuid scripts are inherently insecure
right from the start. This is because that between the
time that the kernel opens up the file to see what to run,
and when the now setuid interpreter it ran turns around
and reopens the file so it can interpret it, things may
have changed, especially if you have symbolic links on
your system.
Fortunately, sometimes this kernel "feature" can be
disabled. Unfortunately, there are two ways to disable
it. The system can simply outlaw scripts with the setuid
bit set, which doesn't help much. Alternately, it can
simply ignore the setuid bit on scripts. If the latter is
true, Perl can emulate the setuid and setgid mechanism
when it notices the otherwise useless setuid/gid bits on
Perl scripts. It does this via a special executable
called ssssuuuuiiiiddddppppeeeerrrrllll that is automatically invoked for you if
it's needed.
If, however, the kernel setuid script feature isn't
disabled, Perl will complain loudly that your setuid
script is insecure. You'll need to either disable the
kernel setuid script feature, or put a C wrapper around
the script. See the program wwwwrrrraaaappppssssuuuuiiiidddd in the _e_g directory
of your Perl distribution for how to go about doing this.
There are some systems on which setuid scripts are free of
this inherent security bug. For example, recent releases
of Solaris are like this. On such systems, when the
kernel passes the name of the setuid script to open to the
interpreter, rather than using a pathname subject to
mettling, it instead passes /dev/fd/3. This is a special
file already opened on the script, so that there can be no
race condition for evil scripts to exploit. On these
systems, Perl should be compiled with
----DDDDSSSSEEEETTTTUUUUIIIIDDDD____SSSSCCCCRRRRIIIIPPPPTTTTSSSS____AAAARRRREEEE____SSSSEEEECCCCUUUURRRREEEE____NNNNOOOOWWWW. The CCCCoooonnnnffffiiiigggguuuurrrreeee program
that builds Perl tries to figure this out for itself.
When executing a setuid script, or when you have turned on
23/Jan/96 perl 5.002 with 1
PERLSEC(1) User Contributed Perl Documentation PERLSEC(1)
taint checking explicitly using the ----TTTT flag, Perl takes
special precautions to prevent you from falling into any
obvious traps. (In some ways, a Perl script is more
secure than the corresponding C program.) Any command
line argument, environment variable, or input is marked as
"tainted", and may not be used, directly or indirectly, in
any command that invokes a subshell, or in any command
that modifies files, directories, or processes. Any
variable that is set within an expression that has
previously referenced a tainted value also becomes tainted
(even if it is logically impossible for the tainted value