All of lore.kernel.org
 help / color / mirror / Atom feed
* [GIT PATCH] sysfs fixes for 2.6.22-rc4
@ 2007-06-12 23:21 Greg KH
  2007-06-12 23:22 ` [PATCH 1/3] sysfs: store sysfs inode nrs in s_ino to avoid readdir oopses Greg Kroah-Hartman
  2007-06-13  3:24 ` [GIT PATCH] sysfs fixes for 2.6.22-rc4 Eric Sandeen
  0 siblings, 2 replies; 6+ messages in thread
From: Greg KH @ 2007-06-12 23:21 UTC (permalink / raw)
  To: Linus Torvalds, Andrew Morton; +Cc: linux-kernel, htejun, sandeen

Here are some sysfs fixes for 2.6.22-rc4

They are based on a set of patches from Tejun that have been in the -mm
tree for a while and fix a nasty sysfs problem that people have been
hitting in the real world (Google has hit this a lot and spent a lot of
time and effort in tracking this down, I'd really like to say thanks for
the help here.)

Tejun and Eric have backported a small set of patches that fix this for
your current tree, with the larger, more intrusive patches queued up for
after 2.6.22 is out.

Tejun and I have beat on these patches a lot and have not found any
problems.  I know it's late in the series for them, but under the
circumstances, it seems reasonable.

Please pull from:
	master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/

Patches will be sent as a follow-on to this message to lkml for people
to see.

thanks,

greg k-h


 fs/sysfs/dir.c   |   38 +++++++++++++++++++++++++++++++-------
 fs/sysfs/inode.c |   21 +++++++++++++++++++--
 fs/sysfs/mount.c |    1 +
 fs/sysfs/sysfs.h |    2 ++
 4 files changed, 53 insertions(+), 9 deletions(-)

---------------

Eric Sandeen (1):
      sysfs: store sysfs inode nrs in s_ino to avoid readdir oopses

Tejun Heo (2):
      sysfs: fix condition check in sysfs_drop_dentry()
      sysfs: fix race condition around sd->s_dentry, take#2


^ permalink raw reply	[flat|nested] 6+ messages in thread
* [PATCHSET 2.6.22-rc4] sysfs: fix race conditions
@ 2007-06-11  5:01 Tejun Heo
  2007-06-11  5:03 ` [PATCH 2/3] sysfs: fix condition check in sysfs_drop_dentry() Tejun Heo
  0 siblings, 1 reply; 6+ messages in thread
From: Tejun Heo @ 2007-06-11  5:01 UTC (permalink / raw)
  To: linux-kernel, greg, akpm, cebbert, sandeen, maneesh, cs

[-- Attachment #1: Type: text/plain, Size: 1718 bytes --]

Hello, all.

Currently, there are several race conditions around dentry/inode
reclamation.

a. sysfs_dirent->s_dentry dereferencing in sysfs_readdir()

b. sysfs_dirent->s_dentry dereferencing in sysfs_drop_dentry()

c. sysfs_dirent->s_dentry clearing in sysfs_d_iput()

All aboves are done without synchronization and can cause oops if the
timing is right (or wrong).

These race conditions are difficult to trigger but with the attached
patch (sysfs-races.patch) and the following commands running
parallelly, all three are reliably reproducible (you may have to
change timings or disable others to trigger specific one).

1. while true; do insmod drivers/ata/libata.ko; insmod drivers/ata/ata_piix.ko; sleep 1; rmmod ata_piix; rmmod libata; sleep 1; echo -n . ; done
2. while true; do find /sys -type f | xargs cat > /dev/null; echo -n .; sleep 1; done
3. while true; do find /sys/class/scsi_disk -type f | sort | xargs cat > /dev/null; echo -n .; sleep 1; done
4. while true; do umount /sys; sleep 1; mount /sys; sleep 1; echo -n .; done

#1 assumes there are several devices attached to ata_piix controller.
Change #1 to any module or command which creates and removes sysfs
nodes repeatedly and adjust #3 to cat those sysfs nodes.

All known race conditions are fixed in the current -mm.  #a is
replaced by adding sd->s_ino and allocating unique ino with ida.  #b
and #c are fixed during sysfs_drop_dentry() rewrite.  However, those
changes were too big to apply to 2.6.22-rcX or any stable branches.

This patchset contains three minimal backports of fixes in -mm.  With
all patches in the patchset and sysfs-races.patch applied, kernel
survived ~20 hours of stress test without any problem.

Thanks.

-- 
tejun

[-- Attachment #2: sysfs-races.patch --]
[-- Type: text/x-diff, Size: 1187 bytes --]

---
 fs/sysfs/dir.c   |    7 +++++--
 fs/sysfs/inode.c |    2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

Index: work1/fs/sysfs/dir.c
===================================================================
--- work1.orig/fs/sysfs/dir.c
+++ work1/fs/sysfs/dir.c
@@ -18,6 +18,8 @@ static void sysfs_d_iput(struct dentry *
 {
 	struct sysfs_dirent * sd = dentry->d_fsdata;
 
+	udelay(10);
+
 	if (sd) {
 		BUG_ON(sd->s_dentry != dentry);
 		sd->s_dentry = NULL;
@@ -538,9 +540,10 @@ static int sysfs_readdir(struct file * f
 
 				name = sysfs_get_name(next);
 				len = strlen(name);
-				if (next->s_dentry)
+				if (next->s_dentry) {
+					msleep(1);
 					ino = next->s_dentry->d_inode->i_ino;
-				else
+				} else
 					ino = iunique(sysfs_sb, 2);
 
 				if (filldir(dirent, name, len, filp->f_pos, ino,
Index: work1/fs/sysfs/inode.c
===================================================================
--- work1.orig/fs/sysfs/inode.c
+++ work1/fs/sysfs/inode.c
@@ -248,6 +248,8 @@ void sysfs_drop_dentry(struct sysfs_dire
 	struct dentry * dentry = sd->s_dentry;
 	struct inode *inode;
 
+	msleep(1);
+
 	if (dentry) {
 		spin_lock(&dcache_lock);
 		spin_lock(&dentry->d_lock);

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

end of thread, other threads:[~2007-06-13  3:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-12 23:21 [GIT PATCH] sysfs fixes for 2.6.22-rc4 Greg KH
2007-06-12 23:22 ` [PATCH 1/3] sysfs: store sysfs inode nrs in s_ino to avoid readdir oopses Greg Kroah-Hartman
2007-06-12 23:22   ` [PATCH 2/3] sysfs: fix condition check in sysfs_drop_dentry() Greg Kroah-Hartman
2007-06-12 23:22     ` [PATCH 3/3] sysfs: fix race condition around sd->s_dentry, take#2 Greg Kroah-Hartman
2007-06-13  3:24 ` [GIT PATCH] sysfs fixes for 2.6.22-rc4 Eric Sandeen
  -- strict thread matches above, loose matches on Subject: below --
2007-06-11  5:01 [PATCHSET 2.6.22-rc4] sysfs: fix race conditions Tejun Heo
2007-06-11  5:03 ` [PATCH 2/3] sysfs: fix condition check in sysfs_drop_dentry() Tejun Heo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.