Buffer Overflow Errors

R

Robert Mark Bram

Hi All!

I have been reading recently about the 'NX' or "No Execute" technology chip
makers are using to prevent buffer overflow errors. The central idea is that
it allows the OS to automatically kill any process that begins writing
outside its own memory. The article I read said there is a danger with this
at the moment: a lot of 'legitimate code' (i.e. apps that are not viruses)
have buffer overruns for reasons such as sloppy programming, deadlines that
are too tight etc..

My question: does Java suffer from buffer overrun errors?

What about other OO capable languages: C++/C#/.NET etc?

Is it only C code that is worrying?

Rob
:)
 
L

Liz

Robert Mark Bram said:
Hi All!

I have been reading recently about the 'NX' or "No Execute" technology chip
makers are using to prevent buffer overflow errors. The central idea is that
it allows the OS to automatically kill any process that begins writing
outside its own memory. The article I read said there is a danger with this
at the moment: a lot of 'legitimate code' (i.e. apps that are not viruses)
have buffer overruns for reasons such as sloppy programming, deadlines that
are too tight etc..

My question: does Java suffer from buffer overrun errors?

What about other OO capable languages: C++/C#/.NET etc?

Is it only C code that is worrying?

Rob
:)
java b good 4 this.
 
T

Tony Morris

What about other OO capable languages: C++/C#/.NET etc?
Is it only C code that is worrying?

Both Java and managed C# (as opposed to unmanaged C#) in theory are not
supposed to allow the developer to access memory in a way that you describe.
C and C++ both allow the programmer to access any piece of memory anywhere.
The fact that a language is object-oriented does not excuse it from being
capable of writing to memory that is outside of its space - the memory
management model of the language is more relevant.
 
L

Liz

Tony Morris said:
Both Java and managed C# (as opposed to unmanaged C#) in theory are not
supposed to allow the developer to access memory in a way that you
describe.

Close, if I remember right, there is something that you can set
in C# that turns off the run time check for array out of bounds.
 
B

blmblm

Hi All!

I have been reading recently about the 'NX' or "No Execute" technology chip
makers are using to prevent buffer overflow errors. The central idea is that
it allows the OS to automatically kill any process that begins writing
outside its own memory.

I don't know anything about "No Execute" technology, but this
description doesn't sound quite right.

Keeping a process from writing "outside its own memory" (e.g.,
writing to memory that belongs to another process) is a good thing
(usually called "memory protection" AFAIK), but it does not prevent
all buffer overflows, since it's possible to overflow a buffer without
writing outside the process's memory.

I think a distinction can usefully be made between two cases.
Let's talk about these in terms of trying to access element N of
an array of length 100. Most programming languages I know of store
arrays as contiguous chunks of memory (N * size of element here) and
compute the address of element N by multiplying N by the size of an
array element and adding that to the address of the start of the array.

One case: N is some really big number. Then the computed address will
likely be outside the bounds of the program's memory, and the system's
normal memory protection (combination of hardware and operating system
features) should result in the program being killed.

Another case: N=105. The computed address will be a little past
the end of the array. It's possible it will be outside the bounds of
the program's memory, but it's more likely that it won't, but instead
will be associated with some other program variable. If the program
is doing array bounds checking, it will recognize that this is an
out-of-bounds access and do something (throw an exception, e.g.).
If the program isn't doing array bounds checking, it will just
silently write to the address, thereby changing the value of the
other variable. Results vary but can include tricking the program
into executing virus-type code.

The first case is already addressed by memory-protection features.

Probably this new technology attempts to address a subset of the
second case. (Notice too that it may not be all that new -- I vaguely
remember hearing that some systems of the past tried to offer similar
protections.)
The article I read said there is a danger with this
at the moment: a lot of 'legitimate code' (i.e. apps that are not viruses)
have buffer overruns for reasons such as sloppy programming, deadlines that
are too tight etc..

My question: does Java suffer from buffer overrun errors?

In theory, no. Java is supposed to always perform array bounds
checking, and you can't get around it with creative pointer arithmetic
because Java doesn't do the kind of general-purpose pointer arithmetic
that would make it possible.
What about other OO capable languages: C++/C#/.NET etc?

