#7 xzgrep: arbitrary code-execuction and file-write vulnerability (#2073310, CVE-2022-1271)
Merged 2 years ago by rjones. Opened 2 years ago by tmz.
rpms/ tmz/xz rawhide  into  rawhide

file modified
+3 -1
@@ -1,1 +1,3 @@ 

- /xz-5.2.5.tar.xz

+ /*.sig

+ /*.tar.xz

+ /xz-*/

@@ -0,0 +1,75 @@ 

+ -----BEGIN PGP PUBLIC KEY BLOCK-----

+ 

+ mQINBEzEOZIBEACxg/IuXERlDB48JBWmF4NxNUuuup1IhJAJyFGFSKh3OGAO2Ard

+ sNuRLjANsFXA7m7P5eTFcG+BoHHuAVYmKnI3PPZtHVLnUt4pGItPczQZ2BE1WpcI

+ ayjGTBJeKItX3Npqg9D/odO9WWS1i3FQPVdrLn0YH37/BA66jeMQCRo7g7GLpaNf

+ IrvYGsqTbxCwsmA37rpE7oyU4Yrf74HT091WBsRIoq/MelhbxTDMR8eu/dUGZQVc

+ Kj3lN55RepwWwUUKyqarY0zMt4HkFJ7v7yRL+Cvzy92Ouv4Wf2FlhNtEs5LE4Tax

+ W0PO5AEmUoKjX87SezQK0f652018b4u6Ex52cY7p+n5TII/UyoowH6+tY8UHo9yb

+ fStrqgNE/mY2bhA6+AwCaOUGsFzVVPTbjtxL3HacUP/jlA1h78V8VTvTs5d55iG7

+ jSqR9o05wje8rwNiXXK0xtiJahyNzL97Kn/DgPSqPIi45G+8nxWSPFM5eunBKRl9

+ vAnsvwrdPRsR6YR3uMHTuVhQX9/CY891MHkaZJ6wydWtKt3yQwJLYqwo5d4DwnUX

+ CduUwSKv+6RmtWI5ZmTQYOcBRcZyGKml9X9Q8iSbm6cnpFXmLrNQwCJN+D3SiYGc

+ MtbltZo0ysPMa6Xj5xFaYqWk/BI4iLb2Gs+ByGo/+a0Eq4XYBMOpitNniQARAQAB

+ tCdMYXNzZSBDb2xsaW4gPGxhc3NlLmNvbGxpbkB0dWthYW5pLm9yZz6JAlEEEwEK

+ ADsCGwMCHgECF4AECwkIBwMVCggFFgIDAQA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h4jVsKEmVWTiRcehEgUIlrWkCu3qzd5NK+RetS7kJ8MPnzEUfj

+ YbpdC6yrF6n1mSrZZ4VJMkV2ev37bIgXM+Wp1mCAGbjNxQnjn9RabT/gjIqmGuRn

+ AP7RsSeOSuO/gO9h2Pteciz23ussTilB+8cTooQEQQZe6Kv/zukvL+ccSehLHsZ7

+ qVfRUAmtt8nFkXXE+s8jfLfhqstaI2/RJu5witaPcXM8Mnz2E95aASAbZy0eQot9

+ 0Pvf07n9yuC3tueTvzvlXx3h5U3yT44tIOmzANIQjay1TGdm+RBJ2ZYyhyLawlZ2

+ NVUXXSp4QZZXPA0UWbF+pb7Q9cdKDNFVuvGBljuea0Yd0T2o+ibDq43HziX9ll+l

+ SXk9mqvW1UcDOaxWrSsm1Gc1O9g3wqH5xHAhtY8GPh/7VgAawskPkmnlkMW6pYPy

+ zibbeISJL1gd1jIT63y6aoVrtNoo+wYJm280ROflh4+5QOo6QJ+jm70fkXSG/qJ5

+ a8/qCPTHkJc/rpkL6/TDQAJURi9RhDAC0gb40HtusbN1LZEA+i0cWTmYXap+DB4Y

+ R4pApilpaG87M+VUokR4xpnx7vTb2MPa7Mdenvi9FEGnKXadmT8038vlfzz5GGUT

