Skip to content

Commit 4797b7d

Browse files
Vikas ShivappaKAGA-KOKO
authored andcommitted
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>
1 parent 634b0e0 commit 4797b7d

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

‎arch/x86/kernel/cpu/intel_rdt_schemata.c‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ static int update_domains(struct rdt_resource *r, int closid)
188188
return 0;
189189
}
190190

191+
static 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+
191202
ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
192203
char *buf, size_t nbytes, loff_t off)
193204
{
@@ -210,29 +221,20 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
210221

211222
closid = rdtgrp->closid;
212223

213-
for_each_enabled_rdt_resource(r)
224+
for_each_enabled_rdt_resource(r) {
214225
list_for_each_entry(dom, &r->domains, list)
215226
dom->have_new_ctrl = false;
227+
}
216228

217229
while ((tok = strsep(&buf, "\n")) != NULL) {
218230
resname = strim(strsep(&tok, ":"));
219231
if (!tok) {
220232
ret = -EINVAL;
221233
goto out;
222234
}
223-
for_each_enabled_rdt_resource(r) {
224-
if (!strcmp(resname, r->name) &&
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;
235+
ret = rdtgroup_parse_resource(resname, tok, closid);
236+
if (ret)
234237
goto out;
235-
}
236238
}
237239

238240
for_each_enabled_rdt_resource(r) {

0 commit comments

Comments
 (0)