Skip to contentSkip to conversation

x86/intel_rdt: Put group node in rdtgroup_kn_unlock

PATCH New Jiri Olsa 2 participants 2 messages Mar 14, 2017 x86

lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

PATCH 1/1 x86/intel_rdt: Put group node in rdtgroup_kn_unlock

The rdtgroup_kn_unlock waits for the last user to release and put its node. But it's calling kernfs_put on the node which calls the rdtgroup_kn_unlock, which might not be the group's directory node, but another group's file node.

This race could be easily reproduced by running 2 instances of following script:

mount -t resctrl resctrl /sys/fs/resctrl/
pushd /sys/fs/resctrl/
mkdir krava
echo "krava" > krava/schemata
rmdir krava
popd
umount /sys/fs/resctrl

It triggers the slub debug error message with following command line config: slub_debug=,kernfs_node_cache.

Calling kernfs_put on the group's node.

---
 arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +1 -1
index c05509d38b1f..9ac2a5cdd9c2 100644
@@ -727,7 +727,7 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn)
 	if (atomic_dec_and_test(&rdtgrp->waitcount) &&
 	    (rdtgrp->flags & RDT_DELETED)) {
 		kernfs_unbreak_active_protection(kn);
-		kernfs_put(kn);
+		kernfs_put(rdtgrp->kn);
 		kfree(rdtgrp);
 	} else {
 		kernfs_unbreak_active_protection(kn);
Signature · 1 line
2.9.3
#1 lore raw
x86/intel_rdt: Put group node in rdtgroup_kn_unlock
Commit-ID:  49ec8f5b6ae3ab60385492cad900ffc8a523c895
Gitweb:     http://git.kernel.org/tip/49ec8f5b6ae3ab60385492cad900ffc8a523c895
Author:     Jiri Olsa <[email protected]>
AuthorDate: Tue, 14 Mar 2017 15:20:53 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 14 Mar 2017 21:51:58 +0100

x86/intel_rdt: Put group node in rdtgroup_kn_unlock

The rdtgroup_kn_unlock waits for the last user to release and put its node. But it's calling kernfs_put on the node which calls the rdtgroup_kn_unlock, which might not be the group's directory node, but another group's file node.

This race could be easily reproduced by running 2 instances of following script:

mount -t resctrl resctrl /sys/fs/resctrl/
pushd /sys/fs/resctrl/
mkdir krava
echo "krava" > krava/schemata
rmdir krava
popd
umount /sys/fs/resctrl

It triggers the slub debug error message with following command line config: slub_debug=,kernfs_node_cache.

Call kernfs_put on the group's node to fix it.

Fixes 60cf5e101fd4 ("x86/intel_rdt: Add mkdir to resctrl file system")
Cc Fenghua Yu <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Shaohua Li <[email protected]>
---
 arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +1 -1
index c05509d..9ac2a5c 100644
@@ -727,7 +727,7 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn)
 	if (atomic_dec_and_test(&rdtgrp->waitcount) &&
 	    (rdtgrp->flags & RDT_DELETED)) {
 		kernfs_unbreak_active_protection(kn);
-		kernfs_put(kn);
+		kernfs_put(rdtgrp->kn);
 		kfree(rdtgrp);
 	} else {
 		kernfs_unbreak_active_protection(kn);