+ MlVin9BQPTpdA+PpRiJvKJgVDeAFOg==

+ =asTC

+ -----END PGP PUBLIC KEY BLOCK-----

file modified
+2
@@ -1,1 +1,3 @@ 

  SHA512 (xz-5.2.5.tar.xz) = 59266068a51cb616eb31b67cd8f07ffeb2288d1391c61665ae2ec6814465afac80fec69248f6a2f2db45b44475af001296a99af6a32287226a9c41419173ccbb

+ SHA512 (xz-5.2.5.tar.xz.sig) = ea0218ac25843c8b44686871fba573809618f074465ec52f5966a082aeeb5e01bd646d462a56a6af7a786e1c69a05b135a6735ad1f3be27daecf3a2f9be865a5

+ SHA512 (xzgrep-ZDI-CAN-16587.patch.sig) = 527c2702cf3ff3ddee6e49feb6d2305e4e9cd786f856b25f0cb5776df1341c5a960ba54c179cb27c507011e1223baf4a10de8a546199806ff96f531f62b9f136

file modified
+18 -3
@@ -4,7 +4,7 @@ 

  Summary:	LZMA compression utilities

  Name:		xz

  Version:	5.2.5

- Release:	8%{?dist}

+ Release:	9%{?dist}

  

  # Scripts xz{grep,diff,less,more} and symlinks (copied from gzip) are

  # GPLv2+, binaries are Public Domain (linked against LGPL getopt_long but its
@@ -12,11 +12,19 @@ 

  License:	GPLv2+ and Public Domain

  # official upstream release

  Source0:	https://tukaani.org/%{name}/%{name}-%{version}.tar.xz

+ Source1:	https://tukaani.org/%{name}/%{name}-%{version}.tar.xz.sig

+ # https://tukaani.org/misc/lasse_collin_pubkey.txt

+ Source2:        gpgkey-3690C240CE51B4670D30AD1C38EE757D69184620.asc

+ # Signature for Patch2

+ Source3:        https://tukaani.org/%{name}/xzgrep-ZDI-CAN-16587.patch.sig

  

  Source100:	colorxzgrep.sh

  Source101:	colorxzgrep.csh

  

- Patch1:   xz-5.2.5-enable_CET.patch

+ Patch1:		xz-5.2.5-enable_CET.patch

+ # xzgrep: arbitrary-file-write vulnerability (CVE-2022-1271)

+ # NOTE: Source3 contains the upstream signature for this patch

+ Patch2:		https://tukaani.org/%{name}/xzgrep-ZDI-CAN-16587.patch

  

  URL:		https://tukaani.org/%{name}/

  Requires:	%{name}-libs%{?_isa} = %{version}-%{release}
@@ -26,8 +34,9 @@ 

  # have grepconf, but we're only concerned with F22 here.

  Requires:	grep >= 2.20-5

  

- BuildRequires:  make

+ BuildRequires:	make

  BuildRequires:	gcc

+ BuildRequires:	gnupg2

  BuildRequires:	perl-interpreter

  

  
@@ -83,6 +92,8 @@ 

  

  

  %prep

+ %{gpgverify} --keyring='%{SOURCE2}' --signature='%{SOURCE1}' --data='%{SOURCE0}'

+ %{gpgverify} --keyring='%{SOURCE2}' --signature='%{SOURCE3}' --data='%{PATCH2}'

  %autosetup -p1

  

  
@@ -156,6 +167,10 @@ 

  

  

  %changelog

+ * Sat Apr 16 2022 Todd Zullinger <tmz@pobox.com> - 5.2.5-9

+ - verify upstream GPG signature

