The patch titled Fix kobject_rename and !CONFIG_SYSFS has been added to the -mm tree. Its filename is fix-kobject_rename-and-config_sysfs.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/ ------------------------------------------------------ Subject: Fix kobject_rename and !CONFIG_SYSFS From: Eric W. Biederman <ebiederm@xxxxxxxxxxxx> When looking at kobject_rename I found two bugs with that exist when sysfs support is disabled in the kernel. kobject_rename does not change the name on the kobject when sysfs support is not compiled in. kobject_rename without locking attempts to check the validity of a rename operation, which the kobject layer simply does not have the infrastructure to do so. This patch documents the previously unstated requirement of kobject_rename that is the responsibility of the caller to provide mutual exclusion and to be certain that the new_name for the kobject is valid. This patch modifies sysfs_rename_dir in !CONFIG_SYSFS case to call kobject_set_name to actually change the kobject_name. This patch removes the bogus and misleading check in kobject_rename that attempts to see if a rename is valid. The check is bogus because we do not have the proper locking. The check is misleading because it looks like we can and do perform useful checking at the kobject level that we don't. The users in net/core/dev.c already have all of the necessary checks in place and don't care. The other use in net/core/wireless.c as originally implemented is incorrect because it performs no locking and a simple patch has been sent that adds the necessary locking and sanity checks there. Ensuring this patch will not have an effect on users of kobject_rename or device_rename. Signed-off-by: Eric W. Biederman <ebiederm@xxxxxxxxxxxx> Cc: Greg KH <gregkh@xxxxxxx> Cc: Benjamin Thery <benjamin.thery@xxxxxxxx> Cc: Tejun Heo <htejun@xxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxx> Cc: Daniel Lezcano <dlezcano@xxxxxxxxxx> Cc: "Serge E. Hallyn" <serue@xxxxxxxxxx> Cc: Pavel Emelyanov <xemul@xxxxxxxxxx> Cc: Kay Sievers <kay.sievers@xxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- Documentation/kobject.txt | 4 ++++ drivers/base/core.c | 5 +++++ include/linux/sysfs.h | 2 +- lib/kobject.c | 18 +++++------------- 4 files changed, 15 insertions(+), 14 deletions(-) diff -puN Documentation/kobject.txt~fix-kobject_rename-and-config_sysfs Documentation/kobject.txt --- a/Documentation/kobject.txt~fix-kobject_rename-and-config_sysfs +++ a/Documentation/kobject.txt @@ -118,6 +118,10 @@ the name of the kobject, call kobject_re int kobject_rename(struct kobject *kobj, const char *new_name); +Note kobject_rename does perform any locking or have a solid notion of +what names are valid so the provide must provide their own sanity checking +and serialization. + There is a function called kobject_set_name() but that is legacy cruft and is being removed. If your code needs to call this function, it is incorrect and needs to be fixed. diff -puN drivers/base/core.c~fix-kobject_rename-and-config_sysfs drivers/base/core.c --- a/drivers/base/core.c~fix-kobject_rename-and-config_sysfs +++ a/drivers/base/core.c @@ -1308,6 +1308,11 @@ EXPORT_SYMBOL_GPL(device_destroy); * device_rename - renames a device * @dev: the pointer to the struct device to be renamed * @new_name: the new name of the device + * + * It is the responsibility of the caller to provide mutual + * exclusion between two different calls of device_rename + * on the same device to ensure that new_name is valid and + * won't conflict with other devices. */ int device_rename(struct device *dev, char *new_name) { diff -puN include/linux/sysfs.h~fix-kobject_rename-and-config_sysfs include/linux/sysfs.h --- a/include/linux/sysfs.h~fix-kobject_rename-and-config_sysfs +++ a/include/linux/sysfs.h @@ -138,7 +138,7 @@ static inline void sysfs_remove_dir(stru static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name) { - return 0; + return kobject_set_name(kobj, "%s", new_name); } static inline int sysfs_move_dir(struct kobject *kobj, diff -puN lib/kobject.c~fix-kobject_rename-and-config_sysfs lib/kobject.c --- a/lib/kobject.c~fix-kobject_rename-and-config_sysfs +++ a/lib/kobject.c @@ -435,6 +435,11 @@ EXPORT_SYMBOL_GPL(kobject_init_and_add); * kobject_rename - change the name of an object * @kobj: object in question. * @new_name: object's new name + * + * It is the responsibility of the caller to provide mutual + * exclusion between two different calls of kobject_rename + * on the same kobject and to ensure that new_name is valid and + * won't conflict with other kobjects. */ int kobject_rename(struct kobject *kobj, const char *new_name) { @@ -449,19 +454,6 @@ int kobject_rename(struct kobject *kobj, if (!kobj->parent) return -EINVAL; - /* see if this name is already in use */ - if (kobj->kset) { - struct kobject *temp_kobj; - temp_kobj = kset_find_obj(kobj->kset, new_name); - if (temp_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); - kobject_put(temp_kobj); - return -EINVAL; - } - } - devpath = kobject_get_path(kobj, GFP_KERNEL); if (!devpath) { error = -ENOMEM; _ Patches currently in -mm which might be from ebiederm@xxxxxxxxxxxx are origin.patch fix-kobject_rename-and-config_sysfs.patch proc-use-non-racy-method-for-proc-page_owner-creation-page_owner.patch put_pid-make-sure-we-dont-free-the-live-pid.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html