Skip to content

Commit

Permalink
sysfs_notify is only possible on file attributes
Browse files Browse the repository at this point in the history
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)

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Nick Dyer authored and Greg Kroah-Hartman committed Jun 7, 2013
1 parent d6c8aa3 commit fc60bb8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions fs/sysfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fc60bb8

Please sign in to comment.