public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top, runsisi <runsisi@hust.edu.cn>
Subject: Re: [PATCH] pasta, util: Align stack area for clones to maximum natural alignment
Date: Fri, 12 Apr 2024 12:00:30 +1000	[thread overview]
Message-ID: <ZhiVvq2SNwl4c3dQ@zatzit> (raw)
In-Reply-To: <20240411221800.548140-1-sbrivio@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2396 bytes --]

On Fri, Apr 12, 2024 at 12:18:00AM +0200, Stefano Brivio wrote:
> Given that we use this stack pointer as a location to store arbitrary
> data types from the cloned process, we need to guarantee that its
> alignment matches any of those possible data types.
> 
> runsisi reports that pasta gets a SIGBUS in pasta_open_ns() on
> aarch64, where the alignment requirement for stack pointers is a
> 16 bytes (same as the size of a long double), and similar requirements
> actually apply to most architectures we run on.
> 
> Reported-by: runsisi <runsisi@hust.edu.cn>
> Link: https://bugs.passt.top/show_bug.cgi?id=85
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  pasta.c | 3 ++-
>  util.h  | 4 +++-
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/pasta.c b/pasta.c
> index e73b5af..31e1e00 100644
> --- a/pasta.c
> +++ b/pasta.c
> @@ -211,12 +211,13 @@ static int pasta_spawn_cmd(void *arg)
>  void pasta_start_ns(struct ctx *c, uid_t uid, gid_t gid,
>  		    int argc, char *argv[])
>  {
> +	char ns_fn_stack[NS_FN_STACK_SIZE]
> +	__attribute__ ((aligned(__alignof__(max_align_t))));
>  	struct pasta_spawn_cmd_arg arg = {
>  		.exe = argv[0],
>  		.argv = argv,
>  	};
>  	char uidmap[BUFSIZ], gidmap[BUFSIZ];
> -	char ns_fn_stack[NS_FN_STACK_SIZE];
>  	char *sh_argv[] = { NULL, NULL };
>  	char sh_arg0[PATH_MAX + 1];
>  	sigset_t set;
> diff --git a/util.h b/util.h
> index 7c261d7..8c37729 100644
> --- a/util.h
> +++ b/util.h
> @@ -9,6 +9,7 @@
>  #include <stdlib.h>
>  #include <stdarg.h>
>  #include <stdbool.h>
> +#include <stddef.h>
>  #include <string.h>
>  #include <signal.h>
>  
> @@ -116,7 +117,8 @@ int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags,
>  	     void *arg);
>  #define NS_CALL(fn, arg)						\
>  	do {								\
> -		char ns_fn_stack[NS_FN_STACK_SIZE];			\
> +		char ns_fn_stack[NS_FN_STACK_SIZE]			\
> +		__attribute__ ((aligned(__alignof__(max_align_t))));	\
>  									\
>  		do_clone((fn), ns_fn_stack, sizeof(ns_fn_stack),	\
>  			 CLONE_VM | CLONE_VFORK | CLONE_FILES | SIGCHLD,\

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2024-04-12  3:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11 22:18 [PATCH] pasta, util: Align stack area for clones to maximum natural alignment Stefano Brivio
2024-04-12  2:00 ` David Gibson [this message]

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=ZhiVvq2SNwl4c3dQ@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=runsisi@hust.edu.cn \
    --cc=sbrivio@redhat.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).