From 0643c7e49f792207d19f6065acd7133411928633 Mon Sep 17 00:00:00 2001 From: Wong Hoi Sing Edison Date: Fri, 8 Sep 2023 17:19:29 +0800 Subject: [PATCH] Fix CentOS 7 Build by Checking if FSOPEN_CLOEXEC exists See https://github.com/containers/crun/issues/1298#issuecomment-1711193085 Fixes https://github.com/containers/crun/issues/1298 Signed-off-by: Wong Hoi Sing Edison --- configure.ac | 2 +- src/libcrun/handlers/wasmedge.c | 16 +++++++------- src/libcrun/handlers/wasmer.c | 2 +- src/libcrun/handlers/wasmtime.c | 38 ++++++++++++++++----------------- src/libcrun/linux.c | 12 +++++++++++ src/libcrun/seccomp.c | 4 ++++ 6 files changed, 45 insertions(+), 29 deletions(-) diff --git a/configure.ac b/configure.ac index e20da7e4bb..36245ee812 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,7 @@ AC_CHECK_HEADERS([error.h linux/openat2.h stdatomic.h linux/ioprio.h]) AC_CHECK_TYPES([atomic_int], [], [], [[#include ]]) AC_CHECK_TYPES([atomic_bool], [], [], [[#include ]]) -AC_CHECK_FUNCS(copy_file_range fgetxattr statx fgetpwent_r issetugid) +AC_CHECK_FUNCS(copy_file_range fgetxattr statx fgetpwent_r issetugid memfd_create) AC_ARG_ENABLE(crun, AS_HELP_STRING([--enable-crun], [Include crun executable in installation (default: yes)]), diff --git a/src/libcrun/handlers/wasmedge.c b/src/libcrun/handlers/wasmedge.c index 1dc2f60468..c4272a539b 100644 --- a/src/libcrun/handlers/wasmedge.c +++ b/src/libcrun/handlers/wasmedge.c @@ -70,13 +70,13 @@ static int libwasmedge_exec (void *cookie, __attribute__ ((unused)) libcrun_container_t *container, const char *pathname, char *const argv[]) { WasmEdge_ConfigureContext *(*WasmEdge_ConfigureCreate) (void); - void (*WasmEdge_ConfigureDelete) (WasmEdge_ConfigureContext *Cxt); - void (*WasmEdge_ConfigureAddProposal) (WasmEdge_ConfigureContext *Cxt, const enum WasmEdge_Proposal Prop); - void (*WasmEdge_ConfigureAddHostRegistration) (WasmEdge_ConfigureContext *Cxt, enum WasmEdge_HostRegistration Host); + void (*WasmEdge_ConfigureDelete) (WasmEdge_ConfigureContext * Cxt); + void (*WasmEdge_ConfigureAddProposal) (WasmEdge_ConfigureContext * Cxt, const enum WasmEdge_Proposal Prop); + void (*WasmEdge_ConfigureAddHostRegistration) (WasmEdge_ConfigureContext * Cxt, enum WasmEdge_HostRegistration Host); WasmEdge_VMContext *(*WasmEdge_VMCreate) (const WasmEdge_ConfigureContext *ConfCxt, WasmEdge_StoreContext *StoreCxt); - void (*WasmEdge_VMDelete) (WasmEdge_VMContext *Cxt); - WasmEdge_Result (*WasmEdge_VMRegisterModuleFromFile) (WasmEdge_VMContext *Cxt, WasmEdge_String ModuleName, const char *Path); - WasmEdge_Result (*WasmEdge_VMRunWasmFromFile) (WasmEdge_VMContext *Cxt, const char *Path, const WasmEdge_String FuncName, const WasmEdge_Value *Params, const uint32_t ParamLen, WasmEdge_Value *Returns, const uint32_t ReturnLen); + void (*WasmEdge_VMDelete) (WasmEdge_VMContext * Cxt); + WasmEdge_Result (*WasmEdge_VMRegisterModuleFromFile) (WasmEdge_VMContext * Cxt, WasmEdge_String ModuleName, const char *Path); + WasmEdge_Result (*WasmEdge_VMRunWasmFromFile) (WasmEdge_VMContext * Cxt, const char *Path, const WasmEdge_String FuncName, const WasmEdge_Value *Params, const uint32_t ParamLen, WasmEdge_Value *Returns, const uint32_t ReturnLen); bool (*WasmEdge_ResultOK) (const WasmEdge_Result Res); WasmEdge_String (*WasmEdge_StringCreateByCString) (const char *Str); uint32_t argn = 0; @@ -87,8 +87,8 @@ libwasmedge_exec (void *cookie, __attribute__ ((unused)) libcrun_container_t *co WasmEdge_Result result; WasmEdge_ModuleInstanceContext *wasi_module; - WasmEdge_ModuleInstanceContext *(*WasmEdge_VMGetImportModuleContext) (WasmEdge_VMContext *Cxt, const enum WasmEdge_HostRegistration Reg); - void (*WasmEdge_ModuleInstanceInitWASI) (WasmEdge_ModuleInstanceContext *Cxt, const char *const *Args, const uint32_t ArgLen, const char *const *Envs, const uint32_t EnvLen, const char *const *Dirs, const uint32_t DirLen, const char *const *Preopens, const uint32_t PreopenLen); + WasmEdge_ModuleInstanceContext *(*WasmEdge_VMGetImportModuleContext) (WasmEdge_VMContext * Cxt, const enum WasmEdge_HostRegistration Reg); + void (*WasmEdge_ModuleInstanceInitWASI) (WasmEdge_ModuleInstanceContext * Cxt, const char *const *Args, const uint32_t ArgLen, const char *const *Envs, const uint32_t EnvLen, const char *const *Dirs, const uint32_t DirLen, const char *const *Preopens, const uint32_t PreopenLen); WasmEdge_ModuleInstanceInitWASI = dlsym (cookie, "WasmEdge_ModuleInstanceInitWASI"); WasmEdge_ConfigureCreate = dlsym (cookie, "WasmEdge_ConfigureCreate"); diff --git a/src/libcrun/handlers/wasmer.c b/src/libcrun/handlers/wasmer.c index 1080b55ce4..3416f50165 100644 --- a/src/libcrun/handlers/wasmer.c +++ b/src/libcrun/handlers/wasmer.c @@ -98,7 +98,7 @@ libwasmer_exec (void *cookie, libcrun_container_t *container arg_unused, wasm_func_t *(*wasi_get_start_function) (wasm_instance_t *); intptr_t (*wasi_env_read_stdout) (struct wasi_env_t *, char *, uintptr_t); void (*wasi_env_delete) (struct wasi_env_t *); - void (*wasi_config_arg) (struct wasi_config_t *config, const char *arg); + void (*wasi_config_arg) (struct wasi_config_t * config, const char *arg); bool (*wasi_env_initialize_instance) (struct wasi_env_t *, wasm_store_t *, wasm_instance_t *); wat2wasm = dlsym (cookie, "wat2wasm"); diff --git a/src/libcrun/handlers/wasmtime.c b/src/libcrun/handlers/wasmtime.c index 59bd9a7435..1c1b7506cb 100644 --- a/src/libcrun/handlers/wasmtime.c +++ b/src/libcrun/handlers/wasmtime.c @@ -58,25 +58,25 @@ libwasmtime_exec (void *cookie, libcrun_container_t *container arg_unused, void (*wasm_byte_vec_delete) (wasm_byte_vec_t *); void (*wasm_byte_vec_new_uninitialized) (wasm_byte_vec_t *, size_t); wasi_config_t *(*wasi_config_new) (const char *); - wasmtime_store_t *(*wasmtime_store_new) (wasm_engine_t *engine, void *data, void (*finalizer) (void *)); - wasmtime_context_t *(*wasmtime_store_context) (wasmtime_store_t *store); - wasmtime_linker_t *(*wasmtime_linker_new) (wasm_engine_t *engine); - wasmtime_error_t *(*wasmtime_linker_define_wasi) (wasmtime_linker_t *linker); + wasmtime_store_t *(*wasmtime_store_new) (wasm_engine_t * engine, void *data, void (*finalizer) (void *)); + wasmtime_context_t *(*wasmtime_store_context) (wasmtime_store_t * store); + wasmtime_linker_t *(*wasmtime_linker_new) (wasm_engine_t * engine); + wasmtime_error_t *(*wasmtime_linker_define_wasi) (wasmtime_linker_t * linker); wasmtime_error_t *(*wasmtime_module_new) ( - wasm_engine_t *engine, + wasm_engine_t * engine, const uint8_t *wasm, size_t wasm_len, wasmtime_module_t **ret); - void (*wasi_config_inherit_argv) (wasi_config_t *config); - void (*wasi_config_inherit_env) (wasi_config_t *config); - void (*wasi_config_set_argv) (wasi_config_t *config, int argc, const char *argv[]); - void (*wasi_config_inherit_stdin) (wasi_config_t *config); - void (*wasi_config_inherit_stdout) (wasi_config_t *config); - void (*wasi_config_inherit_stderr) (wasi_config_t *config); - wasmtime_error_t *(*wasmtime_context_set_wasi) (wasmtime_context_t *context, wasi_config_t *wasi); + void (*wasi_config_inherit_argv) (wasi_config_t * config); + void (*wasi_config_inherit_env) (wasi_config_t * config); + void (*wasi_config_set_argv) (wasi_config_t * config, int argc, const char *argv[]); + void (*wasi_config_inherit_stdin) (wasi_config_t * config); + void (*wasi_config_inherit_stdout) (wasi_config_t * config); + void (*wasi_config_inherit_stderr) (wasi_config_t * config); + wasmtime_error_t *(*wasmtime_context_set_wasi) (wasmtime_context_t * context, wasi_config_t * wasi); wasmtime_error_t *(*wasmtime_linker_module) ( - wasmtime_linker_t *linker, - wasmtime_context_t *store, + wasmtime_linker_t * linker, + wasmtime_context_t * store, const char *name, size_t name_len, const wasmtime_module_t *module); @@ -87,18 +87,18 @@ libwasmtime_exec (void *cookie, libcrun_container_t *container arg_unused, size_t name_len, wasmtime_func_t *func); wasmtime_error_t *(*wasmtime_func_call) ( - wasmtime_context_t *store, + wasmtime_context_t * store, const wasmtime_func_t *func, const wasmtime_val_t *args, size_t nargs, wasmtime_val_t *results, size_t nresults, wasm_trap_t **trap); - void (*wasmtime_module_delete) (wasmtime_module_t *m); - void (*wasmtime_store_delete) (wasmtime_store_t *store); + void (*wasmtime_module_delete) (wasmtime_module_t * m); + void (*wasmtime_store_delete) (wasmtime_store_t * store); void (*wasmtime_error_message) (const wasmtime_error_t *error, wasm_name_t *message); - void (*wasmtime_error_delete) (wasmtime_error_t *error); - bool (*wasi_config_preopen_dir) (wasi_config_t *config, const char *path, const char *guest_path); + void (*wasmtime_error_delete) (wasmtime_error_t * error); + bool (*wasi_config_preopen_dir) (wasi_config_t * config, const char *path, const char *guest_path); wasmtime_wat2wasm = dlsym (cookie, "wasmtime_wat2wasm"); wasm_engine_new = dlsym (cookie, "wasm_engine_new"); diff --git a/src/libcrun/linux.c b/src/libcrun/linux.c index 54fd51670d..2c610f0ebe 100644 --- a/src/libcrun/linux.c +++ b/src/libcrun/linux.c @@ -92,6 +92,18 @@ # define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 #endif +#ifndef FSOPEN_CLOEXEC +# define FSOPEN_CLOEXEC 0x00000001 +#endif + +#ifndef FSMOUNT_CLOEXEC +# define FSMOUNT_CLOEXEC 0x00000001 +#endif + +#ifndef FSCONFIG_CMD_CREATE +# define FSCONFIG_CMD_CREATE 6 +#endif + struct remount_s { struct remount_s *next; diff --git a/src/libcrun/seccomp.c b/src/libcrun/seccomp.c index ca128ee5d2..19edfae8be 100644 --- a/src/libcrun/seccomp.c +++ b/src/libcrun/seccomp.c @@ -262,9 +262,13 @@ libcrun_apply_seccomp (int infd, int listener_receiver_fd, const char *receiver_ return crun_make_error (err, 0, "the `SECCOMP_FILTER_FLAG_NEW_LISTENER` flag is not supported"); # endif +# ifdef HAVE_MEMFD_CREATE memfd = memfd_create ("seccomp-helper-memfd", O_RDWR); if (UNLIKELY (memfd < 0)) return crun_make_error (err, errno, "memfd_create"); +# else + return crun_make_error (err, ENOSYS, "memfd_create non supported"); +# endif ret = ftruncate (memfd, sizeof (atomic_int)); if (UNLIKELY (ret < 0))