Bugtraq mailing list archives
Re: gzip TOCTOU file-permissions vulnerability
From: Derek Martin <code () pizzashack org>
Date: Wed, 13 Apr 2005 21:14:28 -0400
Imran Ghory [2005-04-04 20:57 +0100]:Vulnerable software ==================== gzip 1.2.4 and 1.3.3 and previous versions running on unix. Vulnerability ============== If a malicious local user has write access to a directory in which a target user is using gzip to extract or compress a file to then a TOCTOU bug can be exploited to change the permission of any file belonging to that user. On decompressing gzip copies the permissions from the compressed gzip file to the uncompressed file. However there is a gap between the uncompressed file being written (and it's file handler being close) and the permissions of the file being changed. During this gap a malicious user can remove the decompressed file and replace it with a hard-link to another file belonging to the user. gzip will then change the permissions on the hard-linked file to be the same as that of the gzip file.
Perusing the code seems to reveal that gzip is written this way for no good reason... It may have been to support operating systems which don't allow the third argument of open(), but looking at the code, the only supported OS which doesn't support the modes argument seems to be MacOS (presumably not MacOS X). However MacOS also seems not to support chmod(), so there seems to be little point in separating the two operations... The code already defines the OPEN macro which either uses or ignores the third (modes) argument to open() as needed. Therefore the attached patch should apply to gzip 1.2.4 (and quite probably to 1.3.x as well) and fix the problem. N.B.: I didn't actually test the patch, but it looks right to me. Yeah, I'm that lazy... =8^) -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0x81CFE75D
Attachment:
gzip-atomic-modes.patch
Description:
Attachment:
_bin
Description:
Current thread:
- gzip TOCTOU file-permissions vulnerability Imran Ghory (Apr 05)
- Re: gzip TOCTOU file-permissions vulnerability Martin Pitt (Apr 13)
- Re: gzip TOCTOU file-permissions vulnerability Derek Martin (Apr 13)
- Re: gzip TOCTOU file-permissions vulnerability Peter J. Holzer (Apr 13)
- Re: gzip TOCTOU file-permissions vulnerability Joey Hess (Apr 13)
- Re: gzip TOCTOU file-permissions vulnerability psz (Apr 14)
- Re: gzip TOCTOU file-permissions vulnerability Theodor Milkov (Apr 15)
- Re: gzip TOCTOU file-permissions vulnerability Derek Martin (Apr 14)
- <Possible follow-ups>
- RE: gzip TOCTOU file-permissions vulnerability Mark Senior (Apr 14)
- Re: gzip TOCTOU file-permissions vulnerability Derek Martin (Apr 14)
- Re: gzip TOCTOU file-permissions vulnerability devnull (Apr 15)
- Re: gzip TOCTOU file-permissions vulnerability Dmitry Yu. Bolkhovityanov (Apr 16)
- Re: gzip TOCTOU file-permissions vulnerability Peter J. Holzer (Apr 15)
- Re: gzip TOCTOU file-permissions vulnerability Scott Gifford (Apr 15)
- Re: gzip TOCTOU file-permissions vulnerability Steve Grubb (Apr 14)
- Re: gzip TOCTOU file-permissions vulnerability Martin Pitt (Apr 13)