<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://bugs.gentoo.org/bugzilla.dtd">

<bugzilla version="2.22.7"
          urlbase="http://bugs.gentoo.org/"
          maintainer="bugzilla@gentoo.org"
>

    <bug>
          <bug_id>70825</bug_id>
          
          <creation_ts>2004-11-11 11:00 0000</creation_ts>
          <short_desc>app-arch/gzip: tempfile vulnerabilities</short_desc>
          <delta_ts>2004-12-29 15:27:59 0000</delta_ts>
          
          
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Gentoo Security</product>
          <component>Vulnerabilities</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <status_whiteboard>A? [stable] koon</status_whiteboard>
          
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>ruth@gentoo.org</reporter>
          <assigned_to>security@gentoo.org</assigned_to>
          <cc>agriffis@gentoo.org</cc>

      

      
          <long_desc isprivate="0">
            <who>ruth@gentoo.org</who>
            <bug_when>2004-11-11 11:00:31 0000</bug_when>
            <thetext>hi,
i have found a tempfile vulnerability in the utility znew, part of app-arch/gzip

affected code in znew.in:

-- snip --

warn=&quot;(does not preserve modes and timestamp)&quot;
tmp=/tmp/zfoo.$$
set -C
echo hi &gt; $tmp.1 || exit 1
echo hi &gt; $tmp.2 || exit 1
if test -z &quot;`(${CPMOD-cpmod} $tmp.1 $tmp.2) 2&gt;&amp;1`&quot;; then
  cpmod=${CPMOD-cpmod}
  warn=&quot;&quot;
fi

-- snap --

as you can see, the temporary file is created highly insecure. (derived from the pid!!!)
therefore, an attacker can create a link for example to shadow or passwd and overwrite that file.

attached is a diff, that resolves this issue

best regards
florian</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>ruth@gentoo.org</who>
            <bug_when>2004-11-11 11:01:40 0000</bug_when>
            <thetext>Created an attachment (id=43732)
...the patch...
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2004-11-11 11:37:55 0000</bug_when>
            <thetext>Audit please confirm.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-11-11 17:14:38 0000</bug_when>
            <thetext>Patch looks good. Please add security-audit@ to the CC: when your wanting somebody from that team to confirm something in the future.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-11-11 17:17:37 0000</bug_when>
            <thetext>Anybody what what might call znew in our build system? (ebuilds, runtime or otherwise)</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vapier@gentoo.org</who>
            <bug_when>2004-11-11 19:57:01 0000</bug_when>
            <thetext>also review Bug 70277</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>ruth@gentoo.org</who>
            <bug_when>2004-11-11 23:07:12 0000</bug_when>
            <thetext>hi, i have revieved the Bug 70277:

