Rework cpu affinity parsing

The CPU_SET_S api is pretty bad. In particular, it has a parameter for the size
of the array, but operations which take two (CPU_EQUAL_S) or even three arrays
(CPU_{AND,OR,XOR}_S) still take just one size. This means that all arrays must
be of the same size, or buffer overruns will occur. This is exactly what our
code would do, if it received an array of unexpected size over the network.
("Unexpected" here means anything different from what cpu_set_malloc() detects
as the "right" size.)

Let's rework this, and store the size in bytes of the allocated storage area.

The code will now parse any number up to 8191, independently of what the current
kernel supports. This matches the kernel maximum setting for any architecture,
to make things more portable.

Fixes #12605.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2019-05-29 10:20:42 +02:00
parent b12ef71416
commit 0985c7c4e2
14 changed files with 293 additions and 254 deletions
+2 -2
View File
@@ -14,6 +14,7 @@ typedef struct Manager Manager;
#include <sys/capability.h>
#include "cgroup-util.h"
#include "cpu-set-util.h"
#include "fdset.h"
#include "list.h"
#include "missing_resource.h"
@@ -172,8 +173,7 @@ struct ExecContext {
int cpu_sched_policy;
int cpu_sched_priority;
unsigned cpuset_ncpus;
cpu_set_t *cpuset;
CPUSet cpu_set;
ExecInput std_input;
ExecOutput std_output;