Re: Stack growth direction to thwart buffer overflow attacks

From: Bill Unruh (unruh_at_string.physics.ubc.ca)
Date: 08/14/03


Date: Thu, 14 Aug 2003 16:50:40 +0000 (UTC)

nmm1@cus.cam.ac.uk (Nick Maclaren) writes:

]That is not so. We could remove almost all, but such things are
]an inherent problem in languages like C and C++.

]Replacing sprintf by snprintf etc. does VERY little good unless
]you can GUARANTEE that the length passed to the latter is the
]correct one, is maintained correctly as the buffer is manipulated
]AND there will be no overlaps. So all you are doing is moving the
]problem around. Used appropriately, the strnxxx functions can help
]to reduce buffer overflows, but they are not a solution.

The question is not whether one can produce bug free code. The question is
whether one can produce code is is resistant to outside corruption. Passing the
wrong length to strnxxx is a bug, but it is not one that can usually be
triggered from outside (unless of course you ask the user for the value of n).

Buffer overflow attacks are triggered from outside. Can one write code such
that, assuming the code written is internally bug free, is resistant or imune
from externally (ie using just the input to the code) induced buffer overflows.
It would seem to me that the strnxxxx etc functions are a huge first step.

]Some of the qmail flammifers attacked Exim on this topic a while
]back, basing their claims of Exim's insecurity on the purest dogma.
]I checked the code. All but 6 uses of strcpy (the claimed loophole)
]were obviously safe, 4 took me a minute to check, 1 could cause
]buffer overflow only following a local root compromise, and only 1
]was in any way 'real'. Even that needed a DNS corruption (sic) to
]get past the information calls before there could be any trouble.

]I have also looked at several codes that use strnxxx religiously.
]Checking them was harder than checking Exim, because they were less
]clean. In several cases, there was the potential for buffer
]overflows by confusing the calculation of offsets and lengths,
]such as by triggering undetected overflow.

]TANSTAAFL.

]The ONLY cure is an architected language where either the compiler
]or the program can GUARANTEE to detect such things. There are (at
]least theoretically) such languages, but C and C++ are not in that
]category and cannot practically be extended or constrained to be
]in it.

]Regards,
]Nick Maclaren.



Relevant Pages

  • Re: Stack growth direction to thwart buffer overflow attacks
    ... ]an inherent problem in languages like C and C++. ... the strnxxx functions can help ... from externally induced buffer overflows. ... ]or the program can GUARANTEE to detect such things. ...
    (comp.security.misc)
  • Re: Are bad developer libraries the problem with M$ software?
    ... No buffer overflows *there*... ... > Except now I'm vulnerable to cross-site scripting:) ... to DoS attacks. ... Also "scripting" languages (those which make extensive use of textual ...
    (SecProg)
  • Re: Microsoft Java almost gone in Vista
    ... virtual machine architecture are nice too - e.g. buffer overflows are much less viable. ... But there are actual non VM languages that also ... protects against it. ...
    (comp.lang.java.programmer)
  • Re: Why C Is Not My Favourite Programming Language
    ... >> I find it hard to believe there are more buffer overflows in C ... >> than there are in assembly programs. ... languages, allthough C has more conzepts to write such code than other ... Kind regards, ...
    (comp.lang.c)