[PATCH 10/11] avoid kobject name conflict with different namespaces

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Benjamin Thery
Date: Tuesday, May 6, 2008 - 10:32 am

The renaming of a kobject will fail if there is another kobject
with the same name belonging to another namespace.

This patch makes the kobject lookup in kobject_rename to check if
the object exists _and_ belongs to the same namespace.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Acked-by: Benjamin Thery <benjamin.thery@bull.net>
---
 fs/sysfs/dir.c        |   10 ++++++++++
 include/linux/sysfs.h |    7 +++++++
 lib/kobject.c         |    2 +-
 3 files changed, 18 insertions(+), 1 deletion(-)

Index: linux-vanilla/fs/sysfs/dir.c
===================================================================
--- linux-vanilla.orig/fs/sysfs/dir.c
+++ linux-vanilla/fs/sysfs/dir.c
@@ -902,6 +902,16 @@ err_out:
 	return error;
 }
 
+int sysfs_tag_cmp(struct kobject *kobj1, struct kobject *kobj2)
+{
+	struct sysfs_dirent *sd1 = kobj1->sd;
+	struct sysfs_dirent *sd2 = kobj2->sd;
+	const void *tag1 = sysfs_dirent_tag(sd1);
+	const void *tag2 = sysfs_dirent_tag(sd2);
+
+	return tag1 != tag2;
+}
+
 int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
 {
 	struct sysfs_dirent *sd = kobj->sd;
Index: linux-vanilla/include/linux/sysfs.h
===================================================================
--- linux-vanilla.orig/include/linux/sysfs.h
+++ linux-vanilla/include/linux/sysfs.h
@@ -95,6 +95,8 @@ int sysfs_schedule_callback(struct kobje
 
 int __must_check sysfs_create_dir(struct kobject *kobj);
 void sysfs_remove_dir(struct kobject *kobj);
+int sysfs_tag_cmp(struct kobject *kobj1, struct kobject *kobj2);
+
 int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
 int __must_check sysfs_move_dir(struct kobject *kobj,
 				struct kobject *new_parent_kobj);
@@ -154,6 +156,11 @@ static inline void sysfs_remove_dir(stru
 {
 }
 
+static inline int sysfs_tag_cmp(struct kobject *kobj1, struct kobject *kobj2)
+{
+	return 0;
+}
+
 static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
 {
 	return 0;
Index: linux-vanilla/lib/kobject.c
===================================================================
--- linux-vanilla.orig/lib/kobject.c
+++ linux-vanilla/lib/kobject.c
@@ -401,7 +401,7 @@ int kobject_rename(struct kobject *kobj,
 	if (kobj->kset) {
 		struct kobject *temp_kobj;
 		temp_kobj = kset_find_obj(kobj->kset, new_name);
-		if (temp_kobj) {
+		if (temp_kobj && !sysfs_tag_cmp(temp_kobj, kobj)) {
 			printk(KERN_WARNING "kobject '%s' cannot be renamed "
 			       "to '%s' as '%s' is already in existence.\n",
 			       kobject_name(kobj), new_name, new_name);

-- 
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 10/11] avoid kobject name conflict with different n ..., Benjamin Thery, (Tue May 6, 10:32 am)
Re: [PATCH 10/11] avoid kobject name conflict with differe ..., Eric W. Biederman, (Wed May 7, 11:49 am)
Re: [PATCH 10/11] avoid kobject name conflict with differe ..., Eric W. Biederman, (Thu May 8, 12:25 pm)
Re: [PATCH 10/11] avoid kobject name conflict with differe ..., Eric W. Biederman, (Thu May 8, 12:28 pm)
[PATCH] wireless: Add missing locking to cfg80211_dev_rename, Eric W. Biederman, (Thu May 8, 2:30 pm)
[PATCH] Fix kobject_rename and !CONFIG_SYSFS, Eric W. Biederman, (Thu May 8, 2:41 pm)
Re: [PATCH 10/11] avoid kobject name conflict with differe ..., Eric W. Biederman, (Fri May 9, 11:16 am)
Re: kobject: Fix kobject_rename and !CONFIG_SYSFS, Eric W. Biederman, (Tue May 13, 12:00 am)
Re: kobject: Fix kobject_rename and !CONFIG_SYSFS, Benjamin Thery, (Tue May 13, 7:25 am)
[PATCH] Fix kobject_rename and !CONFIG_SYSFS v2, Eric W. Biederman, (Tue May 13, 10:55 am)
Re: [PATCH] Fix kobject_rename and !CONFIG_SYSFS v2, Randy.Dunlap, (Tue May 13, 11:23 am)
Re: kobject: Fix kobject_rename and !CONFIG_SYSFS, Benjamin Thery , (Tue May 13, 12:33 pm)
Re: kobject: Fix kobject_rename and !CONFIG_SYSFS, Eric W. Biederman, (Tue May 13, 1:42 pm)
Re: [PATCH] Fix kobject_rename and !CONFIG_SYSFS v2, Eric W. Biederman, (Tue May 13, 1:43 pm)
[PATCH] Fix kobject_rename and !CONFIG_SYSFS v3, Eric W. Biederman, (Tue May 13, 1:45 pm)
Re: [PATCH] Fix kobject_rename and !CONFIG_SYSFS v3, Randy Dunlap, (Tue May 13, 2:18 pm)
[PATCH] Fix kobject_rename and !CONFIG_SYSFS v4, Eric W. Biederman, (Tue May 13, 9:39 pm)
Re: [PATCH] Fix kobject_rename and !CONFIG_SYSFS v4, Andrew Morton, (Tue May 13, 10:03 pm)
Re: [PATCH] Fix kobject_rename and !CONFIG_SYSFS v4, Eric W. Biederman, (Wed May 14, 2:01 am)
Re: [PATCH] Fix kobject_rename and !CONFIG_SYSFS v4, Andrew Morton, (Wed May 14, 2:20 am)
Re: [PATCH] Fix kobject_rename and !CONFIG_SYSFS v4, Benjamin Thery, (Wed May 14, 2:51 am)
Re: [PATCH] Fix kobject_rename and !CONFIG_SYSFS v4, Andrew Morton, (Wed May 14, 2:56 am)