ARM per-thread stack protector

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ARM per-thread stack protector

Will Newton
Hi all,

I've been looking into implementing pre-thread stack protector
canaries for ARM and I would be interested in people's opinions on
whether I have understood it correctly.

At the moment the global canary value is stored in __stack_chk_guard
which is exported by glibc and accesses to this variable are emitted
by gcc if it detects a capable glibc version at configure time.

glibc with per-thread stack canary values does not export
__stack_chk_guard but adds an element to the TCB to contain the
per-thread value and gcc emits TP-relative accesses to load this
value.

Implementing the per-thread scheme would therefore seem to me to break
ABI compatibility and cause problems when mixing gcc and glibc
versions:

Old gcc, old glibc: OK
Old gcc, new glibc: __stack_chk_guard is missing, link time failure.
New gcc, old glibc: stack canary value is loaded from uninitialized
TCB area, security issue.
New gcc, new glibc: OK.

It should be possible to add support for both schemes at the same time
in glibc, exporting __stack_chk_guard at the same time as supporting
per-thread canary values, which would fix the "old gcc, new glibc"
case.

I am not sure if there is a good fix for "new gcc, old glibc",
although gcc configure could be taught about glibc versions and do the
right thing for each.

Or is there a simpler way to handle this? Has any other architecture
implemented per-thread stack protector after already supporting the
simpler scheme?

Thanks,

--
Will Newton
Toolchain Working Group, Linaro
Reply | Threaded
Open this post in threaded view
|

Re: ARM per-thread stack protector

Roland McGrath-4
No machine has a per-thread canary value.  Using one would break
user-implemented stack-switching schemes.

Some machines store the global canary value in every thread's TCB for the
sole reason that it's cheaper to access a field in the TCB than to access a
global variable.  I don't think that's the case on ARM.
Reply | Threaded
Open this post in threaded view
|

Re: ARM per-thread stack protector

Will Newton
On 19 July 2013 22:41, Roland McGrath <[hidden email]> wrote:

Hi Roland,

> No machine has a per-thread canary value.  Using one would break
> user-implemented stack-switching schemes.
>
> Some machines store the global canary value in every thread's TCB for the
> sole reason that it's cheaper to access a field in the TCB than to access a
> global variable.  I don't think that's the case on ARM.

Thanks for the clarification. So the two methods are functionally identical?

I looked at this problem initially after reading Carlos's mail to the
fedora devel list:

http://www.mail-archive.com/devel@.../msg62354.html

From what I understand then all that is missing on ARM from that list
is pointer mangling support?

Thanks,

--
Will Newton
Toolchain Working Group, Linaro
Reply | Threaded
Open this post in threaded view
|

Re: ARM per-thread stack protector

Roland McGrath-4
> Thanks for the clarification. So the two methods are functionally identical?

Yes.  Where you keep the value is just a matter of optimal implementation
convenience for the particular machine.

> >From what I understand then all that is missing on ARM from that list
> is pointer mangling support?

I have no new information.