Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 70825 - app-arch/gzip: tempfile vulnerabilities
Summary: app-arch/gzip: tempfile vulnerabilities
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Gentoo Security
URL:
Whiteboard: A? [stable] koon
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-11 11:00 UTC by Florian Schilhabel (RETIRED)
Modified: 2004-12-29 15:27 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
...the patch... (znew-secutity.diff,615 bytes, patch)
2004-11-11 11:01 UTC, Florian Schilhabel (RETIRED)
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Schilhabel (RETIRED) gentoo-dev 2004-11-11 11:00:31 UTC
hi,
i have found a tempfile vulnerability in the utility znew, part of app-arch/gzip

affected code in znew.in:

-- snip --

warn="(does not preserve modes and timestamp)"
tmp=/tmp/zfoo.$$
set -C
echo hi > $tmp.1 || exit 1
echo hi > $tmp.2 || exit 1
if test -z "`(${CPMOD-cpmod} $tmp.1 $tmp.2) 2>&1`"; then
  cpmod=${CPMOD-cpmod}
  warn=""
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
Comment 1 Florian Schilhabel (RETIRED) gentoo-dev 2004-11-11 11:01:40 UTC
Created attachment 43732 [details, diff]
...the patch...
Comment 2 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-11-11 11:37:55 UTC
Audit please confirm.
Comment 3 solar (RETIRED) gentoo-dev 2004-11-11 17:14:38 UTC
Patch looks good. Please add security-audit@ to the CC: when your wanting somebody from that team to confirm something in the future.
Comment 4 solar (RETIRED) gentoo-dev 2004-11-11 17:17:37 UTC
Anybody what what might call znew in our build system? (ebuilds, runtime or otherwise)
Comment 5 SpanKY gentoo-dev 2004-11-11 19:57:01 UTC
also review Bug 70277
Comment 6 Florian Schilhabel (RETIRED) gentoo-dev 2004-11-11 23:07:12 UTC
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 "$2" > $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


Comment 7 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-11-11 23:58:56 UTC
Thanks solar noted.

Is this patch acceptable? If so please provide an updated ebuild.
Comment 8 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-11-16 23:33:23 UTC
solar/agriffis if this patch is acceptable please apply it or advise.
Comment 9 solar (RETIRED) gentoo-dev 2004-11-17 13:36:14 UTC
Old:
gzip-1.3.5-r2 
KEYWORDS="alpha amd64 arm hppa ia64 mips ppc ppc64 s390 sh sparc x86"

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


