Commit 831d155c authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Andrei Vagin

cgroup: Separate devices.list cgroup restoring

Now restore_special_property() only deals which special property
restore and restore_devices_list() deals with devices.list.

BTW, let's have two variables dev_allow and dev_deny on stack
to simplify it - all this fuss with old_val and old_name
kills the fun.
Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent f14cdada
...@@ -1371,6 +1371,54 @@ int prepare_cgroup_properties(void) ...@@ -1371,6 +1371,54 @@ int prepare_cgroup_properties(void)
return 0; return 0;
} }
/*
* The devices cgroup must be restored in a special way:
* only the contents of devices.list can be read, and it is a whitelist
* of all the devices the cgroup is allowed to create. To re-create
* this whitelist, we firstly deny everything via devices.deny,
* and then write the list back into devices.allow.
*
* Further, we must have a write() call for each line, because the kernel
* only parses the first line of any write().
*/
static int restore_devices_list(char *paux, size_t off, CgroupPropEntry *pr)
{
CgroupPropEntry dev_allow = *pr;
CgroupPropEntry dev_deny = *pr;
char *pos;
int ret;
dev_allow.name = "devices.allow";
dev_deny.name = "devices.deny";
dev_deny.value = "a";
ret = restore_cgroup_prop(&dev_deny, paux, off);
/*
* An emptry string here means nothing is allowed,
* and the kernel disallows writing an "" to devices.allow,
* so let's just keep going.
*/
if (!strcmp(dev_allow.value, ""))
return 0;
if (ret < 0)
return -1;
pos = dev_allow.value;
while (*pos) {
int offset = next_device_entry(pos);
dev_allow.value = pos;
ret = restore_cgroup_prop(&dev_allow, paux, off);
if (ret < 0)
return -1;
pos += offset;
}
return 0;
}
static int restore_special_property(char *paux, size_t off, CgroupPropEntry *pr) static int restore_special_property(char *paux, size_t off, CgroupPropEntry *pr)
{ {
/* /*
...@@ -1384,65 +1432,14 @@ static int restore_special_property(char *paux, size_t off, CgroupPropEntry *pr) ...@@ -1384,65 +1432,14 @@ static int restore_special_property(char *paux, size_t off, CgroupPropEntry *pr)
return 0; return 0;
if (!strcmp(pr->name, "devices.list")) { if (!strcmp(pr->name, "devices.list")) {
/*
* The devices cgroup must be restored in a special way:
* only the contents of devices.list can be read, and it
* is a whitelist of all the devices the cgroup is allowed
* to create. To re-create this whitelist, we firstly deny
* everything via devices.deny, and then write the list back
* into devices.allow.
*
* Further, we must have a write() call for each line,
* because the kernel only parses the first line of
* any write().
*/
CgroupPropEntry *pe = pr;
char *old_val = pe->value, *old_name = pe->name;
int ret;
char *pos;
/* /*
* A bit of a fudge here. These are write only by owner * A bit of a fudge here. These are write only by owner
* by default, but the container engine could have changed * by default, but the container engine could have changed
* the perms. We should come up with a better way to * the perms. We should come up with a better way to
* restore all of this stuff. * restore all of this stuff.
*/ */
pe->perms->mode = 0200; pr->perms->mode = 0200;
return restore_devices_list(paux, off, pr);
pe->name = "devices.deny";
pe->value = "a";
ret = restore_cgroup_prop(pr, paux, off);
pe->name = old_name;
pe->value = old_val;
/*
* An emptry string here means nothing is allowed,
* and the kernel disallows writing an "" to devices.allow,
* so let's just keep going.
*/
if (!strcmp(pe->value, ""))
return 0;
if (ret < 0)
return -1;
pe->name = "devices.allow";
pos = pe->value;
while (*pos) {
int offset = next_device_entry(pos);
pe->value = pos;
ret = restore_cgroup_prop(pe, paux, off);
if (ret < 0) {
pe->name = old_name;
pe->value = old_val;
return -1;
}
pos += offset;
}
pe->value = old_val;
pe->name = old_name;
return 0;
} }
return restore_cgroup_prop(pr, paux, off); return restore_cgroup_prop(pr, paux, off);
......
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