Skip to contentSkip to conversation

fs-sysfs bugfix of sysfs_hash_and_remove dereferencing before checking for NULL

PATCH In review Doug Thompson 2 participants 2 messages Jun 22, 2007 – Jun 25, 2007 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs-sysfs bugfix of sysfs_hash_and_remove dereferencing before checking for NULL

From: Douglas Thompson <[email protected]>

In tracking down one of my bugs in using sysfs, I found the kernel doing a NULL de-reference in function fs/sysfs/inode.c:sysfs_hash_and_remove(), when I (incorrectly) passed in a dentry value of NULL.

The check for NULL should occur BEFORE the dereference of 'dir'. This patch modifies the sequence and does the check FIRST

---

fs/sysfs/inode.c +3 -1
Index: linux-2.6.22-rc4-mm2/fs/sysfs/inode.c
===================================================================
@@ -285,7 +285,7 @@ void sysfs_drop_dentry(struct sysfs_dire
 int sysfs_hash_and_remove(struct dentry * dir, const char * name)
 {
 	struct sysfs_dirent **pos, *sd;
-	struct sysfs_dirent *parent_sd = dir->d_fsdata;
+	struct sysfs_dirent *parent_sd;
 	int found = 0;
 
 	if (!dir)
@@ -295,6 +295,8 @@ int sysfs_hash_and_remove(struct dentry 
 		/* no inode means this hasn't been made visible yet */
 		return -ENOENT;
 
+	parent_sd = dir->d_fsdata;
+
 	mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
 	for (pos = &parent_sd->s_children; *pos; pos = &(*pos)->s_sibling) {
 		sd = *pos;
#1 lore raw
Quoted 6 lines · Doug Thompson

From: Douglas Thompson <[email protected]>

In tracking down one of my bugs in using sysfs, I found the kernel doing a NULL de-reference in function fs/sysfs/inode.c:sysfs_hash_and_remove(), when I (incorrectly) passed in a dentry value of NULL.

Quoted 8 lines

The check for NULL should occur BEFORE the dereference of 'dir'. This patch modifies the sequence and does the check FIRST

---

Index: linux-2.6.22-rc4-mm2/fs/sysfs/inode.c

There's been a lot of churn and change in this area and this patch doens't apply anymore. Can you try respinning it against the next -mm release and resending it if it is still needed?

thanks,

greg k-h