Junxiao Bi 76ae281f63 configfs: fix race between dentry put and lookup
A race window in configfs, it starts from one dentry is UNHASHED and end
before configfs_d_iput is called.  In this window, if a lookup happen,
since the original dentry was UNHASHED, so a new dentry will be
allocated, and then in configfs_attach_attr(), sd->s_dentry will be
updated to the new dentry.  Then in configfs_d_iput(),
BUG_ON(sd->s_dentry != dentry) will be triggered and system panic.

sys_open:                     sys_close:
 ...                           fput
                                dput
                                 dentry_kill
                                  __d_drop <--- dentry unhashed here,
                                           but sd->dentry still point
                                           to this dentry.

 lookup_real
  configfs_lookup
   configfs_attach_attr---> update sd->s_dentry
                            to new allocated dentry here.

                                   d_kill
                                     configfs_d_iput <--- BUG_ON(sd->s_dentry != dentry)
                                                     triggered here.

To fix it, change configfs_d_iput to not update sd->s_dentry if
sd->s_count > 2, that means there are another dentry is using the sd
beside the one that is going to be put.  Use configfs_dirent_lock in
configfs_attach_attr to sync with configfs_d_iput.

With the following steps, you can reproduce the bug.

1. enable ocfs2, this will mount configfs at /sys/kernel/config and
   fill configure in it.

2. run the following script.
	while [ 1 ]; do cat /sys/kernel/config/cluster/$your_cluster_name/idle_timeout_ms > /dev/null; done &
	while [ 1 ]; do cat /sys/kernel/config/cluster/$your_cluster_name/idle_timeout_ms > /dev/null; done &

Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-11-21 16:42:27 -08:00
..
2013-10-24 23:43:27 -04:00
2013-11-13 12:09:12 +09:00
2013-06-29 12:56:53 +04:00
2013-11-15 22:04:16 -05:00
2013-10-27 16:27:07 -07:00
2013-09-16 18:20:25 -07:00
2013-11-16 13:14:56 -08:00
2013-06-29 12:56:32 +04:00
2013-11-09 00:16:32 -05:00
2013-06-29 12:56:39 +04:00
2013-06-29 12:56:29 +04:00
2013-11-14 17:16:35 +09:00
2013-11-13 07:30:53 -05:00
2013-06-29 12:57:04 +04:00
2013-10-24 23:34:54 -04:00
2013-04-29 15:40:23 -04:00
2013-09-13 23:06:40 -04:00
2013-10-24 23:34:54 -04:00
2013-06-29 12:57:05 +04:00
2013-03-03 23:00:23 -05:00
2013-09-10 18:56:31 -04:00
2013-10-24 23:34:54 -04:00
2013-11-09 00:16:20 -05:00
2013-10-24 23:34:54 -04:00
2013-04-17 13:25:09 +01:00
2013-11-09 00:16:19 -05:00
2013-11-09 00:16:19 -05:00
2013-05-07 20:16:25 -07:00
2013-10-24 23:35:00 -04:00
2013-10-24 23:34:54 -04:00
2013-10-24 23:34:54 -04:00
2013-10-24 23:34:54 -04:00
2013-11-09 00:16:31 -05:00
2013-11-09 00:16:20 -05:00
2013-05-29 12:57:34 -07:00