CVE-2021-36770 (published 2021-08-11T23:15Z)

Encode.pm, as distributed in Perl through 5.34.0, allows local users to gain privileges via a Trojan horse Encode::ConfigLocal library (in the current working directory) that preempts dynamic module loading. Exploitation requires an unusual configuration, and certain 2021 versions of Encode.pm (3.05 through 3.11). This issue occurs because the || operator evaluates @INC in a scalar context, and thus @INC has only an integer value.

Severity: MEDIUM
CVSS v2 base score: 6.8 (AV:N/AC:M/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 7.8, HIGH (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-427
cwe_name: Uncontrolled Search Path Element
description: The product uses a fixed or controlled search path to find resources, but one or more locations in that path can be under the control of unintended actors.
extended_description: 
            Although this weakness can occur with any type of resource, it is frequently introduced when a product uses a directory search path to find executables or code libraries, but the path contains a directory that can be modified by an attacker, such as "/tmp" or the current working directory.
            In Windows-based systems, when the LoadLibrary or LoadLibraryEx function is called with a DLL name that does not contain a fully qualified path, the function follows a search order that includes two path elements that might be uncontrolled:
               
                  the directory from which the program has been loaded
                  the current working directory
               
            In some cases, the attack can be conducted remotely, such as when SMB or WebDAV network shares are used.
	    One or more locations in that path could include the Windows drive root or its subdirectories. This often exists in Linux-based code assuming the controlled nature of the root directory (/) or its subdirectories (/etc, etc), or a code that recursively accesses the parent directory.  In Windows, the drive root and some of its subdirectories have weak permissions by default, which makes them uncontrolled.
            In some Unix-based systems, a PATH might be created that contains an empty element, e.g. by splicing an empty variable into the PATH. This empty element can be interpreted as equivalent to the current working directory, which might be an untrusted search element.
            In software package management frameworks (e.g., npm, RubyGems, or PyPi), the framework may identify dependencies on third-party libraries or other packages, then consult a repository that contains the desired package. The framework may search a public repository before a private repository. This could be exploited by attackers by placing a malicious package in the public repository that has the same name as a package from the private repository. The search path might not be directly under control of the developer relying on the framework, but this search order effectively contains an untrusted element.
         
         

Fix information:
repo_url: https://github.com/Perl/perl5
commit_details: repo_url: https://github.com/Perl/perl5
author: Ricardo Signes
author_date: 2021-08-09 08:14:05-04:00
msg: Encode.pm: apply a local patch for CVE-2021-36770

I expect Encode to see a new release today.

Without this fix, Encode::ConfigLocal can be loaded from a path relative
to the current directory, because the || operator will evaluate @INC in
scalar context, putting an integer as the only value in @INC.
repository: repo_url: https://github.com/Perl/perl5
repo_name: Perl/perl5
description: 🐪 The Perl programming language
repo_language: Perl
owner: Perl
file_changes: filename: Encode.pm
change_type: ModificationType.MODIFY
diff: @@ -7,7 +7,8 @@ use warnings;
 use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG};
 our $VERSION;
 BEGIN {
-    $VERSION = sprintf "%d.%02d", q$Revision: 3.10 $ =~ /(\d+)/g;
+    $VERSION = "3.10_01";
+    $VERSION = eval $VERSION;
     require XSLoader;
     XSLoader::load( __PACKAGE__, $VERSION );
 }
@@ -65,8 +66,8 @@ require Encode::Config;
 eval {
     local $SIG{__DIE__};
     local $SIG{__WARN__};
-    local @INC = @INC || ();
-    pop @INC if $INC[-1] eq '.';
+    local @INC = @INC;
+    pop @INC if @INC && $INC[-1] eq '.';
     require Encode::ConfigLocal;
 };
 

programming_language: Perl
repo_url: https://github.com/dankogai/p5-encode
commit_details: repo_url: https://github.com/dankogai/p5-encode
author: Dan Kogai
author_date: 2021-08-09 23:19:25+09:00
msg: version 3.12 to address CVE-2021-36770
repository: repo_url: https://github.com/dankogai/p5-encode
repo_name: dankogai/p5-encode
description: Encode - character encodings (for Perl 5.8 or better)
repo_language: Perl
owner: dankogai
file_changes: filename: Changes
change_type: ModificationType.MODIFY
diff: @@ -1,8 +1,12 @@
 # Revision history for Perl extension Encode.
 #
-# $Id: Changes,v 3.11 2021/07/23 02:26:54 dankogai Exp dankogai $
+# $Id: Changes,v 3.12 2021/08/09 14:17:04 dankogai Exp dankogai $
 #
-$Revision: 3.11 $ $Date: 2021/07/23 02:26:54 $
+$Revision: 3.12 $ $Date: 2021/08/09 14:17:04 $
+! Encode.pm
+  Address CVE-2021-36770
+  <9639159a-d070-4762-9cbd-f1622f10449c@beta.fastmail.com>
+3.11 2021/07/23 02:26:54
 ! Unicode/Unicode.xs
 + t/Unicode_trailing_nul.t
   Pulled: Ensure that UTF-16 decode always includes a trailing NUL.

programming_language: Markdown
filename: Encode.pm
change_type: ModificationType.MODIFY
diff: @@ -1,5 +1,5 @@
 #
-# $Id: Encode.pm,v 3.11 2021/07/23 02:26:02 dankogai Exp $
+# $Id: Encode.pm,v 3.12 2021/08/09 14:17:04 dankogai Exp dankogai $
 #
 package Encode;
 use strict;
@@ -7,7 +7,7 @@ use warnings;
 use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG};
 our $VERSION;
 BEGIN {
-    $VERSION = sprintf "%d.%02d", q$Revision: 3.11 $ =~ /(\d+)/g;
+    $VERSION = sprintf "%d.%02d", q$Revision: 3.12 $ =~ /(\d+)/g;
     require XSLoader;
     XSLoader::load( __PACKAGE__, $VERSION );
 }
@@ -65,8 +65,8 @@ require Encode::Config;
 eval {
     local $SIG{__DIE__};
     local $SIG{__WARN__};
-    local @INC = @INC || ();
-    pop @INC if $INC[-1] eq '.';
+    local @INC = @INC;
+    pop @INC if @INC && $INC[-1] eq '.';
     require Encode::ConfigLocal;
 };
 

programming_language: Perl
filename: Unicode.xs
change_type: ModificationType.MODIFY
diff: @@ -1,5 +1,5 @@
 /*
- $Id: Unicode.xs,v 2.20 2021/07/23 02:26:54 dankogai Exp dankogai $
+ $Id: Unicode.xs,v 2.20 2021/07/23 02:26:54 dankogai Exp $
  */
 
 #define IN_UNICODE_XS

programming_language: C
filename: Unicode.t
change_type: ModificationType.MODIFY
diff: @@ -1,5 +1,5 @@
 #
-# $Id: Unicode.t,v 2.4 2021/07/23 02:26:54 dankogai Exp dankogai $
+# $Id: Unicode.t,v 2.4 2021/07/23 02:26:54 dankogai Exp $
 #
 # This script is written entirely in ASCII, even though quoted literals
 # do include non-BMP unicode characters -- Are you happy, jhi?

programming_language: Perl