2015-08-31 21:01:19

by Andy Lutomirski

[permalink] [raw]
Subject: Why is irq_stack_union a union?

Why not just a struct?

Also, why is this all tangled up in gsbase initialization? And why
does irq_stack_ptr point 64 bytes from the top? And why does the
stack overflow thing look STACK_TOP_MARGIN == 128 bytes from the top?

Confused.

--Andy

--
Andy Lutomirski
AMA Capital Management, LLC


2015-08-31 21:47:48

by Brian Gerst

[permalink] [raw]
Subject: Re: Why is irq_stack_union a union?

On Mon, Aug 31, 2015 at 5:00 PM, Andy Lutomirski <[email protected]> wrote:
> Why not just a struct? Also, why is this all tangled up in gsbase initialization?

It has to do with the fact that the GCC stackprotector is hardcoded to
look for the canary at %gs:40. Since we also use %gs for the percpu
segment, we have to make sure that the canary is placed at the start
of the percpu section. Overlaying it onto the bottom of the IRQ stack
and was the most convenient way to do it, with a side benefit that
overflowing the stack will trip the canary.

--
Brian Gerst

2015-08-31 22:02:00

by Andy Lutomirski

[permalink] [raw]
Subject: Re: Why is irq_stack_union a union?

On Mon, Aug 31, 2015 at 2:47 PM, Brian Gerst <[email protected]> wrote:
> On Mon, Aug 31, 2015 at 5:00 PM, Andy Lutomirski <[email protected]> wrote:
>> Why not just a struct? Also, why is this all tangled up in gsbase initialization?
>
> It has to do with the fact that the GCC stackprotector is hardcoded to
> look for the canary at %gs:40. Since we also use %gs for the percpu
> segment, we have to make sure that the canary is placed at the start
> of the percpu section. Overlaying it onto the bottom of the IRQ stack
> and was the most convenient way to do it, with a side benefit that
> overflowing the stack will trip the canary.

Would a struct not make more sense, then?

--Andy

>
> --
> Brian Gerst



--
Andy Lutomirski
AMA Capital Management, LLC

2015-09-01 03:55:56

by Brian Gerst

[permalink] [raw]
Subject: Re: Why is irq_stack_union a union?

On Mon, Aug 31, 2015 at 6:01 PM, Andy Lutomirski <[email protected]> wrote:
> On Mon, Aug 31, 2015 at 2:47 PM, Brian Gerst <[email protected]> wrote:
>> On Mon, Aug 31, 2015 at 5:00 PM, Andy Lutomirski <[email protected]> wrote:
>>> Why not just a struct? Also, why is this all tangled up in gsbase initialization?
>>
>> It has to do with the fact that the GCC stackprotector is hardcoded to
>> look for the canary at %gs:40. Since we also use %gs for the percpu
>> segment, we have to make sure that the canary is placed at the start
>> of the percpu section. Overlaying it onto the bottom of the IRQ stack
>> and was the most convenient way to do it, with a side benefit that
>> overflowing the stack will trip the canary.
>
> Would a struct not make more sense, then?

Why would it? A union shows the overlay better.

--
Brian Gerst