Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 179583 - sys-apps/file Buffer overflow (CVE-2007-2799)
Summary: sys-apps/file Buffer overflow (CVE-2007-2799)
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All Linux
: High major (vote)
Assignee: Gentoo Security
URL: https://bugzilla.redhat.com/bugzilla/...
Whiteboard: A2 [glsa] jaervosz
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-23 21:04 UTC by Sune Kloppenborg Jeppesen
Modified: 2007-06-24 23:27 UTC (History)
3 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sune Kloppenborg Jeppesen gentoo-dev 2007-05-23 21:04:49 UTC
Seems like the fix to CVE-2007-1536 introduced another issue:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

=============================================================================
FreeBSD-SA-07:04.file                                       Security Advisory
                                                          The FreeBSD Project

Topic:          Heap overflow in file(1)

Category:       contrib
Module:         file
Announced:      2007-05-23
Affects:        All FreeBSD releases.
Corrected:      2007-05-23 16:12:51 UTC (RELENG_6, 6.2-STABLE)
                2007-05-23 16:13:07 UTC (RELENG_6_2, 6.2-RELEASE-p5)
                2007-05-23 16:13:20 UTC (RELENG_6_1, 6.1-RELEASE-p17)
                2007-05-23 16:12:10 UTC (RELENG_5, 5.5-STABLE)
                2007-05-23 16:12:35 UTC (RELENG_5_5, 5.5-RELEASE-p13)
CVE Name:       CVE-2007-1536

For general information regarding FreeBSD Security Advisories,
including descriptions of the fields above, security branches, and the
following sections, please visit <URL:http://security.FreeBSD.org/>.

I.   Background

The file(1) utility attempts to classify file system objects based on
filesystem, magic number and language tests.

The libmagic(3) library provides most of the functionality of file(1)
and may be used by other applications.

II.  Problem Description

When writing data into a buffer in the file_printf function, the length
of the unused portion of the buffer is not correctly tracked, resulting
in a buffer overflow when processing certain files.

III. Impact

An attacker who can cause file(1) to be run on a maliciously constructed
input can cause file(1) to crash.  It may be possible for such an attacker
to execute arbitrary code with the privileges of the user running file(1).

The above also applies to any other applications using the libmagic(3)
library.

IV.  Workaround

No workaround is available, but systems where file(1) and other
libmagic(3)-using applications are never run on untrusted input are not
vulnerable.

V.   Solution

Perform one of the following:

1) Upgrade your vulnerable system to 5-STABLE, or 6-STABLE, or to the
RELENG_6_2, RELENG_6_1, or RELENG_5_5 security branch dated after the
correction date.

2) To patch your present system:

The following patches have been verified to apply to FreeBSD 5.5, 6.1,
and 6.2 systems.

a) Download the relevant patch from the location below, and verify the
detached PGP signature using your PGP utility.

[FreeBSD 5.5]
# fetch http://security.FreeBSD.org/patches/SA-07:04/file5.patch
# fetch http://security.FreeBSD.org/patches/SA-07:04/file5.patch.asc

[FreeBSD 6.1 and 6.2]
# fetch http://security.FreeBSD.org/patches/SA-07:04/file6.patch
# fetch http://security.FreeBSD.org/patches/SA-07:04/file6.patch.asc

b) Execute the following commands as root:

# cd /usr/src
# patch < /path/to/patch
# cd /usr/src/lib/libmagic
# make obj && make depend && make && make install

VI.  Correction details

The following list contains the revision numbers of each file that was
corrected in FreeBSD.

Branch                                                           Revision
  Path
- -------------------------------------------------------------------------
RELENG_5
  src/contrib/file/file.h                                     1.1.1.7.2.1
  src/contrib/file/funcs.c                                    1.1.1.1.2.1
  src/contrib/file/magic.c                                    1.1.1.1.2.1
RELENG_5_5
  src/UPDATING                                            1.342.2.35.2.13
  src/sys/conf/newvers.sh                                  1.62.2.21.2.15
  src/contrib/file/file.h                                     1.1.1.7.8.1
  src/contrib/file/funcs.c                                    1.1.1.1.8.1
  src/contrib/file/magic.c                                    1.1.1.1.8.1
RELENG_6
  src/contrib/file/file.h                                     1.1.1.8.2.1
  src/contrib/file/funcs.c                                    1.1.1.2.2.1
  src/contrib/file/magic.c                                    1.1.1.2.2.1
