use Perl
search use Perl
 
All the Perl that's Practical to Extract and Report
 
 

Security hole found in the Safe module
posted by rafael on 2002.10.06 5:21   
Module News
rafael writes "A security hole has been discovered in Safe.pm. When a Safe compartment has already been used, there's no guarantee that it's safe any longer, because there's a way for code executed within the Safe compartment to alter its operation mask. (Thus, programs that use a Safe compartment only once aren't affected by this bug.)" Read below for the fixes...

A new version of Safe (2.08) for Perl 5.8.0 has been uploaded to the CPAN with a fix. If you're running Perl 5.8.0, replace your Safe.pm file with the one provided in the CPAN distribution.

If you're running perl version 5.005_03 through 5.6.x, (and possibly older ones, but my time machine doesn't go that far), you can fix the bug by applying two minor changes to the Safe.pm file:

--- Safe.pm.orig
+++ Safe.pm
@@ -213,7 +213,7 @@
     # Create anon sub ref in root of compartment.
     # Uses a closure (on $expr) to pass in the code to be executed.
     # (eval on one line to keep line numbers as expected by caller)
-	my $evalcode = sprintf('package %s; sub { eval $expr; }', $root);
+	my $evalcode = sprintf('package %s; sub { @_ = (); eval $expr; }', $root);
     my $evalsub;
 
 	if ($strict) { use strict; $evalsub = eval $evalcode; }
@@ -227,7 +227,7 @@
     my $root = $obj->{Root};
 
     my $evalsub = eval
-	    sprintf('package %s; sub { do $file }', $root);
+	    sprintf('package %s; sub { @_ = (); do $file }', $root);
     return Opcode::_safe_call_sv($root, $obj->{Mask}, $evalsub);
 }

Those little installation annoyances should be resolved in an upcoming Safe-2.09.

This exploit has been discovered by Andreas Jurenda, who also suggested the fix. More info about it can be found here.

 

 
use Perl Login
Nickname:

Password:

[ Create a new account ]

Related Links
· use.perl.org
· Perl
· Safe
· here
· rafael
· More on Module News
· Also by rafael

Security hole found in the Safe module | Log in/Create an Account | Top | 2 comments | Search Discussion
Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Safe 2.09 on it's way. (Score:1)
by sky (1411) <arthur at contiller.se> on 2002.10.06 7:32 (#13612)
( Last Journal: 2003.08.21 9:46 )
Fixes the installation issue and works on 5.6 atleast, probably on 5.005 aswell.

Arthur
sky

[ Reply to This ]
  • Re:Safe 2.09 on it's way. by Wayne (Score:1) 2003.05.20 3:39
  • There are features that should not be used.
    There are concepts that should not be exploited.
    There are problems that should not be solved.
    There are programs that should not be written.
                --Richard Harter, <rh@smds.com>
    Download Perl Now!

    Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2004, their respective owners.