This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #128763] Fix POSIX.xs longdbl assertion
[perl5.git] / pod / perlsec.pod
index 7b3f99d..43dd136 100644 (file)
@@ -14,11 +14,24 @@ untrustworthy) programs to accomplish its purposes.
 
 =head1 SECURITY VULNERABILITY CONTACT INFORMATION
 
-If you believe you have found a security vulnerability in Perl, please email
-perl5-security-report@perl.org with details.  This points to a closed
-subscription, unarchived mailing list.  Please only use this address for
-security issues in the Perl core, not for modules independently distributed on
-CPAN.
+If you believe you have found a security vulnerability in Perl, please
+email the details to perl5-security-report@perl.org. This creates a new
+Request Tracker ticket in a special queue which isn't initially publicly
+accessible. The email will also be copied to a closed subscription
+unarchived mailing list which includes all the core committers, who will
+be able to help assess the impact of issues, figure out a resolution, and
+help co-ordinate the release of patches to mitigate or fix the problem
+across all platforms on which Perl is supported. Please only use this
+address for security issues in the Perl core, not for modules
+independently distributed on CPAN.
+
+When sending an initial request to the security email address, please
+don't Cc any other parties, because if they reply to all, the reply will
+generate yet another new ticket. Once you have received an initial reply
+with a C<[perl #NNNNNN]> ticket number in  the headline, it's okay to Cc
+subsequent replies to third parties: all emails to the
+perl5-security-report address with the ticket number in the subject line
+will be added to the ticket; without it, a new ticket will be created.
 
 =head1 SECURITY MECHANISMS AND CONCERNS
 
@@ -28,9 +41,9 @@ Perl automatically enables a set of special security checks, called I<taint
 mode>, when it detects its program running with differing real and effective
 user or group IDs.  The setuid bit in Unix permissions is mode 04000, the
 setgid bit mode 02000; either or both may be set.  You can also enable taint
-mode explicitly by using the B<-T> command line flag. This flag is
+mode explicitly by using the B<-T> command line flag.  This flag is
 I<strongly> suggested for server programs and any program run on behalf of
-someone else, such as a CGI script. Once taint mode is on, it's on for
+someone else, such as a CGI script.  Once taint mode is on, it's on for
 the remainder of your script.
 
 While in this mode, Perl takes special precautions called I<taint
@@ -183,8 +196,9 @@ But testing for taintedness gets you only so far.  Sometimes you have just
 to clear your data's taintedness.  Values may be untainted by using them
 as keys in a hash; otherwise the only way to bypass the tainting
 mechanism is by referencing subpatterns from a regular expression match.
-Perl presumes that if you reference a substring using $1, $2, etc., that
-you knew what you were doing when you wrote the pattern.  That means using
+Perl presumes that if you reference a substring using $1, $2, etc. in a
+non-tainting pattern, that
+you knew what you were doing when you wrote that pattern.  That means using
 a bit of thought--don't just blindly untaint anything, or you defeat the
 entire mechanism.  It's better to verify that the variable has only good
 characters (for certain values of "good") rather than checking whether it
@@ -233,9 +247,9 @@ Unix-like environments that support #! and setuid or setgid scripts.)
 
 When the taint mode (C<-T>) is in effect, the "." directory is removed
 from C<@INC>, and the environment variables C<PERL5LIB> and C<PERLLIB>
-are ignored by Perl. You can still adjust C<@INC> from outside the
+are ignored by Perl.  You can still adjust C<@INC> from outside the
 program by using the C<-I> command line option as explained in
-L<perlrun>. The two environment variables are ignored because
+L<perlrun>.  The two environment variables are ignored because
 they are obscured, and a user running a program could be unaware that
 they are set, whereas the C<-I> option is clearly visible and
 therefore permitted.
@@ -246,7 +260,7 @@ the C<lib> pragma, e.g.:
   perl -Mlib=/foo program
 
 The benefit of using C<-Mlib=/foo> over C<-I/foo>, is that the former
-will automagically remove any duplicated directories, while the later
+will automagically remove any duplicated directories, while the latter
 will not.
 
 Note that if a tainted string is added to C<@INC>, the following
@@ -270,7 +284,7 @@ your PATH, it makes sure you set the PATH.
 The PATH isn't the only environment variable which can cause problems.
 Because some shells may use the variables IFS, CDPATH, ENV, and
 BASH_ENV, Perl checks that those are either empty or untainted when
-starting subprocesses. You may wish to add something like this to your
+starting subprocesses.  You may wish to add something like this to your
 setid and taint-checking scripts.
 
     delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};   # Make %ENV safer
