From: tip-bot for Fenghua Yu <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: mingo@kernel.org, mingo@elte.hu, tony.luck@intel.com,
fenghua.yu@intel.com, sai.praneeth.prakhya@intel.com,
ravi.v.shankar@intel.com, h.peter.anvin@intel.com,
linux-kernel@vger.kernel.org, tglx@linutronix.de,
vikas.shivappa@linux.intel.com, hpa@zytor.com
Subject: [tip:x86/cache] x86/intel_rdt: Protect info directory from removal
Date: Tue, 15 Nov 2016 09:42:58 -0800 [thread overview]
Message-ID: <tip-f57b308728902d9ffade53466e9201e999a870e4@git.kernel.org> (raw)
In-Reply-To: <1478912558-55514-1-git-send-email-fenghua.yu@intel.com>
Commit-ID: f57b308728902d9ffade53466e9201e999a870e4
Gitweb: http://git.kernel.org/tip/f57b308728902d9ffade53466e9201e999a870e4
Author: Fenghua Yu <fenghua.yu@intel.com>
AuthorDate: Fri, 11 Nov 2016 17:02:36 -0800
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 15 Nov 2016 18:35:49 +0100
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: Fenghua 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.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index 4795880..cff286e 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -644,16 +644,29 @@ static int parse_rdtgroupfs_options(char *data)
*/
static struct rdtgroup *kernfs_to_rdtgroup(struct kernfs_node *kn)
{
- if (kernfs_type(kn) == KERNFS_DIR)
- return kn->priv;
- else
+ if (kernfs_type(kn) == KERNFS_DIR) {
+ /*
+ * 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;
+ }
}
struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn)
{
struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn);
+ if (!rdtgrp)
+ return NULL;
+
atomic_inc(&rdtgrp->waitcount);
kernfs_break_active_protection(kn);
@@ -670,6 +683,9 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn)
{
struct rdtgroup *rdtgrp = kernfs_to_rdtgroup(kn);
+ if (!rdtgrp)
+ return;
+
mutex_unlock(&rdtgroup_mutex);
if (atomic_dec_and_test(&rdtgrp->waitcount) &&
@@ -918,7 +934,7 @@ static int rdtgroup_rmdir(struct kernfs_node *kn)
rdtgrp = rdtgroup_kn_lock_live(kn);
if (!rdtgrp) {
rdtgroup_kn_unlock(kn);
- return -ENOENT;
+ return -EPERM;
}
/* Give any tasks back to the default group */
prev parent reply other threads:[~2016-11-15 17:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-12 1:02 [PATCH 1/3] x86/intel_rdt: Fix kernfs_to_rdtgroup to know about "info/*" directories Fenghua Yu
2016-11-12 1:02 ` [PATCH 2/3] x86/intel_rdt: Return state to default on umount Fenghua Yu
2016-11-15 13:35 ` Thomas Gleixner
2016-11-15 17:28 ` Thomas Gleixner
2016-11-15 17:44 ` [tip:x86/cache] x86/intel_rdt: Reset per cpu closids on unmount tip-bot for Fenghua Yu
2016-11-12 1:02 ` [PATCH 3/3] x86/intel_rdt: Update closid in PQR_ASSOC registers in synchronous mode when changing "cpus" Fenghua Yu
2016-11-15 13:43 ` Thomas Gleixner
2016-11-15 14:00 ` Thomas Gleixner
2016-11-15 16:40 ` Thomas Gleixner
2016-11-15 17:44 ` [tip:x86/cache] x86/intel_rdt: Update percpu closid immeditately on CPUs affected by changee tip-bot for Fenghua Yu
2016-11-15 17:42 ` tip-bot for Fenghua Yu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-f57b308728902d9ffade53466e9201e999a870e4@git.kernel.org \
--to=tipbot@zytor.com \
--cc=fenghua.yu@intel.com \
--cc=h.peter.anvin@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@kernel.org \
--cc=ravi.v.shankar@intel.com \
--cc=sai.praneeth.prakhya@intel.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=vikas.shivappa@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).