No idea about C# or .NET, but C++ certainly makes buffer overruns
possible -- no automatic array bounds checking, and many ways to
use pointers that could result in buffer overruns or similar problems.
Is it only C code that is worrying?

No, though it has a reputation for encouraging programming habits that
make buffer overruns possible. You *can* do array bounds checking in
C, but you might have to put it in yourself, and people often don't.
I used to write in Fortran, which has similar issues, and after a
few years of tracking down "interesting" bugs caused by other people
not putting array bounds checking in their code, I learned ....
 
M

Michael Borgwardt

I don't know anything about "No Execute" technology, but this
description doesn't sound quite right.
Indeed.

Keeping a process from writing "outside its own memory" (e.g.,
writing to memory that belongs to another process) is a good thing
(usually called "memory protection" AFAIK), but it does not prevent
all buffer overflows, since it's possible to overflow a buffer without
writing outside the process's memory.

Actually, an intentional malicious buffer overflow *never* writes outside
the process memory, because that would mean an immediate SIG11, i.e. the
exploit would not work.
I think a distinction can usefully be made between two cases. []
Another case: N=105. The computed address will be a little past
the end of the array. It's possible it will be outside the bounds of
the program's memory, but it's more likely that it won't, but instead
will be associated with some other program variable. If the program
is doing array bounds checking, it will recognize that this is an
out-of-bounds access and do something (throw an exception, e.g.).
If the program isn't doing array bounds checking, it will just
silently write to the address, thereby changing the value of the
other variable. Results vary but can include tricking the program
into executing virus-type code.

Usually by overflowing the array (which is a local variale on the stack)
in such a way that the data overwrites the return adress (also on the
stack) to point inside the array, causing the CPU to execute the data
inside the array as instructions.
Probably this new technology attempts to address a subset of the
second case.

Indeed it does, by marking the stack as "data memory", which the CPU will
then refuse to treat as executable code.
 
K

Kevin McMurtrie

Robert Mark Bram said:
Hi All!

I have been reading recently about the 'NX' or "No Execute" technology chip
makers are using to prevent buffer overflow errors. The central idea is that
it allows the OS to automatically kill any process that begins writing
outside its own memory. The article I read said there is a danger with this
at the moment: a lot of 'legitimate code' (i.e. apps that are not viruses)
have buffer overruns for reasons such as sloppy programming, deadlines that
are too tight etc..

My question: does Java suffer from buffer overrun errors?

What about other OO capable languages: C++/C#/.NET etc?

Is it only C code that is worrying?

Rob
:)

The Java language can not suffer from buffer overruns but the JVM and
custom JNI code could.

The "NX" technology is a bunch of crap. Many exploits rely on poorly
designed features which provide inadequately restricted access, not
injection of executable code into data space. Buffer overruns that
attack stack variables to alter program behaviour, without changing
executable code, will continue to work under NX too.
 
L

Liz

Tony Morris said:
No there isn't.
Perhaps you are confusing the fact that C# provides for true
multi-dimensional arrays where Java doesn't

Ok, I confess that I didn't buy a C# compiler, but my book
"C# in a nutshell" says there is a keyword "unsafe" that you
can use to turn off the check. Maybe if you have a compiler you
can try it and provide us with a demo.
 
T

Tony Morris

Liz said:
Ok, I confess that I didn't buy a C# compiler, but my book
"C# in a nutshell" says there is a keyword "unsafe" that you
can use to turn off the check. Maybe if you have a compiler you
can try it and provide us with a demo.

Without going into detail, the unsafe keyword does a lot more than that.
"Unsafe C#" (more often referred to as unmanaged code) is analogous to
Java's JNI.
It allows the use of pointers, etc. and has the intention of allowing
existing C/C++ users to migrate over to C# i.e. run C/C++ native code from
C#.

The /unsafe compiler switch says "I know that this code does its own memory
management (etc.) and doesn't fit into the typical .NET model, but I'm
willing to accept that".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top