aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVikas Shivappa <vikas.shivappa@linux.intel.com>2017-04-19 19:50:04 -0400
committerThomas Gleixner <tglx@linutronix.de>2017-04-20 09:57:59 -0400
commit4797b7dfdfcf457075c36743d71e2b0feeaaa20f (patch)
tree492d523c4e644e22fbca5cc6ea93734d33881c8e
parent634b0e0491d6f6e882b922eb41c278d01a743bab (diff)
x86/intel_rdt: Return error for incorrect resource names in schemata
When schemata parses the resource names it does not return an error if it detects incorrect resource names and fails quietly. This happens because for_each_enabled_rdt_resource(r) leaves "r" pointing beyond the end of the rdt_resources_all[] array, and the check for !r->name results in an out of bounds access. Split the resource parsing part into a helper function to avoid the issue. [ tglx: Made it readable by splitting the parser loop out into a function ] Reported-by: Prakhya, Sai Praneeth <sai.praneeth.prakhya@intel.com> Signed-off-by: Vikas Shivappa <vikas.shivappa@linux.intel.com> Tested-by: Prakhya, Sai Praneeth <sai.praneeth.prakhya@intel.com> Cc: fenghua.yu@intel.com Cc: tony.luck@intel.com Cc: ravi.v.shankar@intel.com Cc: vikas.shivappa@intel.com Link: http://lkml.kernel.org/r/1492645804-17465-4-git-send-email-vikas.shivappa@linux.intel.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r--arch/x86/kernel/cpu/intel_rdt_schemata.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/arch/x86/kernel/cpu/intel_rdt_schemata.c b/arch/x86/kernel/cpu/intel_rdt_schemata.c
index e64b2cf1c428..406d7a6532f9 100644
--- a/arch/x86/kernel/cpu/intel_rdt_schemata.c
+++ b/arch/x86/kernel/cpu/intel_rdt_schemata.c
@@ -188,6 +188,17 @@ done:
188 return 0; 188 return 0;
189} 189}
190 190
191static int rdtgroup_parse_resource(char *resname, char *tok, int closid)
192{
193 struct rdt_resource *r;
194
195 for_each_enabled_rdt_resource(r) {
196 if (!strcmp(resname, r->name) && closid < r->num_closid)
197 return parse_line(tok, r);
198 }
199 return -EINVAL;
200}
201
191ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of, 202ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
192 char *buf, size_t nbytes, loff_t off) 203 char *buf, size_t nbytes, loff_t off)
193{ 204{
@@ -210,9 +221,10 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
210 221
211 closid = rdtgrp->closid; 222 closid = rdtgrp->closid;
212 223
213 for_each_enabled_rdt_resource(r) 224 for_each_enabled_rdt_resource(r) {
214 list_for_each_entry(dom, &r->domains, list) 225 list_for_each_entry(dom, &r->domains, list)
215 dom->have_new_ctrl = false; 226 dom->have_new_ctrl = false;
227 }
216 228
217 while ((tok = strsep(&buf, "\n")) != NULL) { 229 while ((tok = strsep(&buf, "\n")) != NULL) {
218 resname = strim(strsep(&tok, ":")); 230 resname = strim(strsep(&tok, ":"));
@@ -220,19 +232,9 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
220 ret = -EINVAL; 232 ret = -EINVAL;
221 goto out; 233 goto out;
222 } 234 }
223 for_each_enabled_rdt_resource(r) { 235 ret = rdtgroup_parse_resource(resname, tok, closid);
224 if (!strcmp(resname, r->name) && 236 if (ret)
225 closid < r->num_closid) {
226 ret = parse_line(tok, r);
227 if (ret)
228 goto out;
229 break;
230 }
231 }
232 if (!r->name) {
233 ret = -EINVAL;
234 goto out; 237 goto out;
235 }
236 } 238 }
237 239
238 for_each_enabled_rdt_resource(r) { 240 for_each_enabled_rdt_resource(r) {