mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Doug Thompson <norsk5@yahoo.com>
To: Greg K-H <greg@kroah.com>, linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] fs-sysfs bugfix of sysfs_hash_and_remove dereferencing before checking for NULL
Date: Fri, 22 Jun 2007 10:13:24 -0700 (PDT)	[thread overview]
Message-ID: <887490.81074.qm@web50106.mail.re2.yahoo.com> (raw)

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;

             reply	other threads:[~2007-06-22 17:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-22 17:13 Doug Thompson [this message]
2007-06-25 21:25 ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=887490.81074.qm@web50106.mail.re2.yahoo.com \
    --to=norsk5@yahoo.com \
    --cc=dougthompson@xmission.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®