Skip to content

Commit

Permalink
restore: cleanup cgroup properly in error path
Browse files Browse the repository at this point in the history
Cgroup yard is setup in crtools_prepare_shared. But it is not cleaned up
properly in some code path, which leads cgroup mountpoint leaking.

Signed-off-by: Liu Hua <[email protected]>
  • Loading branch information
Liu Hua committed Jul 7, 2021
1 parent 15266a4 commit 379884b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
18 changes: 7 additions & 11 deletions criu/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1771,19 +1771,19 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
}

if (make_yard(cg_yard))
goto err;
return -1;
}

pr_debug("Opening %s as cg yard\n", cg_yard);
i = open(cg_yard, O_DIRECTORY);
if (i < 0) {
pr_perror("Can't open cgyard");
goto err;
return -1;
}

ret = install_service_fd(CGROUP_YARD, i);
if (ret < 0)
goto err;
return -1;

paux[off++] = '/';

Expand All @@ -1794,7 +1794,7 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)

if (ctrl->n_cnames < 1) {
pr_err("Each cg_controller_entry must have at least 1 controller\n");
goto err;
return -1;
}

ctl_off += ctrl_dir_and_opt(ctrl,
Expand All @@ -1811,11 +1811,11 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
pr_debug("\tMaking controller dir %s (%s)\n", paux, opt);
if (mkdir(paux, 0700)) {
pr_perror("\tCan't make controller dir %s", paux);
goto err;
return -1;
}
if (mount("none", paux, fstype, 0, opt) < 0) {
pr_perror("\tCan't mount controller dir %s", paux);
goto err;
return -1;
}
}

Expand All @@ -1827,14 +1827,10 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
if (opts.manage_cgroups &&
prepare_cgroup_dirs(ctrl->cnames, ctrl->n_cnames, yard, yard_off,
ctrl->dirs, ctrl->n_dirs))
goto err;
return -1;
}

return 0;

err:
fini_cgroup();
return -1;
}

static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controllers,
Expand Down
11 changes: 5 additions & 6 deletions criu/cr-restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -2459,8 +2459,6 @@ static int restore_root_task(struct pstree_item *init)
if (restore_freezer_state())
pr_err("Unable to restore freezer state\n");

fini_cgroup();

/* Detaches from processes and they continue run through sigreturn. */
if (finalize_restore_detach())
goto out_kill_network_unlocked;
Expand Down Expand Up @@ -2507,7 +2505,6 @@ static int restore_root_task(struct pstree_item *init)
}

out:
fini_cgroup();
depopulate_roots_yard(mnt_ns_fd, true);
stop_usernsd();
__restore_switch_stage(CR_STATE_FAIL);
Expand Down Expand Up @@ -2595,15 +2592,17 @@ int cr_restore_tasks(void)
goto err;

if (crtools_prepare_shared() < 0)
goto err;
goto clean_cgroup;

if (criu_signals_setup() < 0)
goto err;
goto clean_cgroup;

if (prepare_lazy_pages_socket() < 0)
goto err;
goto clean_cgroup;

ret = restore_root_task(root_item);
clean_cgroup:
fini_cgroup();
err:
cr_plugin_fini(CR_PLUGIN_STAGE__RESTORE, ret);
return ret;
Expand Down

0 comments on commit 379884b

Please sign in to comment.