login
Header Space

 
 

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

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>
Cc: Eric W. Biederman <ebiederm@...>, Tejun Heo <htejun@...>, Greg Kroah-Hartman <gregkh@...>, Al Viro <viro@...>, Daniel Lezcano <dlezcano@...>, Serge E. Hallyn <serue@...>, Pavel Emelyanov <xemul@...>, <netdev@...>, Benjamin Thery <benjamin.thery@...>
Date: Tuesday, May 6, 2008 - 1:32 pm

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);

-- 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

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