pasta, util: Align stack area for clones to maximum natural alignment
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>
This commit is contained in:
parent
5d5208b67d
commit
ee338a256e
2 changed files with 5 additions and 2 deletions
3
pasta.c
3
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,
|
void pasta_start_ns(struct ctx *c, uid_t uid, gid_t gid,
|
||||||
int argc, char *argv[])
|
int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
char ns_fn_stack[NS_FN_STACK_SIZE]
|
||||||
|
__attribute__ ((aligned(__alignof__(max_align_t))));
|
||||||
struct pasta_spawn_cmd_arg arg = {
|
struct pasta_spawn_cmd_arg arg = {
|
||||||
.exe = argv[0],
|
.exe = argv[0],
|
||||||
.argv = argv,
|
.argv = argv,
|
||||||
};
|
};
|
||||||
char uidmap[BUFSIZ], gidmap[BUFSIZ];
|
char uidmap[BUFSIZ], gidmap[BUFSIZ];
|
||||||
char ns_fn_stack[NS_FN_STACK_SIZE];
|
|
||||||
char *sh_argv[] = { NULL, NULL };
|
char *sh_argv[] = { NULL, NULL };
|
||||||
char sh_arg0[PATH_MAX + 1];
|
char sh_arg0[PATH_MAX + 1];
|
||||||
sigset_t set;
|
sigset_t set;
|
||||||
|
|
4
util.h
4
util.h
|
@ -9,6 +9,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.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);
|
void *arg);
|
||||||
#define NS_CALL(fn, arg) \
|
#define NS_CALL(fn, arg) \
|
||||||
do { \
|
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), \
|
do_clone((fn), ns_fn_stack, sizeof(ns_fn_stack), \
|
||||||
CLONE_VM | CLONE_VFORK | CLONE_FILES | SIGCHLD,\
|
CLONE_VM | CLONE_VFORK | CLONE_FILES | SIGCHLD,\
|
||||||
|
|
Loading…
Reference in a new issue