i guess, the problem is here:
line 37:
tmp=`tempfile -d /tmp -p gz` || {
...
this actually _creates_ a temporary file...
and this behaviour of tempfile is the reason, why
line 53:
gzip -cdfq &quot;$2&quot; &gt; $tmp || exit
(correctly) refuses to extract to an existing file...

solution:

one could unlink the tempfile after creating it with tempfile
note, that this solution would introduce (theoretically) a race condition...
(an attacker knows the tempfilename after unlinking and _before_ actually writing to that file)
as gzip refuses to extract, if the file already exists, i guess this would be a 
good solution anyways...

further comments?

best regards
florian


</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2004-11-11 23:58:56 0000</bug_when>
            <thetext>Thanks solar noted.

Is this patch acceptable? If so please provide an updated ebuild.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2004-11-16 23:33:23 0000</bug_when>
            <thetext>solar/agriffis if this patch is acceptable please apply it or advise.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-11-17 13:36:14 0000</bug_when>
            <thetext>Old:
gzip-1.3.5-r2 
KEYWORDS=&quot;alpha amd64 arm hppa ia64 mips ppc ppc64 s390 sh sparc x86&quot;

New:
gzip-1.3.5-r3 
KEYWORDS=&quot;~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86&quot;


Changes include only addition of files/gzip-1.3.5-znew-tempfile.patch from this bug. (Not well tested)</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-11-17 14:22:37 0000</bug_when>
            <thetext>No changes to the patch. If changes are desired, then those changes must be attached here. (I&apos;m thinking that you probably want changes)</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-11-18 02:17:57 0000</bug_when>
            <thetext>Arches, please test znew in gzip-1.3.5-r3 and mark stable.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>gustavoz@gentoo.org</who>
            <bug_when>2004-11-18 03:14:35 0000</bug_when>
            <thetext>sparc stable.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>tester@gentoo.org</who>
            <bug_when>2004-11-18 07:27:38 0000</bug_when>
            <thetext>x86 there</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>lu_zero@gentoo.org</who>
            <bug_when>2004-11-18 08:46:08 0000</bug_when>
            <thetext>ppc too</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>hardave@gentoo.org</who>
            <bug_when>2004-11-18 09:01:15 0000</bug_when>
            <thetext>Stable on mips.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>corsair@gentoo.org</who>
            <bug_when>2004-11-18 11:35:11 0000</bug_when>
            <thetext>stable on ppc64</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>sekretarz@gentoo.org</who>
            <bug_when>2004-11-18 13:24:14 0000</bug_when>
            <thetext>Stable on amd64</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>kloeri@gentoo.org</who>
            <bug_when>2004-11-18 13:50:04 0000</bug_when>
            <thetext>Stable on alpha.
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-11-18 14:00:18 0000</bug_when>
            <thetext>Ready for GLSA
Maybe upstream/vendor-sec sync would be a good idea ?</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-11-22 01:47:26 0000</bug_when>
            <thetext>gzexe has the same predictable tmpfile &quot;vulnerability&quot;.

--------------------------------
echo hi &gt; zfoo1$$ || exit 1
echo hi &gt; zfoo2$$ || exit 1
if test -z &quot;`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2&gt;&amp;1`&quot;; then
  cpmod=${CPMOD-cpmod}
fi
rm -f zfoo[12]$$
--------------------------------

This is CAN-2004-0970 (both znew and gzexe), but our patch can be considered insufficient as it relies on $$ which is quite predictable on most machines. Strange thing being it was considered sufficient for DSA-588-1...

Note: Debian stable and testing are vulnerable to the znew $$ one.
Debian testing is vulnerable to the gzexe $$ one, but Debian stable has a different approach and doesn&apos;t seem vulnerable to that one.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-11-23 00:36:47 0000</bug_when>
            <thetext>Florian : could you extend your patch to improve unpredictability in gzexe as well ?</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-11-23 08:14:51 0000</bug_when>
            <thetext>Downgrading severity</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2004-12-08 00:47:14 0000</bug_when>
            <thetext>Solar since Florian is MIA please advise.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-12-08 07:15:49 0000</bug_when>
            <thetext>Mandrake just has a tmpfile gzip advisory out :
http://www.mandrakesoft.com/security/advisories?name=MDKSA-2004:142

Don&apos;t know if they fix as much as we do... rip the SRPM to find out ?</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>lewk@gentoo.org</who>
            <bug_when>2004-12-08 07:44:12 0000</bug_when>
            <thetext>Mandrake patches:

http://dev.gentoo.org/~lewk/gzip/gzip-1.2.4-gzexe.patch.bz2
http://dev.gentoo.org/~lewk/gzip/gzip-1.2.4a-mktemp.patch.bz2
http://dev.gentoo.org/~lewk/gzip/gzip-1.2.4a-zdiff-CAN-2004-0970.patch
http://dev.gentoo.org/~lewk/gzip/gzip-1.2.4a-znew.patch.bz2</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-12-08 08:56:44 0000</bug_when>
            <thetext>Sorry I&apos;m a little backed up right now. Will review this bug later. 
Side note anything that requires my direct attention should be mailed to me directly for the next few weeks.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-12-12 16:30:23 0000</bug_when>
            <thetext>I remain backed up please have &apos;another dev&apos; review and apply patches.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vapier@gentoo.org</who>
            <bug_when>2004-12-12 20:33:25 0000</bug_when>
            <thetext>gzip-1.2.4-gzexe.patch
 - not applicable to 1.3.5 afaict
gzip-1.2.4a-znew.patch
 - updated our local patch to use this extended version
gzip-1.2.4a-zdiff-CAN-2004-0970.patch
 - this is our gzip-1.3.5-zdiff-tempfile.patch
gzip-1.2.4a-mktemp.patch
 - our deb patch already has this in it</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vapier@gentoo.org</who>
            <bug_when>2004-12-12 20:34:55 0000</bug_when>
            <thetext>ive added 1.3.5-r4 to portage which resolves Bug 70825 and updates the znew patch with the extended mdk version</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-12-13 01:02:40 0000</bug_when>
            <thetext>Arches, please test and mark 1.3.5-r4 stable
Target KEYWORDS=&quot;alpha amd64 arm hppa ia64 mips ppc ppc64 s390 sh sparc x86&quot;
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>dragonheart@gentoo.org</who>
            <bug_when>2004-12-13 03:19:06 0000</bug_when>
            <thetext>ppc stable as requested. the arch race begins again.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>gustavoz@gentoo.org</who>
            <bug_when>2004-12-13 04:57:42 0000</bug_when>
            <thetext>sparc stable.
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>kingtaco@gentoo.org</who>
            <bug_when>2004-12-13 06:52:22 0000</bug_when>
            <thetext>stable on amd64</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-12-13 09:22:01 0000</bug_when>
            <thetext>Hmm the vulnerability in gzexe is still there in 1.3.5-r4 :

------------ snip -----------
echo hi &gt; zfoo1$$ || exit 1
echo hi &gt; zfoo2$$ || exit 1
------------ snip -----------

uncalling arches, the time to produce a updated patch.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vapier@gentoo.org</who>
            <bug_when>2004-12-13 15:37:13 0000</bug_when>
            <thetext>i&apos;m pretty sure it&apos;s not

look up a few lines in gzexe.in:
set -C

that means bash wont clobber files with redirects:
$ [[ -e clobber ]] &amp;&amp; echo f
$ set -C
$ echo f &gt; clobber
$ echo f &gt; clobber
bash: clobber: cannot overwrite existing file</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-12-14 01:21:06 0000</bug_when>
            <thetext>Hmm you&apos;re right. Apparently the vulnerability this bug was originally about is nullified by the set -C thing. Thanks for pointing that out, back to the stable game, sorry for the interference.
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-12-14 04:41:11 0000</bug_when>
            <thetext>Given that the patches present were already sufficiently good, this will be closed without GLSA when all supported arches will have marked stable.

Florian: if you disagree, feel free to reopen this bug... I&apos;m getting tired by those recurring gzip script tmpfile bugs (they just won&apos;t stay dead).</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>gmsoft@gentoo.org</who>
            <bug_when>2004-12-14 06:45:18 0000</bug_when>
            <thetext>Stable on hppa.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>corsair@gentoo.org</who>
            <bug_when>2004-12-14 08:05:41 0000</bug_when>
            <thetext>stable on ppc64</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>kloeri@gentoo.org</who>
            <bug_when>2004-12-14 13:37:41 0000</bug_when>
            <thetext>Stable on alpha.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vapier@gentoo.org</who>
            <bug_when>2004-12-15 16:58:42 0000</bug_when>
            <thetext>arm/ia64/s390/sh/x86 stable</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-12-16 01:16:48 0000</bug_when>
            <thetext>Fixed in all supported arches, and closed without GLSA because it&apos;s a security improvement more than a vulnerability fix.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>hardave@gentoo.org</who>
            <bug_when>2004-12-29 15:27:59 0000</bug_when>
            <thetext>Stable on mips.</thetext>
          </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>43732</attachid>
            <date>2004-11-11 11:01 0000</date>
            <desc>...the patch...</desc>
            <filename>znew-secutity.diff</filename>
            <type>text/plain</type>
            <data encoding="base64">LS0tIC4vem5ldy5pbn4JMjAwNC0xMS0xMSAxOTo0MDozMC4wMDAwMDAwMDAgKzAxMDAKKysrIC4v
em5ldy5pbgkyMDA0LTExLTExIDE5OjUxOjIwLjEwMDY1MDM5MiArMDEwMApAQCAtMTQsMTAgKzE0
LDE1IEBACiAjIGJsb2NrIGlzIHRoZSBkaXNrIGJsb2NrIHNpemUgKGJlc3QgZ3Vlc3MsIG5lZWQg
bm90IGJlIGV4YWN0KQogCiB3YXJuPSIoZG9lcyBub3QgcHJlc2VydmUgbW9kZXMgYW5kIHRpbWVz
dGFtcCkiCi10bXA9L3RtcC96Zm9vLiQkCit0bXA9YHRlbXBmaWxlIC1kIC90bXAgLXAgemZvb2Ag
fHwgeworICAgICAgICBlY2hvICdjYW5ub3QgY3JlYXRlIGEgdGVtcG9yYXJ5IGZpbGUnID4mMgor
ICAgICAgICBleGl0IDEKK30KIHNldCAtQwogZWNobyBoaSA+ICR0bXAuMSB8fCBleGl0IDEKIGVj
aG8gaGkgPiAkdG1wLjIgfHwgZXhpdCAxCit0cmFwICdybSAtZiAkdG1wLjE7IGV4aXQgMicgSFVQ
IElOVCBQSVBFIFRFUk0gMAordHJhcCAncm0gLWYgJHRtcC4yOyBleGl0IDInIEhVUCBJTlQgUElQ
RSBURVJNIDAKIGlmIHRlc3QgLXogImAoJHtDUE1PRC1jcG1vZH0gJHRtcC4xICR0bXAuMikgMj4m
MWAiOyB0aGVuCiAgIGNwbW9kPSR7Q1BNT0QtY3Btb2R9CiAgIHdhcm49IiIK
</data>        

          </attachment>
    </bug>

</bugzilla>