Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runc exec: refuze paused container/cgroup #727

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/libcrun/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1867,16 +1867,21 @@ libcrun_cgroup_enter (struct libcrun_cgroup_args *args, libcrun_error_t *err)
}

int
libcrun_cgroup_is_container_paused (const char *cgroup_path, int cgroup_mode, bool *paused, libcrun_error_t *err)
libcrun_cgroup_is_container_paused (const char *cgroup_path, bool *paused, libcrun_error_t *err)
{
cleanup_free char *content = NULL;
cleanup_free char *path = NULL;
const char *state;
int cgroup_mode;
int ret;

if (cgroup_path == NULL || cgroup_path[0] == '\0')
return 0;

cgroup_mode = libcrun_get_cgroup_mode (err);
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

if (cgroup_mode == CGROUP_MODE_UNIFIED)
{
state = "1";
Expand Down
3 changes: 1 addition & 2 deletions src/libcrun/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ LIBCRUN_PUBLIC int libcrun_move_process_to_cgroup (pid_t pid, pid_t init_pid, ch
LIBCRUN_PUBLIC int libcrun_update_cgroup_resources (int cgroup_mode,
runtime_spec_schema_config_linux_resources *resources, char *path,
libcrun_error_t *err);
LIBCRUN_PUBLIC int libcrun_cgroup_is_container_paused (const char *cgroup_path, int cgroup_mode, bool *paused,
libcrun_error_t *err);
LIBCRUN_PUBLIC int libcrun_cgroup_is_container_paused (const char *cgroup_path, bool *paused, libcrun_error_t *err);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a breaking change in a public libcrun function, but I guess we probably don't hurt anyone :-) and the API is nicer

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debian packaging might complain about it (I barely remember they actually check that).

LIBCRUN_PUBLIC int libcrun_cgroup_pause_unpause (const char *path, const bool pause, libcrun_error_t *err);
LIBCRUN_PUBLIC int libcrun_cgroup_read_pids (const char *path, bool recurse, pid_t **pids, libcrun_error_t *err);

Expand Down
16 changes: 9 additions & 7 deletions src/libcrun/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -2893,13 +2893,7 @@ libcrun_get_container_state_string (const char *id, libcrun_container_status_t *

if (*running && ! has_fifo)
{
int cgroup_mode;

cgroup_mode = libcrun_get_cgroup_mode (err);
if (UNLIKELY (cgroup_mode < 0))
return cgroup_mode;

ret = libcrun_cgroup_is_container_paused (status->cgroup_path, cgroup_mode, &paused, err);
ret = libcrun_cgroup_is_container_paused (status->cgroup_path, &paused, err);
if (UNLIKELY (ret < 0))
{
/*
Expand Down Expand Up @@ -3051,6 +3045,7 @@ libcrun_container_exec (libcrun_context_t *context, const char *id, runtime_spec
libcrun_error_t *err)
{
int container_status, ret;
bool container_paused;
pid_t pid;
libcrun_container_status_t status = {};
const char *state_root = context->state_root;
Expand Down Expand Up @@ -3094,6 +3089,13 @@ libcrun_container_exec (libcrun_context_t *context, const char *id, runtime_spec
if (container_status == 0)
return crun_make_error (err, 0, "the container `%s` is not running.", id);

ret = libcrun_cgroup_is_container_paused (status.cgroup_path, &container_paused, err);
if (UNLIKELY (ret < 0))
return ret;

if (UNLIKELY (container_paused))
return crun_make_error (err, 0, "the container `%s` is paused.", id);

ret = block_signals (err);
if (UNLIKELY (ret < 0))
return ret;
Expand Down