[RFC] sysfs null dentry pointer checking
From: John Zielinski
Date: Sun May 23 2004 - 14:48:38 EST
I've just discovered that some of the sysfs directory functions do not
check if the dentry pointer is valid. Some of the subsystems in the
kernel don't check the return value of subsystem_register since not
being able to create a directory in sysfs is not fatal and shouldn't
prevent booting the machine. Any kobject that tries to create a
directory under that subsystem would cause a null pointer dereference.
Here's a patch where the dentry pointers should be checked. The sysfs
directory structure wouldn't get updated if there were any directory
creation errors in a parent but the internal kset/kobject hierarchy
would still function properly.
John
diff -urNX dontdiff linux-2.6.6/fs/sysfs/dir.c linux/fs/sysfs/dir.c
--- linux-2.6.6/fs/sysfs/dir.c 2004-05-09 22:32:28.000000000 -0400
+++ linux/fs/sysfs/dir.c 2004-05-23 15:15:08.000000000 -0400
@@ -26,6 +26,9 @@
{
int error;
+ if (!p)
+ return -EFAULT;
+
down(&p->d_inode->i_sem);
*d = sysfs_get_dentry(p,n);
if (!IS_ERR(*d)) {
@@ -95,7 +98,8 @@
void sysfs_remove_subdir(struct dentry * d)
{
- remove_dir(d);
+ if (d)
+ remove_dir(d);
}
@@ -164,6 +168,11 @@
if (!kobj->parent)
return;
+ if (!kobj->dentry) {
+ kobject_set_name(kobj,new_name);
+ return;
+ }
+
parent = kobj->parent->dentry;
down(&parent->d_inode->i_sem);