--- lxc-2.0.8/src/lxc/rexec.c.orig 2019-02-13 09:54:35.316707658 +0100 +++ lxc-2.0.8/src/lxc/rexec.c 2019-02-13 13:20:49.551747667 +0100 @@ -37,6 +37,17 @@ #define LXC_MEMFD_REXEC_SEALS \ (F_SEAL_SEAL | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE) +/* Re-alllocate a pointer, do not fail */ +static void *must_realloc(void *orig, size_t sz) +{ + void *ret; + + do { + ret = realloc(orig, sz); + } while (!ret); + return ret; +} + static int push_vargs(char *data, int data_length, char ***output) { int num = 0; @@ -164,6 +175,50 @@ return ret; } +#ifndef HAVE_MEMFD_CREATE +static int memfd_create(const char *name, unsigned int flags) { + #ifndef __NR_memfd_create + #if defined __i386__ + #define __NR_memfd_create 356 + #elif defined __x86_64__ + #define __NR_memfd_create 319 + #elif defined __arm__ + #define __NR_memfd_create 385 + #elif defined __aarch64__ + #define __NR_memfd_create 279 + #elif defined __s390__ + #define __NR_memfd_create 350 + #elif defined __powerpc__ + #define __NR_memfd_create 360 + #elif defined __sparc__ + #define __NR_memfd_create 348 + #elif defined __blackfin__ + #define __NR_memfd_create 390 + #elif defined __ia64__ + #define __NR_memfd_create 1340 + #elif defined _MIPS_SIM + #if _MIPS_SIM == _MIPS_SIM_ABI32 + #define __NR_memfd_create 4354 + #endif + #if _MIPS_SIM == _MIPS_SIM_NABI32 + #define __NR_memfd_create 6318 + #endif + #if _MIPS_SIM == _MIPS_SIM_ABI64 + #define __NR_memfd_create 5314 + #endif + #endif + #endif + #ifdef __NR_memfd_create + return syscall(__NR_memfd_create, name, flags); + #else + errno = ENOSYS; + return -1; + #endif +} +#else +extern int memfd_create(const char *name, unsigned int flags); +#endif + static void lxc_rexec_as_memfd(char **argv, char **envp, const char *memfd_name) { int saved_errno;