mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] fs-sysfs bugfix of sysfs_hash_and_remove dereferencing before checking for NULL
@ 2007-06-22 17:13 Doug Thompson
  2007-06-25 21:25 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Doug Thompson @ 2007-06-22 17:13 UTC (permalink / raw)
  To: Greg K-H, linux-kernel

From:	Douglas Thompson <dougthompson@xmission.com>

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


Signed-off-by:	Douglas Thompson <dougthompson@xmission.com>
---

Index: linux-2.6.22-rc4-mm2/fs/sysfs/inode.c
===================================================================
--- linux-2.6.22-rc4-mm2.orig/fs/sysfs/inode.c
+++ 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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-06-25 21:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-22 17:13 [PATCH 1/1] fs-sysfs bugfix of sysfs_hash_and_remove dereferencing before checking for NULL Doug Thompson
2007-06-25 21:25 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®