+ - xzgrep: arbitrary-file-write vulnerability (#2073310, CVE-2022-1271)

+ 

  * Sat Jan 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 5.2.5-8

  - Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

  

@@ -0,0 +1,94 @@ 

+ From 69d1b3fc29677af8ade8dc15dba83f0589cb63d6 Mon Sep 17 00:00:00 2001

+ From: Lasse Collin <lasse.collin@tukaani.org>

+ Date: Tue, 29 Mar 2022 19:19:12 +0300

+ Subject: [PATCH] xzgrep: Fix escaping of malicious filenames (ZDI-CAN-16587).

+ 

+ Malicious filenames can make xzgrep to write to arbitrary files

+ or (with a GNU sed extension) lead to arbitrary code execution.

+ 

+ xzgrep from XZ Utils versions up to and including 5.2.5 are

+ affected. 5.3.1alpha and 5.3.2alpha are affected as well.

+ This patch works for all of them.

+ 

+ This bug was inherited from gzip's zgrep. gzip 1.12 includes

+ a fix for zgrep.

+ 

+ The issue with the old sed script is that with multiple newlines,

+ the N-command will read the second line of input, then the

+ s-commands will be skipped because it's not the end of the

+ file yet, then a new sed cycle starts and the pattern space

+ is printed and emptied. So only the last line or two get escaped.

+ 

+ One way to fix this would be to read all lines into the pattern

+ space first. However, the included fix is even simpler: All lines

+ except the last line get a backslash appended at the end. To ensure

+ that shell command substitution doesn't eat a possible trailing

+ newline, a colon is appended to the filename before escaping.

+ The colon is later used to separate the filename from the grep

+ output so it is fine to add it here instead of a few lines later.

+ 

+ The old code also wasn't POSIX compliant as it used \n in the

+ replacement section of the s-command. Using \<newline> is the

+ POSIX compatible method.

+ 

+ LC_ALL=C was added to the two critical sed commands. POSIX sed

+ manual recommends it when using sed to manipulate pathnames

+ because in other locales invalid multibyte sequences might

+ cause issues with some sed implementations. In case of GNU sed,

+ these particular sed scripts wouldn't have such problems but some

+ other scripts could have, see:

+ 

+     info '(sed)Locale Considerations'

+ 

+ This vulnerability was discovered by:

+ cleemy desu wayo working with Trend Micro Zero Day Initiative

+ 

+ Thanks to Jim Meyering and Paul Eggert discussing the different

+ ways to fix this and for coordinating the patch release schedule

+ with gzip.

+ ---

+  src/scripts/xzgrep.in | 20 ++++++++++++--------

+  1 file changed, 12 insertions(+), 8 deletions(-)

+ 

+ diff --git a/src/scripts/xzgrep.in b/src/scripts/xzgrep.in

+ index b180936..e5186ba 100644

+ --- a/src/scripts/xzgrep.in

+ +++ b/src/scripts/xzgrep.in

+ @@ -180,22 +180,26 @@ for i; do

+           { test $# -eq 1 || test $no_filename -eq 1; }; then

+        eval "$grep"

+      else

+ +      # Append a colon so that the last character will never be a newline

+ +      # which would otherwise get lost in shell command substitution.

+ +      i="$i:"

+ +

+ +      # Escape & \ | and newlines only if such characters are present

+ +      # (speed optimization).

+        case $i in

+        (*'

+  '* | *'&'* | *'\'* | *'|'*)

+ -        i=$(printf '%s\n' "$i" |

+ -            sed '

+ -              $!N

+ -              $s/[&\|]/\\&/g

+ -              $s/\n/\\n/g

+ -            ');;

+ +        i=$(printf '%s\n' "$i" | LC_ALL=C sed 's/[&\|]/\\&/g; $!s/$/\\/');;

+        esac

+ -      sed_script="s|^|$i:|"

+ +

+ +      # $i already ends with a colon so don't add it here.

+ +      sed_script="s|^|$i|"

+  

+        # Fail if grep or sed fails.

+        r=$(

+          exec 4>&1

+ -        (eval "$grep" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&-

+ +        (eval "$grep" 4>&-; echo $? >&4) 3>&- |

+ +            LC_ALL=C sed "$sed_script" >&3 4>&-

+        ) || r=2

+        exit $r

+      fi >&3 5>&-

+ -- 

+ 2.35.1

+ 

Apply the upstream patch to resolve CVE-2022-1271 (rhbz#2073310).

Check upstream gpg signature in %prep. Minor adjustments to the .gitignore patterns.

Pull-Request has been merged by rjones

2 years ago