public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH v9 23/42] Documentation/x86: Add CET shadow stack description
       [not found]                 ` <1c0460a2042480b6a2d4cc1f6b99b27ab1371f3a.camel@intel.com>
@ 2023-07-11  8:08                   ` szabolcs.nagy
  2023-07-12  9:39                     ` Szabolcs Nagy
  0 siblings, 1 reply; 2+ messages in thread
From: szabolcs.nagy @ 2023-07-11  8:08 UTC (permalink / raw)
  To: Edgecombe, Rick P, Lutomirski, Andy
  Cc: Xu, Pengfei, tglx, linux-arch, kcc, nadav.amit, kirill.shutemov,
	david, Schimpe, Christina, akpm, peterz, corbet, nd, broonie,
	dethoma, linux-kernel, x86, pavel, bp, debug, linux-api, rppt,
	john.allen, jamorris, rdunlap, mike.kravetz, jannh, oleg,
	andrew.cooper3, keescook, gorcunov, arnd, Yu, Yu-cheng, fweimer,
	hpa, mingo, hjl.tools, bsingharora, linux-mm, Syromiatnikov,
	Eugene, Yang, Weijiang, linux-doc, dave.hansen, Torvalds, Linus,
	Eranian, Stephane, libc-alpha, dalias, branislav.rankov

The 07/10/2023 22:56, Edgecombe, Rick P wrote:
> On Mon, 2023-07-10 at 17:54 +0100, szabolcs.nagy@arm.com wrote:
> > in short the only important change for v1 is shstk sizing.
> 
> I tried searching through this long thread and AFAICT this is a new
> idea. Sorry if I missed something, but your previous answer on this(3)
> seemed concerned with the opposite problem (oversized shadow stacks).
> 
> Quoted from a past mail:
> On Mon, 2023-07-03 at 19:19 +0100, szabolcs.nagy@arm.com wrote:
...
> > - tiny thread stack but big sigaltstack (musl libc, go).

and 4 months earlier:

> Date: Fri, 3 Mar 2023 16:30:37 +0000
> Subject: Re: [PATCH v7 01/41] Documentation/x86: Add CET shadow stack description
> > Looking at this again, I'm not sure why a new rlimit is needed. It
> > seems many of those points were just formulations of that the clone3
> > stack size was not used, but it actually is and just not documented. If
> > you disagree perhaps you could elaborate on what the requirements are
> > and we can see if it seems tricky to do in a follow up.
> 
> - tiny thread stack and deep signal stack.
> (note that this does not really work with glibc because it has
> implementation internal signals that don't run on alt stack,
> cannot be masked and don't fit on a tiny thread stack, but
> with other runtimes this can be a valid use-case, e.g. musl
> allows tiny thread stacks, < pagesize.)
...

that analysis was wrong: it considered handling any signals
at all, but if the stack overflows due to a recursive call
with empty stack frames then the stack gets used up at the
same rate as the shadow stack and since the signal handler
on the alt stack uses the same shadow stack that can easily
overflow too independently of the stack size.

this is a big deal as it affects what operations the libc
can support and handling stack overflow is a common
requirement.

i originally argued for a fix using separate alt shadow
stacks, but since it became clear that does not work for
the x86 v1 abi i am recommending the size increase.

with shadow stack size = stack size + 1 page, libc can
document a depth limit for the alt stack that works.
(longjumping back to the alt stack is still broken
though, but that's rarely a requirement)

> Also glibc would have to size ucontext shadow stacks with an additional

yes, assuming glibc wants to support sigaltstack.

> page as well. I think it would be good to get some other signs of
> interest on this tweak due to the requirements for glibc to participate
> on the scheme. Can you gather that quickly, so we can get this all
> prepped again?

i can cc libc-alpha.

the decision is for x86 shadow stack linux abi to use

  shadow stack size = stack size

or

  shadow stack size = stack size + 1 page

as default policy when alt stack signals use the same
shadow stack, not a separate one.

note: smallest stack frame size is 8bytes, same as the
shadow stack entry. on a target where smallest frame
size is 2x shadow stack entry size, the formula would
use (stack size / 2).

note: there is no api to change the policy from userspace
at this point.

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

* Re: [PATCH v9 23/42] Documentation/x86: Add CET shadow stack description
  2023-07-11  8:08                   ` [PATCH v9 23/42] Documentation/x86: Add CET shadow stack description szabolcs.nagy
@ 2023-07-12  9:39                     ` Szabolcs Nagy
  0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2023-07-12  9:39 UTC (permalink / raw)
  To: Edgecombe, Rick P, Lutomirski, Andy
  Cc: Xu, Pengfei, tglx, linux-arch, kcc, nadav.amit, kirill.shutemov,
	david, Schimpe, Christina, akpm, peterz, corbet, nd, broonie,
	dethoma, linux-kernel, x86, pavel, bp, debug, linux-api, rppt,
	john.allen, jamorris, rdunlap, mike.kravetz, jannh, oleg,
	andrew.cooper3, keescook, gorcunov, arnd, Yu, Yu-cheng, fweimer,
	hpa, mingo, hjl.tools, bsingharora, linux-mm, Syromiatnikov,
	Eugene, Yang, Weijiang, linux-doc, dave.hansen, Torvalds, Linus,
	Eranian, Stephane, libc-alpha, dalias, branislav.rankov

The 07/11/2023 09:08, szabolcs.nagy--- via Libc-alpha wrote:
> the decision is for x86 shadow stack linux abi to use
> 
>   shadow stack size = stack size
> 
> or
> 
>   shadow stack size = stack size + 1 page
> 
> as default policy when alt stack signals use the same
> shadow stack, not a separate one.
> 
> note: smallest stack frame size is 8bytes, same as the
> shadow stack entry. on a target where smallest frame
> size is 2x shadow stack entry size, the formula would
> use (stack size / 2).

i convinced myself that shadow stack size = stack size
works:

libc can reserve N bytes on the initial stack frame so
when the stack overflows there will be at least N bytes
on the shadow stack usable for signal handling.

this is only bad for tiny user allocated stacks where libc
should not consume too much stack space. but e.g. glibc
already uses >128 bytes on the initial stack frame for its
cancellation jumpbuf so 16 deep signal call stack is
already guaranteed to work.

the glibc makecontext code has to be adjusted, but that's
a libc side discussion.

the shadow stack of the main stack can still overflow, but
that requires increasing RLIMIT_STACK at runtime which is
not very common.

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

end of thread, other threads:[~2023-07-12  9:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <ZJ2sTu9QRmiWNISy@arm.com>
     [not found] ` <e057de9dd9e9fe48981afb4ded4b337e8a83fabf.camel@intel.com>
     [not found]   ` <ZKMRFNSYQBC6S+ga@arm.com>
     [not found]     ` <eda8b2c4b2471529954aadbe04592da1ddae906d.camel@intel.com>
     [not found]       ` <ZKa8jB4lOik/aFn2@arm.com>
     [not found]         ` <68b7f983ffd3b7c629940b6c6ee9533bb55d9a13.camel@intel.com>
     [not found]           ` <ZKguVAZe+DGA1VEv@arm.com>
     [not found]             ` <1c2f524cbaff886ce782bf3a3f95756197bc1e27.camel@intel.com>
     [not found]               ` <ZKw3zSKxCug0IbC1@arm.com>
     [not found]                 ` <1c0460a2042480b6a2d4cc1f6b99b27ab1371f3a.camel@intel.com>
2023-07-11  8:08                   ` [PATCH v9 23/42] Documentation/x86: Add CET shadow stack description szabolcs.nagy
2023-07-12  9:39                     ` Szabolcs Nagy

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).