Commit e6302380 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

lsm: Move host lsmtype on kerndat

Currently this is lsm.c's static variable, but since kdat
is now cached (and uncached) this value stays zero (no lsm)
if the cache file gets loaded, which is obviously wrong and
breaks the restore all the time on lsm-enabled hosts.

https://github.com/xemul/criu/issues/323Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 171acca8
#ifndef __CR_KERNDAT_H__ #ifndef __CR_KERNDAT_H__
#define __CR_KERNDAT_H__ #define __CR_KERNDAT_H__
#include <stdbool.h>
#include "int.h" #include "int.h"
struct stat; struct stat;
...@@ -45,6 +47,7 @@ struct kerndat_s { ...@@ -45,6 +47,7 @@ struct kerndat_s {
unsigned long mmap_min_addr; unsigned long mmap_min_addr;
bool has_tcp_half_closed; bool has_tcp_half_closed;
bool stack_guard_gap_hidden; bool stack_guard_gap_hidden;
int lsm;
}; };
extern struct kerndat_s kdat; extern struct kerndat_s kdat;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include "kerndat.h"
#include "config.h" #include "config.h"
#include "pstree.h" #include "pstree.h"
#include "util.h" #include "util.h"
...@@ -19,8 +20,6 @@ ...@@ -19,8 +20,6 @@
#include <selinux/selinux.h> #include <selinux/selinux.h>
#endif #endif
static Lsmtype lsmtype;
static int apparmor_get_label(pid_t pid, char **profile_name) static int apparmor_get_label(pid_t pid, char **profile_name)
{ {
FILE *f; FILE *f;
...@@ -108,7 +107,7 @@ static int selinux_get_label(pid_t pid, char **output) ...@@ -108,7 +107,7 @@ static int selinux_get_label(pid_t pid, char **output)
void kerndat_lsm(void) void kerndat_lsm(void)
{ {
if (access(AA_SECURITYFS_PATH, F_OK) == 0) { if (access(AA_SECURITYFS_PATH, F_OK) == 0) {
lsmtype = LSMTYPE__APPARMOR; kdat.lsm = LSMTYPE__APPARMOR;
return; return;
} }
...@@ -119,17 +118,17 @@ void kerndat_lsm(void) ...@@ -119,17 +118,17 @@ void kerndat_lsm(void)
* well. * well.
*/ */
if (access("/sys/fs/selinux", F_OK) == 0) { if (access("/sys/fs/selinux", F_OK) == 0) {
lsmtype = LSMTYPE__SELINUX; kdat.lsm = LSMTYPE__SELINUX;
return; return;
} }
#endif #endif
lsmtype = LSMTYPE__NO_LSM; kdat.lsm = LSMTYPE__NO_LSM;
} }
Lsmtype host_lsm_type(void) Lsmtype host_lsm_type(void)
{ {
return lsmtype; return kdat.lsm;
} }
int collect_lsm_profile(pid_t pid, CredsEntry *ce) int collect_lsm_profile(pid_t pid, CredsEntry *ce)
...@@ -138,7 +137,7 @@ int collect_lsm_profile(pid_t pid, CredsEntry *ce) ...@@ -138,7 +137,7 @@ int collect_lsm_profile(pid_t pid, CredsEntry *ce)
ce->lsm_profile = NULL; ce->lsm_profile = NULL;
switch (lsmtype) { switch (kdat.lsm) {
case LSMTYPE__NO_LSM: case LSMTYPE__NO_LSM:
ret = 0; ret = 0;
break; break;
...@@ -167,7 +166,7 @@ extern Lsmtype image_lsm; ...@@ -167,7 +166,7 @@ extern Lsmtype image_lsm;
int validate_lsm(char *lsm_profile) int validate_lsm(char *lsm_profile)
{ {
if (image_lsm == LSMTYPE__NO_LSM || image_lsm == lsmtype) if (image_lsm == LSMTYPE__NO_LSM || image_lsm == kdat.lsm)
return 0; return 0;
/* /*
...@@ -187,7 +186,7 @@ int render_lsm_profile(char *profile, char **val) ...@@ -187,7 +186,7 @@ int render_lsm_profile(char *profile, char **val)
{ {
*val = NULL; *val = NULL;
switch (lsmtype) { switch (kdat.lsm) {
case LSMTYPE__APPARMOR: case LSMTYPE__APPARMOR:
if (strcmp(profile, "unconfined") != 0 && asprintf(val, "changeprofile %s", profile) < 0) { if (strcmp(profile, "unconfined") != 0 && asprintf(val, "changeprofile %s", profile) < 0) {
pr_err("allocating lsm profile failed\n"); pr_err("allocating lsm profile failed\n");
...@@ -226,14 +225,14 @@ int lsm_check_opts(void) ...@@ -226,14 +225,14 @@ int lsm_check_opts(void)
aux++; aux++;
if (strcmp(opts.lsm_profile, "apparmor") == 0) { if (strcmp(opts.lsm_profile, "apparmor") == 0) {
if (lsmtype != LSMTYPE__APPARMOR) { if (kdat.lsm != LSMTYPE__APPARMOR) {
pr_err("apparmor LSM specified but apparmor not supported by kernel\n"); pr_err("apparmor LSM specified but apparmor not supported by kernel\n");
return -1; return -1;
} }
opts.lsm_profile = aux; opts.lsm_profile = aux;
} else if (strcmp(opts.lsm_profile, "selinux") == 0) { } else if (strcmp(opts.lsm_profile, "selinux") == 0) {
if (lsmtype != LSMTYPE__SELINUX) { if (kdat.lsm != LSMTYPE__SELINUX) {
pr_err("selinux LSM specified but selinux not supported by kernel\n"); pr_err("selinux LSM specified but selinux not supported by kernel\n");
return -1; return -1;
} }
......
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