Date: 09 April 2008
Click here for printable version
Click here for PGP verifiable version
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
===========================================================================
AUSCERT External Security Bulletin Redistribution
ESB-2008.0366 -- [Win][UNIX/Linux]
Vulnerability Note VU#162289 gcc silently discards some wraparound checks
9 April 2008
===========================================================================
AusCERT Security Bulletin Summary
---------------------------------
Product: gcc
Publisher: US-CERT
Operating System: Windows
UNIX variants (UNIX, Linux, OSX)
Impact: Reduced Security
CVE Names: CVE-2008-1685
Original Bulletin: http://www.kb.cert.org/vuls/id/162289
- --------------------------BEGIN INCLUDED TEXT--------------------
Vulnerability Note VU#162289
gcc silently discards some wraparound checks
Overview
Some versions of gcc may silently discard certain checks for overflow.
Applications compiled with these versions of gcc may be vulnerable to
buffer overflows.
I. Description
The GNU Compiler Collection provides a compiler suite for a number of
languages, the most prominent being C (gcc). In gcc versions 4.2 and
later, given the types:
char *buf;
int len;
gcc will assume that buf+len >= buf.
As a result, code that performs length checks similar to the following:
len = 1<<30;
[...]
if(buf+len < buf) /* length check */
[...overflow occurred...]
are compiled away by these versions of gcc; no object code to perform
the check will appear in the resulting executable program. In the case
where the length test expression is compiled away, a subsequent
manipulation of len could cause an overflow. As a result, applications
that perform such checks as a postcondition may be vulnerable to buffer
overflows.
Note: this issue does not strictly constitute a vulnerability in gcc
itself. The behavior that gcc exhibits in this case is permitted
by the ISO/IEC 9899:1999 C specification (§6.5.6p8). Rather, this
behavior may introduce vulnerabilities in applications compiled
with the affected versions of gcc. It must be emphasized that
this is a change of behavior for the compiler. Existing code is
particularly susceptible to this change.
II. Impact
An application which performs bounds checks based on an expression such
as the one described above may be vulnerable to buffer overflow if
compiled with gcc versions 4.2 or later. The nature of the resulting
vulnerability would be specific to the application and depends on how
the affected code is used.
III. Solution
Use casts
Cast objects of type char* to uintptr_t before comparison. The faulty
length check listed above would be written:
#include <stdint.h>
[...]
if((uintptr_t)buf+len < (uintptr_t)buf)
[...]
Alternatively, developers can use size_t on platforms that do not
provide the uintptr_t type. Developers should also follow the
recommendations described in CERT C Secure Coding rule ARR38-C.
Avoid newer versions of gcc
Application developers and vendors of large codebases that cannot be
audited for use of the defective length checks are urged to avoiding
the use of gcc versions 4.2 and later.
Use compiler flags
The gcc compiler provides several flags that may workaround this
condition. The -ftrapv flag will cause a program that uses the
defective test to crash if an overflow occurs. The -fwrapv flag makes
signed arithmetic overflow. It should be noted that both of these
options are somewhat rarely used and it's possible that there are
defects in their implementation. It should also be noted that the use
of -fwrapv may have a negative performance impact on the resulting
program but reduce the likelihood that the offending optimization
will occur.
Systems Affected
No Information Available
References
https://www.securecoding.cert.org/confluence/x/SgHm
Credit
Thanks to Russ Cox for discovering this issue and providing additional
information and assistance.
This document was written by Chad R Dougherty.
Other Information
Date Public 03/30/2008
Date First Published 04/04/2008 09:07:25 AM
Date Last Updated 04/07/2008
CERT Advisory
CVE Name
US-CERT Technical Alerts
Metric 0.00
Document Revision 24
If you have feedback, comments, or additional information about this
vulnerability, please send us email.
- --------------------------END INCLUDED TEXT--------------------
You have received this e-mail bulletin as a result of your organisation's
registration with AusCERT. The mailing list you are subscribed to is
maintained within your organisation, so if you do not wish to continue
receiving these bulletins you should contact your local IT manager. If
you do not know who that is, please send an email to auscert@auscert.org.au
and we will forward your request to the appropriate person.
NOTE: Third Party Rights
This security bulletin is provided as a service to AusCERT's members. As
AusCERT did not write the document quoted above, AusCERT has had no control
over its content. The decision to follow or act on information or advice
contained in this security bulletin is the responsibility of each user or
organisation, and should be considered in accordance with your organisation's
site policies and procedures. AusCERT takes no responsibility for consequences
which may arise from following or acting on information or advice contained in
this security bulletin.
NOTE: This is only the original release of the security bulletin. It may
not be updated when updates to the original are made. If downloading at
a later date, it is recommended that the bulletin is retrieved directly
from the author's website to ensure that the information is still current.
Contact information for the authors of the original document is included
in the Security Bulletin above. If you have any questions or need further
information, please contact them directly.
Previous advisories and external security bulletins can be retrieved from:
http://www.auscert.org.au/render.html?cid=1980
If you believe that your computer system has been compromised or attacked in
any way, we encourage you to let us know by completing the secure National IT
Incident Reporting Form at:
http://www.auscert.org.au/render.html?it=3192
===========================================================================
Australian Computer Emergency Response Team
The University of Queensland
Brisbane
Qld 4072
Internet Email: auscert@auscert.org.au
Facsimile: (07) 3365 7031
Telephone: (07) 3365 4417 (International: +61 7 3365 4417)
AusCERT personnel answer during Queensland business hours
which are GMT+10:00 (AEST).
On call after hours for member emergencies only.
===========================================================================
-----BEGIN PGP SIGNATURE-----
Comment: http://www.auscert.org.au/render.html?it=1967
iQCVAwUBR/xffSh9+71yA2DNAQIUiQQAjyjEWMS3dJjvXYRtbA/5toUXv5ni9UQh
2OvQshzqFJbDX6t7cDgkz7e4ELNYIofUh+qlm18DhjORCk3hFOwIlwuEnqwFWb50
mcf4dfFGPIvIVtBZpWovOsGc2j36aYTvZjdQZ5CRTouH7ll2jZ4c2D/6mzTvKYaB
Zc7gebURznA=
=sVxx
-----END PGP SIGNATURE-----
|