Commit f57b3087 authored by Fenghua Yu's avatar Fenghua Yu Committed by Thomas Gleixner

x86/intel_rdt: Protect info directory from removal

The info directory and the per-resource subdirectories of the info
directory have no reference to a struct rdtgroup in kn->priv. An attempt to
remove one of those directories results in a NULL pointer dereference.

Protect the directories from removal and return -EPERM instead of -ENOENT.

[ tglx: Massaged changelog ]
Signed-off-by: default avatarFenghua Yu <fenghua.yu@intel.com>
Cc: "Ravi V Shankar" <ravi.v.shankar@intel.com>
Cc: "Tony Luck" <tony.luck@intel.com>
Cc: "Sai Prakhya" <sai.praneeth.prakhya@intel.com>
Cc: "Vikas Shivappa" <vikas.shivappa@linux.intel.com>
Cc: "Ingo Molnar" <mingo@elte.hu>
Cc: "H. Peter Anvin" <h.peter.anvin@intel.com>
Link: http://lkml.kernel.org/r/1478912558-55514-1-git-send-email-fenghua.yu@intel.comSigned-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 458b0d6e
...@@ -644,16 +644,29 @@ static int parse_rdtgroupfs_options(char *data) ...@@ -644,16 +644,29 @@ static int parse_rdtgroupfs_options(char *data)
*/ */
static struct rdtgroup *kernfs_to_rdtgroup(struct kernfs_node *kn) static struct rdtgroup *kernfs_to_rdtgroup(struct kernfs_node *kn)
{ {
if (kernfs_type(kn) == KERNFS_DIR) if (kernfs_type(kn) == KERNFS_DIR) {
return kn->priv; /*
else * All the resource directories use "kn->priv"
* to point to the "struct rdtgroup" for the
* resource. "info" and its subdirectories don't
* have rdtgroup structures, so return NULL here.
*/
if (kn == kn_info || kn->parent == kn_info)
return NULL;
else
return kn->priv;
} else {
return kn->parent->priv; return kn->parent->priv;
}
} }
struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn) struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn)
{ {
struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn); struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn);
if (!rdtgrp)
return NULL;
atomic_inc(&rdtgrp->waitcount); atomic_inc(&rdtgrp->waitcount);
kernfs_break_active_protection(kn); kernfs_break_active_protection(kn);
...@@ -670,6 +683,9 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn) ...@@ -670,6 +683,9 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn)
{ {
struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn); struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn);
if (!rdtgrp)
return;
mutex_unlock(&rdtgroup_mutex); mutex_unlock(&rdtgroup_mutex);
if (atomic_dec_and_test(&rdtgrp->waitcount) && if (atomic_dec_and_test(&rdtgrp->waitcount) &&
...@@ -918,7 +934,7 @@ static int rdtgroup_rmdir(struct kernfs_node *kn) ...@@ -918,7 +934,7 @@ static int rdtgroup_rmdir(struct kernfs_node *kn)
rdtgrp = rdtgroup_kn_lock_live(kn); rdtgrp = rdtgroup_kn_lock_live(kn);
if (!rdtgrp) { if (!rdtgrp) {
rdtgroup_kn_unlock(kn); rdtgroup_kn_unlock(kn);
return -ENOENT; return -EPERM;
} }
/* Give any tasks back to the default group */ /* Give any tasks back to the default group */
......
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