Skip to contentSkip to conversation

Fix null pointer dereference caused by sysfs_notify on binary attribute

PATCH In review Nick Dyer 2 participants 5 messages Jun 6, 2013 – Jun 7, 2013 Driver core

lore
Share & tools
lore

Nick Dyer

author
#0 lore raw

PATCH 1/1 Fix null pointer dereference caused by sysfs_notify on binary attribute

It would be nice to have this work as expected but for now this is a minimal fix to prevent the kernel panic.

---
 fs/sysfs/file.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
fs/sysfs/file.c +6 -4
index 602f56d..976819b 100644
@@ -449,10 +449,12 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
 
 	spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
 
-	od = sd->s_attr.open;
-	if (od) {
-		atomic_inc(&od->event);
-		wake_up_interruptible(&od->poll);
+	if (sd->s_attr) {
+		od = sd->s_attr.open;
+		if (od) {
+			atomic_inc(&od->event);
+			wake_up_interruptible(&od->poll);
+		}
 	}
 
 	spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
Signature · 1 line
1.7.10.4
maintainer
#1 lore raw
Quoted 2 lines · Nick Dyer

It would be nice to have this work as expected but for now this is a minimal fix to prevent the kernel panic.

Is anyone calling sysfs_notify on a binary attribute today? Or can this go into 3.11?

thanks,

greg k-h

author
#2 lore raw
Quoted 6 lines · Greg KH
Quoted 2 lines · Nick Dyer

It would be nice to have this work as expected but for now this is a minimal fix to prevent the kernel panic.

Is anyone calling sysfs_notify on a binary attribute today? Or can this go into 3.11?

Nope. I think I'm the first person to try it. So 3.11 is fine.

maintainer
#3 lore raw

Re: [PATCH] sysfs: Fix null pointer dereference caused by sysfs_notify on binary attribute

In reply to Nick Dyer
Quoted 19 lines · Nick Dyer

If sysfs_notify is called on a binary attribute, bad things can happen, so prevent it.

Note, no in-kernel usage of this is currently present, but in the future, it's good to be safe.

---
 fs/sysfs/file.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
fs/sysfs/file.c +0 -0
index 602f56d..976819b 100644
@@ -449,10 +449,12 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
 
 	spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
 

fs/sysfs/file.c void sysfs_notify_dirent(struct sysfs_dirent *sd) · line 457

Quoted 10 lines
fs/sysfs/file.c +6 -4
-	od = sd->s_attr.open;
-	if (od) {
-		atomic_inc(&od->event);
-		wake_up_interruptible(&od->poll);
+	if (sd->s_attr) {
+		od = sd->s_attr.open;
+		if (od) {
+			atomic_inc(&od->event);
+			wake_up_interruptible(&od->poll);
+		}

Please test build your patches, it makes kernel maintainers very grumpy when you send them patches that are obviously broken :(

greg k-h

author
#4 lore raw

PATCH v2 1/1 sysfs_notify is only possible on file attributes

If sysfs_notify is called on a binary attribute, bad things can happen, so prevent it.

Note, no in-kernel usage of this is currently present, but in the future, it's good to be safe.

Changes in V2:
- Also ignore sysfs_notify on dirs, links
- Use WARN_ON rather than silently failing
- Compiled and tested (huge apologies about first submission)

---
 fs/sysfs/file.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
fs/sysfs/file.c +6 -4
index 602f56d..d2bb7ed 100644
@@ -449,10 +449,12 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
 
 	spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
 
-	od = sd->s_attr.open;
-	if (od) {
-		atomic_inc(&od->event);
-		wake_up_interruptible(&od->poll);
+	if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
+		od = sd->s_attr.open;
+		if (od) {
+			atomic_inc(&od->event);
+			wake_up_interruptible(&od->poll);
+		}
 	}
 
 	spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
Signature · 1 line
1.7.10.4