]> git.neil.brown.name Git - history.git/commit
[PATCH] sysfs: pin kobjects to fix use-after-free crashes
authorAndrew Morton <akpm@osdl.org>
Thu, 18 Mar 2004 22:59:41 +0000 (14:59 -0800)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Thu, 18 Mar 2004 22:59:41 +0000 (14:59 -0800)
commit2c0e195ba4530094ac14d8219362bdf290b28812
treeff0186045be73865cb1539d0c8b00373012b26f8
parentb67cee68c51ee8b1b4be249a23efae16baa5e2e1
[PATCH] sysfs: pin kobjects to fix use-after-free crashes

From: Maneesh Soni <maneesh@in.ibm.com>

Fix a sysfs use-after-free crash.  The problem we have is of the kobject
going away while we have a live dentry (the corresponding sysfs directory)
still pointing to it throuh d_fsdata pointer.  The patch makes sure to keep
the kobject alive by taking a reference to it during the life-time of
corresponding dentry.

o The following pins the kobject when sysfs assigns dentry and inode to
  the kobject. This ensures that kobject is alive during the life time of
  the dentry and inode, and people holding ref. to the dentry can access the
  kobject without any problems.

o The ref. taken for the kobject is released through dentry->d_op->d_iput()
  call when the dentry ref. count drops to zero and it is being freed. For
  this sysfs_dentry_operations is introduced.

For testing one has to run the following test on a SMP box:

1) Do insmod/rmmod "dummy.o" network driver in a forever loop.

2) Parallely do "find /sys/class/net | xargs cat" also in a forever loop.
fs/sysfs/dir.c