Commit 7424ccaa authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

lsm: get host lsm type from the host mntns

We check files in /sys, so we must do this from host mount namespaces.

The write_img_inventory() is called after kerndat_init() and it's only
called on dump. The bug is triggered on restore, because the mount
namespace of the restored process doesn't have
/sys/kernel/security/apparmor/

I think it's better to initialize the host lsm in a one place for dump
and restore.

Currently we initialize the host lsm when we try to use it at a first
time. It works fine for the dump operation. On restore it doesn't work
because criu checks files in a restored mount namespace and it does this
for each process, what isn't optimal.
Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Acked-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a6e13e1a
...@@ -9,6 +9,11 @@ ...@@ -9,6 +9,11 @@
*/ */
extern Lsmtype host_lsm_type(); extern Lsmtype host_lsm_type();
/*
* Initilize the Lsmtype for the current host
*/
extern void kerndat_lsm();
/* /*
* Read the LSM profile for the pstree item * Read the LSM profile for the pstree item
*/ */
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "asm/types.h" #include "asm/types.h"
#include "cr_options.h" #include "cr_options.h"
#include "util.h" #include "util.h"
#include "lsm.h"
struct kerndat_s kdat = { struct kerndat_s kdat = {
.tcp_max_rshare = 3U << 20, .tcp_max_rshare = 3U << 20,
...@@ -323,6 +324,8 @@ int kerndat_init(void) ...@@ -323,6 +324,8 @@ int kerndat_init(void)
if (!ret) if (!ret)
ret = kerndat_fdinfo_has_lock(); ret = kerndat_fdinfo_has_lock();
kerndat_lsm();
return ret; return ret;
} }
...@@ -342,5 +345,7 @@ int kerndat_init_rst(void) ...@@ -342,5 +345,7 @@ int kerndat_init_rst(void)
if (!ret) if (!ret)
ret = kerndat_has_memfd_create(); ret = kerndat_has_memfd_create();
kerndat_lsm();
return ret; return ret;
} }
...@@ -102,7 +102,7 @@ static int selinux_get_label(pid_t pid, char **output) ...@@ -102,7 +102,7 @@ static int selinux_get_label(pid_t pid, char **output)
} }
#endif #endif
static void get_host_lsm() void kerndat_lsm()
{ {
if (access("/sys/kernel/security/apparmor", F_OK) == 0) { if (access("/sys/kernel/security/apparmor", F_OK) == 0) {
get_label = apparmor_get_label; get_label = apparmor_get_label;
...@@ -132,17 +132,11 @@ static void get_host_lsm() ...@@ -132,17 +132,11 @@ static void get_host_lsm()
Lsmtype host_lsm_type() Lsmtype host_lsm_type()
{ {
if (name == NULL)
get_host_lsm();
return lsmtype; return lsmtype;
} }
int collect_lsm_profile(pid_t pid, CredsEntry *ce) int collect_lsm_profile(pid_t pid, CredsEntry *ce)
{ {
if (name == NULL)
get_host_lsm();
ce->lsm_profile = NULL; ce->lsm_profile = NULL;
if (lsmtype == LSMTYPE__NO_LSM) if (lsmtype == LSMTYPE__NO_LSM)
...@@ -162,9 +156,6 @@ extern Lsmtype image_lsm; ...@@ -162,9 +156,6 @@ extern Lsmtype image_lsm;
int validate_lsm(CredsEntry *ce) int validate_lsm(CredsEntry *ce)
{ {
if (name == NULL)
get_host_lsm();
if (image_lsm == LSMTYPE__NO_LSM || image_lsm == lsmtype) if (image_lsm == LSMTYPE__NO_LSM || image_lsm == lsmtype)
return 0; return 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