Commit 09c131c8 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

lsm: Postpone lsm_profile vs kerndat checks

We need to keep the host LSM mode on kerndat (next patches),
at the same time the --lsm-profile option needs to correspond
to it.

So split the option handling into two parts -- first keep it
as is, next -- check for kerndat correspondance.
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent ebc48538
...@@ -1539,6 +1539,9 @@ int cr_pre_dump_tasks(pid_t pid) ...@@ -1539,6 +1539,9 @@ int cr_pre_dump_tasks(pid_t pid)
if (kerndat_init()) if (kerndat_init())
goto err; goto err;
if (lsm_check_opts())
goto err;
if (irmap_load_cache()) if (irmap_load_cache())
goto err; goto err;
...@@ -1689,6 +1692,9 @@ int cr_dump_tasks(pid_t pid) ...@@ -1689,6 +1692,9 @@ int cr_dump_tasks(pid_t pid)
if (kerndat_init()) if (kerndat_init())
goto err; goto err;
if (lsm_check_opts())
goto err;
if (irmap_load_cache()) if (irmap_load_cache())
goto err; goto err;
......
...@@ -2134,6 +2134,9 @@ int cr_restore_tasks(void) ...@@ -2134,6 +2134,9 @@ int cr_restore_tasks(void)
if (kerndat_init()) if (kerndat_init())
goto err; goto err;
if (lsm_check_opts())
goto err;
timing_start(TIME_RESTORE); timing_start(TIME_RESTORE);
if (cpu_init() < 0) if (cpu_init() < 0)
......
...@@ -511,8 +511,8 @@ int main(int argc, char *argv[], char *envp[]) ...@@ -511,8 +511,8 @@ int main(int argc, char *argv[], char *envp[])
return -1; return -1;
break; break;
case 1071: case 1071:
if (parse_lsm_arg(optarg) < 0) opts.lsm_profile = optarg;
return -1; opts.lsm_supplied = true;
break; break;
case 1072: case 1072:
opts.timeout = atoi(optarg); opts.timeout = atoi(optarg);
......
...@@ -33,5 +33,5 @@ int validate_lsm(char *profile); ...@@ -33,5 +33,5 @@ int validate_lsm(char *profile);
*/ */
int render_lsm_profile(char *profile, char **val); int render_lsm_profile(char *profile, char **val);
extern int parse_lsm_arg(char *arg); extern int lsm_check_opts(void);
#endif /* __CR_LSM_H__ */ #endif /* __CR_LSM_H__ */
...@@ -108,14 +108,6 @@ static int selinux_get_label(pid_t pid, char **output) ...@@ -108,14 +108,6 @@ static int selinux_get_label(pid_t pid, char **output)
void kerndat_lsm(void) void kerndat_lsm(void)
{ {
/* On restore, if someone passes --lsm-profile, we might end up doing
* detection twice, once during flag parsing and once for
* kerndat_init(). Let's detect when we've already done detection
* and not do it again.
*/
if (name)
return;
if (access(AA_SECURITYFS_PATH, F_OK) == 0) { if (access(AA_SECURITYFS_PATH, F_OK) == 0) {
get_label = apparmor_get_label; get_label = apparmor_get_label;
lsmtype = LSMTYPE__APPARMOR; lsmtype = LSMTYPE__APPARMOR;
...@@ -207,43 +199,42 @@ int render_lsm_profile(char *profile, char **val) ...@@ -207,43 +199,42 @@ int render_lsm_profile(char *profile, char **val)
return 0; return 0;
} }
int parse_lsm_arg(char *arg) int lsm_check_opts(void)
{ {
char *aux; char *aux;
kerndat_lsm(); if (!opts.lsm_supplied)
return 0;
aux = strchr(arg, ':'); aux = strchr(opts.lsm_profile, ':');
if (aux == NULL) { if (aux == NULL) {
pr_err("invalid argument %s for --lsm-profile\n", arg); pr_err("invalid argument %s for --lsm-profile\n", opts.lsm_profile);
return -1; return -1;
} }
*aux = '\0'; *aux = '\0';
aux++; aux++;
if (strcmp(arg, "apparmor") == 0) { if (strcmp(opts.lsm_profile, "apparmor") == 0) {
if (lsmtype != LSMTYPE__APPARMOR) { if (lsmtype != 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(arg, "selinux") == 0) { } else if (strcmp(opts.lsm_profile, "selinux") == 0) {
if (lsmtype != LSMTYPE__SELINUX) { if (lsmtype != 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;
} }
opts.lsm_profile = aux; opts.lsm_profile = aux;
} else if (strcmp(arg, "none") == 0) { } else if (strcmp(opts.lsm_profile, "none") == 0) {
opts.lsm_profile = NULL; opts.lsm_profile = NULL;
} else { } else {
pr_err("unknown lsm %s\n", arg); pr_err("unknown lsm %s\n", opts.lsm_profile);
return -1; return -1;
} }
opts.lsm_supplied = true;
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