From: spshykX Date: Tue, 21 Mar 2017 10:13:55 +0000 (+0000) Subject: intel_rdt: fix validation of configured core id values X-Git-Tag: collectd-5.8.0~203^2 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=06e3485ad08e85188fd3431bed8bcb810c9b2fea intel_rdt: fix validation of configured core id values Change-Id: Ia009635c93e1cecd9852326b01c62fc6d2b090b5 Signed-off-by: Serhiy Pshyk --- diff --git a/src/intel_rdt.c b/src/intel_rdt.c index e2e2e394..fc2a5f17 100644 --- a/src/intel_rdt.c +++ b/src/intel_rdt.c @@ -252,14 +252,13 @@ static int cgroup_set(rdt_core_group_t *cg, char *desc, uint64_t *cores, * `item' Config option containing core groups. * `groups' Table of core groups to set values in. * `max_groups' Maximum number of core groups allowed. - * `max_core' Maximum allowed core value. * * RETURN VALUE * On success, the number of core groups set up. On error, appropriate * negative error value. */ static int oconfig_to_cgroups(oconfig_item_t *item, rdt_core_group_t *groups, - size_t max_groups, uint64_t max_core) { + size_t max_groups) { int index = 0; assert(groups != NULL); @@ -285,14 +284,6 @@ static int oconfig_to_cgroups(oconfig_item_t *item, rdt_core_group_t *groups, return (-EINVAL); } - for (int i = 0; i < n; i++) { - if (cores[i] > max_core) { - ERROR(RDT_PLUGIN ": Core group (%s) contains invalid core id (%d)", - item->values[j].value.string, (int)cores[i]); - return (-EINVAL); - } - } - /* set core group info */ ret = cgroup_set(&groups[index], item->values[j].value.string, cores, n); if (ret < 0) @@ -395,6 +386,15 @@ static int rdt_default_cgroups(void) { return g_rdt->pqos_cpu->num_cores; } +static int rdt_is_core_id_valid(int core_id) { + + for (int i = 0; i < g_rdt->pqos_cpu->num_cores; i++) + if (core_id == g_rdt->pqos_cpu->cores[i].lcore) + return 1; + + return 0; +} + static int rdt_config_cgroups(oconfig_item_t *item) { int n = 0; enum pqos_mon_event events = 0; @@ -413,14 +413,27 @@ static int rdt_config_cgroups(oconfig_item_t *item) { DEBUG(RDT_PLUGIN ": [%d]: %s", j, item->values[j].value.string); } - n = oconfig_to_cgroups(item, g_rdt->cgroups, RDT_MAX_CORES, - g_rdt->pqos_cpu->num_cores - 1); + n = oconfig_to_cgroups(item, g_rdt->cgroups, g_rdt->pqos_cpu->num_cores); if (n < 0) { rdt_free_cgroups(); ERROR(RDT_PLUGIN ": Error parsing core groups configuration."); return (-EINVAL); } + /* validate configured core id values */ + for (int group_idx = 0; group_idx < n; group_idx++) { + for (int core_idx = 0; core_idx < g_rdt->cgroups[group_idx].num_cores; + core_idx++) { + if (!rdt_is_core_id_valid(g_rdt->cgroups[group_idx].cores[core_idx])) { + ERROR(RDT_PLUGIN ": Core group '%s' contains invalid core id '%d'", + g_rdt->cgroups[group_idx].desc, + (int)g_rdt->cgroups[group_idx].cores[core_idx]); + rdt_free_cgroups(); + return (-EINVAL); + } + } + } + if (n == 0) { /* create default core groups if "Cores" config option is empty */ n = rdt_default_cgroups();