Skip to contentSkip to conversation

kernfs: fix hash calculation in kernfs_rename_ns()

PATCH In review Tejun Heo 2 participants 4 messages Feb 10, 2014 – Feb 11, 2014 kernfs

lore
Share & tools
lore

Tejun Heo

author maintainer
#0 lore raw

PATCH 1/1 kernfs: fix hash calculation in kernfs_rename_ns()

3eef34ad7dc3 ("kernfs: implement kernfs_get_parent(), kernfs_name/path() and friends") restructured kernfs_rename_ns() such that new name assignment happens under kernfs_rename_lock; unfortunately, it mistakenly passed NULL to kernfs_name_hash() to calculate the new hash if the name hasn't changed, which can lead to oops.

Fix it by using kn->name and kn->ns when calculating the new hash.

---
 fs/kernfs/dir.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/kernfs/dir.c +1 -1
index 939684e..ba8c858 100644
@@ -1296,7 +1296,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
 
 	spin_unlock_irq(&kernfs_rename_lock);
 
-	kn->hash = kernfs_name_hash(new_name, new_ns);
+	kn->hash = kernfs_name_hash(kn->name, kn->ns);
 	kernfs_link_sibling(kn);
 
 	kernfs_put(old_parent);
#1 lore raw
Quoted 8 lines · Tejun Heo

3eef34ad7dc3 ("kernfs: implement kernfs_get_parent(), kernfs_name/path() and friends") restructured kernfs_rename_ns() such that new name assignment happens under kernfs_rename_lock; unfortunately, it mistakenly passed NULL to kernfs_name_hash() to calculate the new hash if the name hasn't changed, which can lead to oops.

Fix it by using kn->name and kn->ns when calculating the new hash.

Now applied, thanks.

Also, can you look into the merge of 3.14-rc2 into the driver-core-next branch? There are some conflicts in the kernfs code due to the lockdep changes that I couldn't easily verify I got right, so I didn't do the merge. Could you give me a diff of the merge for me to work off of?

thanks,

greg k-h

author maintainer
#2 lore raw

Hello, Greg.

Quoted 4 lines · Greg Kroah-Hartman

Also, can you look into the merge of 3.14-rc2 into the driver-core-next branch? There are some conflicts in the kernfs code due to the lockdep changes that I couldn't easily verify I got right, so I didn't do the merge. Could you give me a diff of the merge for me to work off of?

Sure thing. It can be resolved by simply ignoring the driver-core-linus side. kernfs_drain() updates in driver-core-next already has all the necessary lockdep flag checks through kernfs_lockdep().

The following git branch contains a test merge between driver-core-next and rc2.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git driver-core-next-test-merge-rc2

Thanks!

Signature · 1 line
tejun
#3 lore raw
Quoted 13 lines · Tejun Heo

Hello, Greg.

Quoted 4 lines · Greg Kroah-Hartman

Also, can you look into the merge of 3.14-rc2 into the driver-core-next branch? There are some conflicts in the kernfs code due to the lockdep changes that I couldn't easily verify I got right, so I didn't do the merge. Could you give me a diff of the merge for me to work off of?

Sure thing. It can be resolved by simply ignoring the driver-core-linus side. kernfs_drain() updates in driver-core-next already has all the necessary lockdep flag checks through kernfs_lockdep().

Quoted 4 lines

The following git branch contains a test merge between driver-core-next and rc2.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git driver-core-next-test-merge-rc2

Thanks, I took this merge and pulled it into my tree.

greg k-h