RELENG_6_2
  src/UPDATING                                             1.416.2.29.2.8
  src/sys/conf/newvers.sh                                   1.69.2.13.2.8
  src/contrib/file/file.h                                     1.1.1.8.8.1
  src/contrib/file/funcs.c                                    1.1.1.2.8.1
  src/contrib/file/magic.c                                    1.1.1.2.8.1
RELENG_6_1
  src/UPDATING                                            1.416.2.22.2.19
  src/sys/conf/newvers.sh                                  1.69.2.11.2.19
  src/contrib/file/file.h                                     1.1.1.8.6.1
  src/contrib/file/funcs.c                                    1.1.1.2.6.1
  src/contrib/file/magic.c                                    1.1.1.2.6.1
- -------------------------------------------------------------------------

VII. References

http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-1536

The latest revision of this advisory is available at
http://security.FreeBSD.org/advisories/FreeBSD-SA-07:04.file.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFGVGjhFdaIBMps37IRAgogAJ9o/0yCxtRi527rgvhg/BoC/AvEsQCfcwMX
ABl7JIb1XiY6QKWQ6UfwlGA=
=meQ0
-----END PGP SIGNATURE-----
Comment 1 Roy Marples (RETIRED) gentoo-dev 2007-05-24 01:30:11 UTC
I got this email earlier today and my first thought was dupe :)

*** This bug has been marked as a duplicate of bug 171452 ***
Comment 2 Sune Kloppenborg Jeppesen gentoo-dev 2007-05-24 06:05:15 UTC
It's not a dupe. The patch for CVE-2007-1536 introduced another issue. Information from Redhat bug:

Colin Percival discovered that the fix for CVE-2007-1536 created an integer
overflow flaw in file.  This new flaw has been assigned CVE-2007-2799.

Here is the information from Colin:

+       len = ms->o.size - ms->o.left;
+       /* * 4 is for octal representation, + 1 is for NUL */
+       psize = len * 4 + 1;
+       assert(psize > len);

On a 32-bit system, if len is 1.35GB, len * 4 + 1 = 5.4GB == 1.4GB, so
the assert will pass.  The buffer will then be overflowed (by as much
as the attacker wants, although of course he'll run into unwriteable
addresses eventually).  This looks pretty exploitable...

I think the right solution is to apply
-       assert(psize > len);
+       if (len > (SIZE_T_MAX - 1) / 4) {
+               file_oomem(ms);
+               return NULL;
+       }
and add
#include <limits.h> to the top (in place of the #include <assert.h> which
the earlier patch adds).
Comment 3 solar (RETIRED) gentoo-dev 2007-05-24 06:17:32 UTC
This needs to be fixed. The fix for the last two bumps were bogus. 
Somewhat a shame fbsd had to figure this out and our own people did not. 
Credits to the fbsd team.
Comment 4 SpanKY gentoo-dev 2007-05-25 04:13:18 UTC
file-4.21 is in portage
Comment 5 Sune Kloppenborg Jeppesen gentoo-dev 2007-05-25 06:35:20 UTC
Thx Mike. Arches please test and mark stable. Target keywords are:

file-4.21.ebuild:KEYWORDS="alpha amd64 arm hppa ia64 m68k mips ppc ppc64 s390 sh sparc ~sparc-fbsd x86 ~x86-fbsd"
Comment 6 Jeroen Roovers (RETIRED) gentoo-dev 2007-05-25 07:01:14 UTC
Stable for HPPA.
Comment 7 Christian Faulhammer (RETIRED) gentoo-dev 2007-05-25 07:45:36 UTC
x86/amd64 stable
Comment 8 Raúl Porcel (RETIRED) gentoo-dev 2007-05-25 11:02:06 UTC
alpha/ia64 stable
Comment 9 Brent Baude (RETIRED) gentoo-dev 2007-05-25 14:04:11 UTC
ppc64 stable
Comment 10 Tobias Scherbaum (RETIRED) gentoo-dev 2007-05-25 17:57:18 UTC
ppc stable
Comment 11 Gustavo Zacarias (RETIRED) gentoo-dev 2007-05-28 12:29:50 UTC
sparc stable.
Comment 12 Raphael Marichez (Falco) (RETIRED) gentoo-dev 2007-06-01 07:13:50 UTC
200705-25, thanks everybody
Comment 13 Joshua Kinard gentoo-dev 2007-06-02 00:57:49 UTC
mips stable.
Comment 14 Sune Kloppenborg Jeppesen gentoo-dev 2007-06-06 20:02:06 UTC
*** Bug 181099 has been marked as a duplicate of this bug. ***