@@ -279,7 +293,8 @@ It's also possible to get into trouble with other operations that don't
 care whether they use tainted values.  Make judicious use of the file
 tests in dealing with any user-supplied filenames.  When possible, do
 opens and such B<after> properly dropping any special user (or group!)
-privileges. Perl doesn't prevent you from opening tainted filenames for reading,
+privileges.  Perl doesn't prevent you from
+opening tainted filenames for reading,
 so be careful what you print out.  The tainting mechanism is intended to
 prevent stupid mistakes, not to remove the need for thought.
 
@@ -307,7 +322,7 @@ not called with a string that the shell could expand.  This is by far the
 best way to call something that might be subjected to shell escapes: just
 never call the shell at all.  
 
-        use English '-no_match_vars';
+        use English;
         die "Can't fork: $!" unless defined($pid = open(KID, "-|"));
         if ($pid) {           # parent
             while (<KID>) {
@@ -352,7 +367,7 @@ are trapped and namespace access is carefully controlled.  Safe should
 not be considered bullet-proof, though: it will not prevent the foreign
 code to set up infinite loops, allocate gigabytes of memory, or even
 abusing perl bugs to make the host interpreter crash or behave in
-unpredictable ways. In any case it's better avoided completely if you're
+unpredictable ways.  In any case it's better avoided completely if you're
 really concerned about security.
 
 =head2 Security Bugs
@@ -454,41 +469,88 @@ I<Denial of Service> (DoS) attacks.
 
 =item *
 
-Hash Function - the algorithm used to "order" hash elements has been
-changed several times during the development of Perl, mainly to be
-reasonably fast.  In Perl 5.8.1 also the security aspect was taken
-into account.
-
-In Perls before 5.8.1 one could rather easily generate data that as
-hash keys would cause Perl to consume large amounts of time because
-internal structure of hashes would badly degenerate.  In Perl 5.8.1
-the hash function is randomly perturbed by a pseudorandom seed which
-makes generating such naughty hash keys harder.
-See L<perlrun/PERL_HASH_SEED> for more information.
-
-In Perl 5.8.1 the random perturbation was done by default, but as of
-5.8.2 it is only used on individual hashes if the internals detect the
-insertion of pathological data. If one wants for some reason emulate the
-old behaviour (and expose oneself to DoS attacks) one can set the
-environment variable PERL_HASH_SEED to zero to disable the protection
-(or any other integer to force a known perturbation, rather than random). 
-One possible reason for wanting to emulate the old behaviour is that in the
-new behaviour consecutive runs of Perl will order hash keys differently,
-which may confuse some applications (like Data::Dumper: the outputs of two
-different runs are no longer identical).
-
-B<Perl has never guaranteed any ordering of the hash keys>, and the
-ordering has already changed several times during the lifetime of
-Perl 5.  Also, the ordering of hash keys has always been, and
-continues to be, affected by the insertion order.
+Hash Algorithm - Hash algorithms like the one used in Perl are well
+known to be vulnerable to collision attacks on their hash function.
+Such attacks involve constructing a set of keys which collide into
+the same bucket producing inefficient behavior.  Such attacks often
+depend on discovering the seed of the hash function used to map the
+keys to buckets.  That seed is then used to brute-force a key set which
+can be used to mount a denial of service attack.  In Perl 5.8.1 changes
+were introduced to harden Perl to such attacks, and then later in
+Perl 5.18.0 these features were enhanced and additional protections
+added.
+
+At the time of this writing, Perl 5.18.0 is considered to be
+well-hardened against algorithmic complexity attacks on its hash
+implementation.  This is largely owed to the following measures
+mitigate attacks:
+
+=over 4
+
+=item Hash Seed Randomization
+
+In order to make it impossible to know what seed to generate an attack
+key set for, this seed is randomly initialized at process start.  This
+may be overridden by using the PERL_HASH_SEED environment variable, see
+L<perlrun/PERL_HASH_SEED>.  This environment variable controls how
+items are actually stored, not how they are presented via
+C<keys>, C<values> and C<each>.
+
+=item Hash Traversal Randomization
+
+Independent of which seed is used in the hash function, C<keys>,
+C<values>, and C<each> return items in a per-hash randomized order.
+Modifying a hash by insertion will change the iteration order of that hash.
+This behavior can be overridden by using C<hash_traversal_mask()> from
+L<Hash::Util> or by using the PERL_PERTURB_KEYS environment variable,
+see L<perlrun/PERL_PERTURB_KEYS>.  Note that this feature controls the
+"visible" order of the keys, and not the actual order they are stored in.
+
+=item Bucket Order Perturbance
+
+When items collide into a given hash bucket the order they are stored in
+the chain is no longer predictable in Perl 5.18.  This
+has the intention to make it harder to observe a
+collision.  This behavior can be overridden by using
+the PERL_PERTURB_KEYS environment variable, see L<perlrun/PERL_PERTURB_KEYS>.
+
+=item New Default Hash Function
+
+The default hash function has been modified with the intention of making
+it harder to infer the hash seed.
+
+=item Alternative Hash Functions
+
+The source code includes multiple hash algorithms to choose from.  While we
+believe that the default perl hash is robust to attack, we have included the
+hash function Siphash as a fall-back option.  At the time of release of
+Perl 5.18.0 Siphash is believed to be of cryptographic strength.  This is
+not the default as it is much slower than the default hash.
+
+=back
+
+Without compiling a special Perl, there is no way to get the exact same
+behavior of any versions prior to Perl 5.18.0.  The closest one can get
+is by setting PERL_PERTURB_KEYS to 0 and setting the PERL_HASH_SEED
+to a known value.  We do not advise those settings for production use
+due to the above security considerations.
+
+B<Perl has never guaranteed any ordering of the hash keys>, and
+the ordering has already changed several times during the lifetime of
+Perl 5.  Also, the ordering of hash keys has always been, and continues
+to be, affected by the insertion order and the history of changes made
+to the hash over its lifetime.
 
 Also note that while the order of the hash elements might be
-randomised, this "pseudoordering" should B<not> be used for
-applications like shuffling a list randomly (use List::Util::shuffle()
+randomized, this "pseudo-ordering" should B<not> be used for
+applications like shuffling a list randomly (use C<List::Util::shuffle()>
 for that, see L<List::Util>, a standard core module since Perl 5.8.0;
-or the CPAN module Algorithm::Numerical::Shuffle), or for generating
-permutations (use e.g. the CPAN modules Algorithm::Permute or
-Algorithm::FastPermute), or for any cryptographic applications.
+or the CPAN module C<Algorithm::Numerical::Shuffle>), or for generating
+permutations (use e.g. the CPAN modules C<Algorithm::Permute> or
+C<Algorithm::FastPermute>), or for any cryptographic applications.
+
+Tied hashes may have their own ordering and algorithmic complexity
+attacks.
 
 =item *
 
@@ -511,7 +573,7 @@ misbehave on any input.
 
 =back
 
-See L<http://www.cs.rice.edu/~scrosby/hash/> for more information,
+See L<https://www.usenix.org/legacy/events/sec03/tech/full_papers/crosby/crosby.pdf> for more information,
 and any computer science textbook on algorithmic complexity.
 
 =head1 SEE ALSO