conf: add personality_t

Catch errors in personality handling better. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 70cf1461
...@@ -95,7 +95,7 @@ struct attach_context { ...@@ -95,7 +95,7 @@ struct attach_context {
uid_t target_host_gid; uid_t target_host_gid;
char *lsm_label; char *lsm_label;
struct lxc_container *container; struct lxc_container *container;
signed long personality; personality_t personality;
unsigned long long capability_mask; unsigned long long capability_mask;
int ns_inherited; int ns_inherited;
int ns_fd[LXC_NS_MAX]; int ns_fd[LXC_NS_MAX];
...@@ -197,7 +197,7 @@ static struct attach_context *alloc_attach_context(void) ...@@ -197,7 +197,7 @@ static struct attach_context *alloc_attach_context(void)
} }
static int get_personality(const char *name, const char *lxcpath, static int get_personality(const char *name, const char *lxcpath,
signed long *personality) personality_t *personality)
{ {
__do_free char *p = NULL; __do_free char *p = NULL;
int ret; int ret;
...@@ -1153,7 +1153,7 @@ __noreturn static void do_attach(struct attach_payload *ap) ...@@ -1153,7 +1153,7 @@ __noreturn static void do_attach(struct attach_payload *ap)
new_personality = options->personality; new_personality = options->personality;
if (new_personality != LXC_ARCH_UNCHANGED) { if (new_personality != LXC_ARCH_UNCHANGED) {
ret = personality(new_personality); ret = lxc_personality(new_personality);
if (ret < 0) if (ret < 0)
goto on_error; goto on_error;
......
...@@ -1728,14 +1728,14 @@ static int lxc_setup_devpts_child(struct lxc_handler *handler) ...@@ -1728,14 +1728,14 @@ static int lxc_setup_devpts_child(struct lxc_handler *handler)
return 0; return 0;
} }
static int setup_personality(signed long persona) static int setup_personality(personality_t persona)
{ {
int ret; int ret;
if (persona == LXC_ARCH_UNCHANGED) if (persona == LXC_ARCH_UNCHANGED)
return log_debug(0, "Retaining original personality"); return log_debug(0, "Retaining original personality");
ret = personality(persona); ret = lxc_personality(persona);
if (ret < 0) if (ret < 0)
return syserror("Failed to set personality to \"0lx%lx\"", persona); return syserror("Failed to set personality to \"0lx%lx\"", persona);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "start.h" #include "start.h"
#include "storage/storage.h" #include "storage/storage.h"
#include "string_utils.h" #include "string_utils.h"
#include "syscall_wrappers.h"
#include "terminal.h" #include "terminal.h"
#if HAVE_SYS_RESOURCE_H #if HAVE_SYS_RESOURCE_H
...@@ -36,6 +37,8 @@ ...@@ -36,6 +37,8 @@
typedef void * scmp_filter_ctx; typedef void * scmp_filter_ctx;
#endif #endif
typedef signed long personality_t;
/* worth moving to configure.ac? */ /* worth moving to configure.ac? */
#define subuidfile "/etc/subuid" #define subuidfile "/etc/subuid"
#define subgidfile "/etc/subgid" #define subgidfile "/etc/subgid"
...@@ -327,7 +330,7 @@ struct lxc_conf { ...@@ -327,7 +330,7 @@ struct lxc_conf {
const char *name; const char *name;
bool is_execute; bool is_execute;
int reboot; int reboot;
signed long personality; personality_t personality;
struct utsname *utsname; struct utsname *utsname;
struct { struct {
...@@ -628,4 +631,12 @@ static inline void lxc_clear_cgroup2_devices(struct bpf_devices *bpf_devices) ...@@ -628,4 +631,12 @@ static inline void lxc_clear_cgroup2_devices(struct bpf_devices *bpf_devices)
lxc_list_init(&bpf_devices->device_item); lxc_list_init(&bpf_devices->device_item);
} }
static inline int lxc_personality(personality_t persona)
{
if (persona < 0)
return ret_errno(EINVAL);
return personality(persona);
}
#endif /* __LXC_CONF_H */ #endif /* __LXC_CONF_H */
...@@ -1242,7 +1242,7 @@ static int set_config_personality(const char *key, const char *value, ...@@ -1242,7 +1242,7 @@ static int set_config_personality(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
int ret; int ret;
signed long personality; personality_t personality;
ret = lxc_config_parse_arch(value, &personality); ret = lxc_config_parse_arch(value, &personality);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment