First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 70825
Alias:
Product:
Component:
Status: RESOLVED
Resolution: FIXED
Assigned To: Gentoo Security <security@gentoo.org>
Hardware:
OS:
Version:
Priority:
Severity:
Reporter: Florian Schilhabel (RETIRED) <ruth@gentoo.org>
Add CC:
CC:
Remove selected CCs
URL:
Summary:
Status Whiteboard:
Keywords:
Flags: Requestee:
 
 
  ()

Filename Description Type Creator Created Size Actions
znew-secutity.diff ...the patch... patch Florian Schilhabel (RETIRED) 2004-11-11 11:01 0000 615 bytes Details | Diff
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 70825 depends on: Show dependency tree
Show dependency graph
Bug 70825 blocks:

Additional Comments: (this is where you put emerge --info)







View Bug Activity   |   Format For Printing   |   XML   |   Clone This Bug


Description:   Opened: 2004-11-11 11:00 0000
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 From Florian Schilhabel (RETIRED) 2004-11-11 11:01:40 0000 -------
Created an attachment (id=43732) [edit]
...the patch...

------- Comment #2 From Sune Kloppenborg Jeppesen 2004-11-11 11:37:55 0000 -------
Audit please confirm.

------- Comment #3 From solar 2004-11-11 17:14:38 0000 -------
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 From solar 2004-11-11 17:17:37 0000 -------
Anybody what what might call znew in our build system? (ebuilds, runtime or
otherwise)

------- Comment #5 From SpanKY 2004-11-11 19:57:01 0000 -------
also review Bug 70277

------- Comment #6 From Florian Schilhabel (RETIRED) 2004-11-11 23:07:12 0000 -------
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 From Sune Kloppenborg Jeppesen 2004-11-11 23:58:56 0000 -------
Thanks solar noted.

Is this patch acceptable? If so please provide an updated ebuild.

------- Comment #8 From Sune Kloppenborg Jeppesen 2004-11-16 23:33:23 0000 -------
solar/agriffis if this patch is acceptable please apply it or advise.

------- Comment #9 From solar 2004-11-17 13:36:14 0000 -------
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 From solar 2004-11-17 14:22:37 0000 -------
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 From Thierry Carrez (RETIRED) 2004-11-18 02:17:57 0000 -------
Arches, please test znew in gzip-1.3.5-r3 and mark stable.

------- Comment #12 From Gustavo Zacarias (RETIRED) 2004-11-18 03:14:35 0000 -------
sparc stable.

------- Comment #13 From Olivier Crete 2004-11-18 07:27:38 0000 -------
x86 there

------- Comment #14 From Luca Barbato 2004-11-18 08:46:08 0000 -------
ppc too

------- Comment #15 From Hardave Riar (RETIRED) 2004-11-18 09:01:15 0000 -------
Stable on mips.

------- Comment #16 From Markus Rothe 2004-11-18 11:35:11 0000 -------
stable on ppc64

------- Comment #17 From Karol Wojtaszek (RETIRED) 2004-11-18 13:24:14 0000 -------
Stable on amd64

------- Comment #18 From Bryan Østergaard (RETIRED) 2004-11-18 13:50:04 0000 -------
Stable on alpha.

------- Comment #19 From Thierry Carrez (RETIRED) 2004-11-18 14:00:18 0000 -------
Ready for GLSA
Maybe upstream/vendor-sec sync would be a good idea ?

------- Comment #20 From Thierry Carrez (RETIRED) 2004-11-22 01:47:26 0000 -------
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 From Thierry Carrez (RETIRED) 2004-11-23 00:36:47 0000 -------
Florian : could you extend your patch to improve unpredictability in gzexe as
well ?

------- Comment #22 From Thierry Carrez (RETIRED) 2004-11-23 08:14:51 0000 -------
Downgrading severity

------- Comment #23 From Sune Kloppenborg Jeppesen 2004-12-08 00:47:14 0000 -------
Solar since Florian is MIA please advise.

------- Comment #24 From Thierry Carrez (RETIRED) 2004-12-08 07:15:49 0000 -------
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 #25 From Luke Macken (RETIRED) 2004-12-08 07:44:12 0000 -------
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

------- Comment #26 From solar 2004-12-08 08:56:44 0000 -------
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 From solar 2004-12-12 16:30:23 0000 -------
I remain backed up please have 'another dev' review and apply patches.

------- Comment #28 From SpanKY 2004-12-12 20:33:25 0000 -------
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 From SpanKY 2004-12-12 20:34:55 0000 -------
ive added 1.3.5-r4 to portage which resolves Bug 70825 and updates the znew
patch with the extended mdk version

------- Comment #30 From Thierry Carrez (RETIRED) 2004-12-13 01:02:40 0000 -------
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 From Daniel Black 2004-12-13 03:19:06 0000 -------
ppc stable as requested. the arch race begins again.

------- Comment #32 From Gustavo Zacarias (RETIRED) 2004-12-13 04:57:42 0000 -------
sparc stable.

------- Comment #33 From Mike Doty 2004-12-13 06:52:22 0000 -------
stable on amd64

------- Comment #34 From Thierry Carrez (RETIRED) 2004-12-13 09:22:01 0000 -------
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 From SpanKY 2004-12-13 15:37:13 0000 -------
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 From Thierry Carrez (RETIRED) 2004-12-14 01:21:06 0000 -------
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 From Thierry Carrez (RETIRED) 2004-12-14 04:41:11 0000 -------
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 From Guy Martin 2004-12-14 06:45:18 0000 -------
Stable on hppa.

------- Comment #39 From Markus Rothe 2004-12-14 08:05:41 0000 -------
stable on ppc64

------- Comment #40 From Bryan Østergaard (RETIRED) 2004-12-14 13:37:41 0000 -------
Stable on alpha.

------- Comment #41 From SpanKY 2004-12-15 16:58:42 0000 -------
arm/ia64/s390/sh/x86 stable

------- Comment #42 From Thierry Carrez (RETIRED) 2004-12-16 01:16:48 0000 -------
Fixed in all supported arches, and closed without GLSA because it's a security
improvement more than a vulnerability fix.

------- Comment #43 From Hardave Riar (RETIRED) 2004-12-29 15:27:59 0000 -------
Stable on mips.

First Last Prev Next    No search results available      Search page      Enter new bug