public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
Cc: Andreas Schwab <schwab@linux-m68k.org>,  "H.J. Lu" <hjl.tools@gmail.com>
Subject: Re: [PATCH v2] x86-64: Align child stack to 16 bytes [BZ #27902]
Date: Mon, 24 May 2021 14:07:18 +0200	[thread overview]
Message-ID: <87lf842v49.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <CAMe9rOopEdoNi2dDRMN-DaLC=SyKrJoFgxOZFOzz7oDUY18fHA@mail.gmail.com> (H. J. Lu via Libc-alpha's message of "Sun, 23 May 2021 11:40:50 -0700")

* H. J. Lu via Libc-alpha:

> +static int
> +f (void *arg)
> +{
> +  bool ok = true;
> +
> +  puts ("in f");
> +
> +  if (TEST_STACK_ALIGN ())
> +    ok = false;
> +
> +  return ok ? 0 : 1;
> +}

Is it okay to call libc functions from the callback because it is after
a fork-style clone (without any flags) that inherits the TCB?  Otherwise
there are going to be problems with the stack protector at least.

> +  char st[STACK_SIZE + 1];
> +  /* NB: Align child stack to 1 byte.  */
> +  char *stack = PTR_ALIGN_UP (&st[0], 2) + 1;
> +
> +#ifdef __ia64__
> +  extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
> +		       size_t __child_stack_size, int __flags,
> +		       void *__arg, ...);
> +  pid_t p = __clone2 (f, stack, STACK_SIZE, 0, 0);
> +#else
> +# if _STACK_GROWS_DOWN
> +  pid_t p = clone (f, stack + STACK_SIZE, 0, 0);
> +# elif _STACK_GROWS_UP
> +  pid_t p = clone (f, stack, 0, 0);
> +# else
> +#  error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
> +# endif
> +#endif

I think the (mis)alignment step has to be among the
_STACK_GROWS_UP/_STACK_GROWS_DOWN part.

Thanks,
Florian


  reply	other threads:[~2021-05-24 12:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-23 17:29 [PATCH] x86-64: Align child stack to 16 bytes H.J. Lu
2021-05-23 17:57 ` Andreas Schwab
2021-05-23 18:40   ` [PATCH v2] x86-64: Align child stack to 16 bytes [BZ #27902] H.J. Lu
2021-05-24 12:07     ` Florian Weimer [this message]
2021-05-24 12:53       ` H.J. Lu
2021-05-24 14:19     ` Carlos O'Donell
2021-05-24 14:55       ` Noah Goldstein
2021-05-24 18:46         ` H.J. Lu
2021-05-24 18:46       ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lf842v49.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=hjl.tools@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).