Changes include only addition of files/gzip-1.3.5-znew-tempfile.patch from this bug. (Not well tested)
Comment 10 solar (RETIRED) gentoo-dev 2004-11-17 14:22:37 UTC
No changes to the patch. If changes are desired, then those changes must be attached here. (I'm thinking that you probably want changes)
Comment 11 Thierry Carrez (RETIRED) gentoo-dev 2004-11-18 02:17:57 UTC
Arches, please test znew in gzip-1.3.5-r3 and mark stable.
Comment 12 Gustavo Zacarias (RETIRED) gentoo-dev 2004-11-18 03:14:35 UTC
sparc stable.
Comment 13 Olivier Crete (RETIRED) gentoo-dev 2004-11-18 07:27:38 UTC
x86 there
Comment 14 Luca Barbato gentoo-dev 2004-11-18 08:46:08 UTC
ppc too
Comment 15 Hardave Riar (RETIRED) gentoo-dev 2004-11-18 09:01:15 UTC
Stable on mips.
Comment 16 Markus Rothe (RETIRED) gentoo-dev 2004-11-18 11:35:11 UTC
stable on ppc64
Comment 17 Karol Wojtaszek (RETIRED) gentoo-dev 2004-11-18 13:24:14 UTC
Stable on amd64
Comment 18 Bryan Østergaard (RETIRED) gentoo-dev 2004-11-18 13:50:04 UTC
Stable on alpha.
Comment 19 Thierry Carrez (RETIRED) gentoo-dev 2004-11-18 14:00:18 UTC
Ready for GLSA
Maybe upstream/vendor-sec sync would be a good idea ?
Comment 20 Thierry Carrez (RETIRED) gentoo-dev 2004-11-22 01:47:26 UTC
gzexe has the same predictable tmpfile "vulnerability".

--------------------------------
echo hi > zfoo1$$ || exit 1
echo hi > zfoo2$$ || exit 1
if test -z "`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2>&1`"; 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't seem vulnerable to that one.
Comment 21 Thierry Carrez (RETIRED) gentoo-dev 2004-11-23 00:36:47 UTC
Florian : could you extend your patch to improve unpredictability in gzexe as well ?
Comment 22 Thierry Carrez (RETIRED) gentoo-dev 2004-11-23 08:14:51 UTC
Downgrading severity
Comment 23 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-12-08 00:47:14 UTC
Solar since Florian is MIA please advise.
Comment 24 Thierry Carrez (RETIRED) gentoo-dev 2004-12-08 07:15:49 UTC
Mandrake just has a tmpfile gzip advisory out :
http://www.mandrakesoft.com/security/advisories?name=MDKSA-2004:142

Don't know if they fix as much as we do... rip the SRPM to find out ?
Comment 26 solar (RETIRED) gentoo-dev 2004-12-08 08:56:44 UTC
Sorry I'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.
Comment 27 solar (RETIRED) gentoo-dev 2004-12-12 16:30:23 UTC
I remain backed up please have 'another dev' review and apply patches.
Comment 28 SpanKY gentoo-dev 2004-12-12 20:33:25 UTC
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
Comment 29 SpanKY gentoo-dev 2004-12-12 20:34:55 UTC
ive added 1.3.5-r4 to portage which resolves Bug 70825 and updates the znew patch with the extended mdk version
Comment 30 Thierry Carrez (RETIRED) gentoo-dev 2004-12-13 01:02:40 UTC
Arches, please test and mark 1.3.5-r4 stable
Target KEYWORDS="alpha amd64 arm hppa ia64 mips ppc ppc64 s390 sh sparc x86"
Comment 31 Daniel Black (RETIRED) gentoo-dev 2004-12-13 03:19:06 UTC
ppc stable as requested. the arch race begins again.
Comment 32 Gustavo Zacarias (RETIRED) gentoo-dev 2004-12-13 04:57:42 UTC
sparc stable.
Comment 33 Mike Doty (RETIRED) gentoo-dev 2004-12-13 06:52:22 UTC
stable on amd64
Comment 34 Thierry Carrez (RETIRED) gentoo-dev 2004-12-13 09:22:01 UTC
Hmm the vulnerability in gzexe is still there in 1.3.5-r4 :

------------ snip -----------
echo hi > zfoo1$$ || exit 1
echo hi > zfoo2$$ || exit 1
------------ snip -----------

uncalling arches, the time to produce a updated patch.
Comment 35 SpanKY gentoo-dev 2004-12-13 15:37:13 UTC
i'm pretty sure it's not

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

that means bash wont clobber files with redirects:
$ [[ -e clobber ]] && echo f
$ set -C
$ echo f > clobber
$ echo f > clobber
bash: clobber: cannot overwrite existing file
Comment 36 Thierry Carrez (RETIRED) gentoo-dev 2004-12-14 01:21:06 UTC
Hmm you'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.
Comment 37 Thierry Carrez (RETIRED) gentoo-dev 2004-12-14 04:41:11 UTC
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'm getting tired by those recurring gzip script tmpfile bugs (they just won't stay dead).
Comment 38 Guy Martin (RETIRED) gentoo-dev 2004-12-14 06:45:18 UTC
Stable on hppa.
Comment 39 Markus Rothe (RETIRED) gentoo-dev 2004-12-14 08:05:41 UTC
stable on ppc64
Comment 40 Bryan Østergaard (RETIRED) gentoo-dev 2004-12-14 13:37:41 UTC
Stable on alpha.
Comment 41 SpanKY gentoo-dev 2004-12-15 16:58:42 UTC
arm/ia64/s390/sh/x86 stable
Comment 42 Thierry Carrez (RETIRED) gentoo-dev 2004-12-16 01:16:48 UTC
Fixed in all supported arches, and closed without GLSA because it's a security improvement more than a vulnerability fix.
Comment 43 Hardave Riar (RETIRED) gentoo-dev 2004-12-29 15:27:59 UTC
Stable on mips.