Chess007
07-20-2006, 06:44 PM
This idea sounded like a great way to stop the security issues that are associated with buffer overflows. I'm looking for some opinions on it.
Leo: But he did have a question. He said: When it comes to the stack, why did it have to write up? Wouldn’t it be more secure to write down? Or is there something more complicated going on with that?
Steve: Okay, now, I didn’t quite get his question.
Leo: He’s talking about why does it go up in memory instead of down in memory. But I don’t think it makes any difference, does it?
Steve: Well, actually there’s something brilliant about this.
Leo: Oh.
Steve: Which I really liked. First of all, he says, why does it write up, meaning why does your – when you’re overflowing the buffer, you’re going from lower memory to higher memory.
Leo: Right.
Steve: And that’s writing up the stack, and that’s overwriting the stuff that’s higher in the stack, which is critical information from previous programs or previous subroutines. Because as we remember from last week, the stack grows downwards. Well, his point was, if buffers overflowed the other direction, then they wouldn’t be overwriting the previous information, they’d just be writing – they’d be overwriting stuff that wasn’t allocated yet on the stack. Well, he’s completely correct. Now, of course...
Leo: So why don’t they do it that way?
Steve: Exactly. I mean, they should. I mean, I love the question. It’s brilliant.
Leo: Wait a minute. Wait a minute. Now, come on. You’re turning years of computer science on its head. Literally.
Steve: Well, okay, now. First of all, it’s not easy from a practical standpoint to fill buffers downward. That is, you know, just everything about the way we think has a buffer being filled from lower memory to higher memory.
Leo: But even if you did that, you would still overwrite – you could overwrite in the negative numbers.
Steve: Well, but hold on. But if the stack instead started at the bottom and grew upwards...
Leo: Yeah.
Steve: ...and there’s no reason it can’t, if the stack started at the bottom and grew upwards...
Leo: So you’re saying if it started at memory location zero...
Steve: Or, well, zero, not everybody can start at zero.
Leo: Not really zero.
Steve: Yeah.
Leo: Let’s say whatever zero is, some arbitrary zero.
Steve: Yes. And then allocating memory on the stack you do by moving your stack pointer up to, like, a certain amount. Now, what’s happened is you’ve reserved all of that memory below that point for your own use. Anybody else who wants some, they move the pointer up, and now they have – they’ve reserved that region that they just moved the pointer across for their own purpose. And the beauty of this is, the person who is currently using the stack, so-called is like on the top of the stack. And if stacks grew from the bottom up instead of from the top down, then buffer overruns would overrun out into unused stack space, not already used stack space. It’s brilliant. I mean, it would really work. And it would solve the problem.
Leo: Somehow I think there’s more to it than that, but all right. If it were that simple, wouldn’t somebody have done this?
Steve: No. Because, again – no, I mean, I...
Leo: All of this was set up long before this ever became a problem.
Steve: Exactly. That’s exactly it, Leo, is that it’s a little more elegant from an architectural standpoint to have, for reasons that are sort of complicated and deal with the way pointers are handled, to have the stack growing down from the top of memory is architecturally simpler. But it was just done that way basically as an arbitrary choice. Someone said, shall we have it come down from the top or up from the bottom? And it’s a little simpler to have it come down from the top. But in terms of the problems that it creates, the idea that overrunning the allocation, if you’re coming down from the top, you’re inherently overwriting the information of someone who’s already allocated information on the stack before you.
Leo: Right. Somebody else’s stack frame.
Steve: Somebody else’s stack, exactly. But literally, if you allocate instead from the bottom up, you don’t overrun. It’s wonderful.
Source:
http://www.grc.com/sn/SN-040.htm
My question is, would that work? Is it possible? Thoughts/opinions?
Leo: But he did have a question. He said: When it comes to the stack, why did it have to write up? Wouldn’t it be more secure to write down? Or is there something more complicated going on with that?
Steve: Okay, now, I didn’t quite get his question.
Leo: He’s talking about why does it go up in memory instead of down in memory. But I don’t think it makes any difference, does it?
Steve: Well, actually there’s something brilliant about this.
Leo: Oh.
Steve: Which I really liked. First of all, he says, why does it write up, meaning why does your – when you’re overflowing the buffer, you’re going from lower memory to higher memory.
Leo: Right.
Steve: And that’s writing up the stack, and that’s overwriting the stuff that’s higher in the stack, which is critical information from previous programs or previous subroutines. Because as we remember from last week, the stack grows downwards. Well, his point was, if buffers overflowed the other direction, then they wouldn’t be overwriting the previous information, they’d just be writing – they’d be overwriting stuff that wasn’t allocated yet on the stack. Well, he’s completely correct. Now, of course...
Leo: So why don’t they do it that way?
Steve: Exactly. I mean, they should. I mean, I love the question. It’s brilliant.
Leo: Wait a minute. Wait a minute. Now, come on. You’re turning years of computer science on its head. Literally.
Steve: Well, okay, now. First of all, it’s not easy from a practical standpoint to fill buffers downward. That is, you know, just everything about the way we think has a buffer being filled from lower memory to higher memory.
Leo: But even if you did that, you would still overwrite – you could overwrite in the negative numbers.
Steve: Well, but hold on. But if the stack instead started at the bottom and grew upwards...
Leo: Yeah.
Steve: ...and there’s no reason it can’t, if the stack started at the bottom and grew upwards...
Leo: So you’re saying if it started at memory location zero...
Steve: Or, well, zero, not everybody can start at zero.
Leo: Not really zero.
Steve: Yeah.
Leo: Let’s say whatever zero is, some arbitrary zero.
Steve: Yes. And then allocating memory on the stack you do by moving your stack pointer up to, like, a certain amount. Now, what’s happened is you’ve reserved all of that memory below that point for your own use. Anybody else who wants some, they move the pointer up, and now they have – they’ve reserved that region that they just moved the pointer across for their own purpose. And the beauty of this is, the person who is currently using the stack, so-called is like on the top of the stack. And if stacks grew from the bottom up instead of from the top down, then buffer overruns would overrun out into unused stack space, not already used stack space. It’s brilliant. I mean, it would really work. And it would solve the problem.
Leo: Somehow I think there’s more to it than that, but all right. If it were that simple, wouldn’t somebody have done this?
Steve: No. Because, again – no, I mean, I...
Leo: All of this was set up long before this ever became a problem.
Steve: Exactly. That’s exactly it, Leo, is that it’s a little more elegant from an architectural standpoint to have, for reasons that are sort of complicated and deal with the way pointers are handled, to have the stack growing down from the top of memory is architecturally simpler. But it was just done that way basically as an arbitrary choice. Someone said, shall we have it come down from the top or up from the bottom? And it’s a little simpler to have it come down from the top. But in terms of the problems that it creates, the idea that overrunning the allocation, if you’re coming down from the top, you’re inherently overwriting the information of someone who’s already allocated information on the stack before you.
Leo: Right. Somebody else’s stack frame.
Steve: Somebody else’s stack, exactly. But literally, if you allocate instead from the bottom up, you don’t overrun. It’s wonderful.
Source:
http://www.grc.com/sn/SN-040.htm
My question is, would that work? Is it possible? Thoughts/opinions?