public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Buffer Overflow Attacks
@ 2001-10-14  5:32 Frank Pilhofer
  2001-10-14  7:33 ` Carlo Wood
  2001-10-14 10:50 ` Florian Weimer
  0 siblings, 2 replies; 13+ messages in thread
From: Frank Pilhofer @ 2001-10-14  5:32 UTC (permalink / raw)
  To: gcc

   Hi,

 beware, the following text contains an idea on a topic that I am not
an expert on and which I have not extensively researched, so it's one
of the usual cases where someone comes along with dangerous half know-
ledge. So ignore me if the following does not make any sense at all.

 A few days ago, I have once again read an article about attacking
systems on the Internet using various kinds of exploits. Seems to me
that apart from braindead administrators, the usual entry into a sys-
tem is by exploiting a buffer overflow error.

 Despite extensive peer review and linkers that warn us about gets(),
new buffer overflow errors in popular software are discovered again
and again.

 If my limited comprehension of this topic is correct, buffer over-
flow exploits are based on the fact that you can overwrite vital parts
like processor registers and a function's return address, which are
stored on the stack just as local variables are.

 So I had the idea whether it would be possible to avoid buffer over-
flow vulnerabilities by using two separate stacks, one for data and
the other for registers and addresses. This is work that could be done
with the compiler and the linker.

 This idea would not work if it is not possible to have two stack seg-
ments. You could place the two parts into different address ranges of
the stack segment, though. If the registers/addresses parts is on a
smaller virtual address, your program would likely run out of real
memory whilst the attacker sends data before the wrap-around occurs
(or fail upon hitting a read-only address).

 Another alternative would be to introduce some randomness in the
usage of stack data. Exploits only work well because we have large
OS distributions that put the same executable onto hundreds of
thousands of machines. But even compiling the same program with
different compiler options makes a difference, e.g. compiling with
or without debugging, invalidating the exploit, doesn't it?

 Some ideas that come to my mind for this topic are e.g. random
padding on the stack (e.g. upon a function call, you add a couple
of bytes more or less), or maybe xor'ing the register values on
the stack with a per-process random number.

 So basically, I am wondering if the compiler could do something to
blunt buffer overflow attacks. I know, that is not the prime purpose
of the compiler but rather the responsibility of the programmer, but
still I find it an attractive idea as a one-step fix for all such
exploits.

 Okay, that's enough for now. If you've read so far, it's either because
there is some sense in my ideas, or because you were getting a good laugh
out of it.

 Any comments?

	Frank



-- 
Frank Pilhofer  ...........................................  fp@fpx.de
A family vacation is when you go away with people you need to get
away from. - Alfred E. Neuman

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Buffer Overflow Attacks
@ 2001-10-14  8:01 dewar
  2001-10-14 10:25 ` Florian Weimer
  0 siblings, 1 reply; 13+ messages in thread
From: dewar @ 2001-10-14  8:01 UTC (permalink / raw)
  To: carlo, fp; +Cc: gcc

<<Because of this, complete new languages have been designed (Java and C#),
which - as a result of that - are considerably slower.  I don't think that
>>

This is misleading, Ada has shown for a long time that bounds checking need
not be that expensive. The performance of Java is not substantially due to
this feature at all. The obvious approach in a compiler to prevent this
kind of error is to generate appropriate runtime checks, and it is by
no means impossible to do this kind of code generation for C (indeed
it can be done already by some C translators). Yes there is overhead, but
probably not significantly more than would occur for the schemes discussed
here (e.g. separated data and control stacks).

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Buffer Overflow Attacks
@ 2001-10-14 12:25 dewar
  0 siblings, 0 replies; 13+ messages in thread
From: dewar @ 2001-10-14 12:25 UTC (permalink / raw)
  To: dewar, fw; +Cc: carlo, fp, gcc

<<According to the language standard, buffer overflow detection for
character pointer types is possible only for buffers which are not
nested in other objects (in struct or union objects).  Overflowing
character buffers has a well-defined effect if the buffer is contained
in an object (and other objects follow the buffer inside this object),
so a C implementation is not free to detect such errors (which is only
possible if the buffer overflow triggers undefined behavior). ;-)
>>

Well there is room for argument on the above analysis (since the standard
does not fully specify how composite types are layed out), but in any case,
it is always just fine to have a switch that requires sensible restrictions
on behavior, regardless of the standard, subsetting is always allowed, and
it is also just fine to compile sensitive code with such a switch and insist
that it conforms to some safe subset.

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Buffer Overflow Attacks
@ 2001-10-18 17:00 mike stump
  2001-10-31 10:01 ` Florian Weimer
  0 siblings, 1 reply; 13+ messages in thread
From: mike stump @ 2001-10-18 17:00 UTC (permalink / raw)
  To: eager, fw; +Cc: gcc, jsm28

> Date: Thu, 18 Oct 2001 15:02:24 -0700
> From: Michael Eager <eager@mvista.com>
> To: Florian Weimer <fw@deneb.enyo.de>
> CC: "Joseph S. Myers" <jsm28@cam.ac.uk>, gcc@gcc.gnu.org

> I think that this is stretching reading of this paragraph.  Creating
> a valid pointer address does not mean that deferencing the pointer is
> defined.

Well, I can't comment on the exact code you gave, but I can comment on
C++ and code like this:

struct foo {
  char c[31];
  int i;
} f;

  *(((char*)&f)+32) and *(((char*)&f)+33) are allowed.

C must have the same rules for this case.  If they don't they got it wrong.

> Referencing these padding bytes is undefined.

Nope.  See above.  Let's suppose that there are 16 bytes of padding in
there.  The two expressions about, must work.

> Indeed, in a hypothetical processor with very fine grained memory
> protection, any padding bytes placed between c and i in the struct
> may be both unreadable and/or unwritable.

Nope.  Cannot be done in C++.  If C doesn't say this, it is wrong.

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Buffer Overflow Attacks
@ 2001-10-31 16:39 mike stump
  0 siblings, 0 replies; 13+ messages in thread
From: mike stump @ 2001-10-31 16:39 UTC (permalink / raw)
  To: fw; +Cc: eager, gcc, jsm28

> To: mike stump <mrs@windriver.com>
> Cc: eager@mvista.com, gcc@gcc.gnu.org, jsm28@cam.ac.uk
> From: Florian Weimer <fw@deneb.enyo.de>
> Date: Wed, 31 Oct 2001 19:23:54 +0100

> So I have to retract my original claim that it was impossible to do
> buffer overflow checks in such cases.  After all, a pointer in
> C-speak (or "address", as in "address-of operator") is not very
> similar to a machine address.

Off Topic: A pointer in C speak is exactly like a machine address.
Please show us C code that shows a difference.  comp.lang.c is a
better place for these types of comments.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2001-10-31 16:39 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-14  5:32 Buffer Overflow Attacks Frank Pilhofer
2001-10-14  7:33 ` Carlo Wood
2001-10-14 10:50 ` Florian Weimer
2001-10-14  8:01 dewar
2001-10-14 10:25 ` Florian Weimer
2001-10-14 11:08   ` Joseph S. Myers
2001-10-14 12:14     ` Florian Weimer
2001-10-14 12:29       ` Joseph S. Myers
2001-10-18 15:02       ` Michael Eager
2001-10-14 12:25 dewar
2001-10-18 17:00 mike stump
2001-10-31 10:01 ` Florian Weimer
2001-10-31 16:39 mike stump

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).