linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Junxiao Bi <junxiao.bi@oracle.com>,
	Joel Becker <jlbec@evilplan.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 3.12 113/116] configfs: fix race between dentry put and lookup
Date: Tue, 26 Nov 2013 16:58:06 -0800	[thread overview]
Message-ID: <20131127005744.754688213@linuxfoundation.org> (raw)
In-Reply-To: <20131127005736.915454872@linuxfoundation.org>

3.12-stable review patch.  If anyone has any objections, please let me know.

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

From: Junxiao Bi <junxiao.bi@oracle.com>

commit 76ae281f6307331aa063288edb6422ae99f435f0 upstream.

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>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/configfs/dir.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -56,10 +56,19 @@ static void configfs_d_iput(struct dentr
 	struct configfs_dirent *sd = dentry->d_fsdata;
 
 	if (sd) {
-		BUG_ON(sd->s_dentry != dentry);
 		/* Coordinate with configfs_readdir */
 		spin_lock(&configfs_dirent_lock);
-		sd->s_dentry = NULL;
+		/* Coordinate with configfs_attach_attr where will increase
+		 * sd->s_count and update sd->s_dentry to new allocated one.
+		 * Only set sd->dentry to null when this dentry is the only
+		 * sd owner.
+		 * If not do so, configfs_d_iput may run just after
+		 * configfs_attach_attr and set sd->s_dentry to null
+		 * even it's still in use.
+		 */
+		if (atomic_read(&sd->s_count) <= 2)
+			sd->s_dentry = NULL;
+
 		spin_unlock(&configfs_dirent_lock);
 		configfs_put(sd);
 	}
@@ -426,8 +435,11 @@ static int configfs_attach_attr(struct c
 	struct configfs_attribute * attr = sd->s_element;
 	int error;
 
+	spin_lock(&configfs_dirent_lock);
 	dentry->d_fsdata = configfs_get(sd);
 	sd->s_dentry = dentry;
+	spin_unlock(&configfs_dirent_lock);
+
 	error = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG,
 				configfs_init_file);
 	if (error) {



  parent reply	other threads:[~2013-11-27  1:00 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-27  0:56 [PATCH 3.12 000/116] 3.12.2-stable review Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 001/116] prepend_path() needs to reinitialize dentry/vfsmount/mnt on restarts Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 002/116] libertas: potential oops in debugfs Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 003/116] aacraid: prevent invalid pointer dereference Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 004/116] xfs: be more forgiving of a v4 secondary sb w/ junk in v5 fields Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 005/116] USB: mos7840: fix tiocmget error handling Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 006/116] can: kvaser_usb: fix usb endpoints detection Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 007/116] Btrfs: relocate csums properly with prealloc extents Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 008/116] crypto: ansi_cprng - Fix off by one error in non-block size request Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 009/116] crypto: s390 - Fix aes-cbc IV corruption Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 010/116] can: c_can: Fix RX message handling, handle lost message before EOB Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 011/116] alx: Reset phy speed after resume Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 012/116] ipc,shm: correct error return value in shmctl (SHM_UNLOCK) Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 013/116] ipc,shm: fix shm_file deletion races Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 014/116] drm: shmobile: Add dependency on BACKLIGHT_CLASS_DEVICE Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 015/116] staging: ashmem: Fix ASHMEM_PURGE_ALL_CACHES return value Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 016/116] drm/nvc0-/gr: fix a number of missing explicit array terminators Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 017/116] thinkpad_acpi: Fix build error when CONFIG_SND_MAX_CARDS > 32 Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 018/116] ARM: OMAP2+: hwmod: check for module address space during init Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 019/116] sched, idle: Fix the idle polling state logic Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 020/116] perf/ftrace: Fix paranoid level for enabling function tracer Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 021/116] ACPI / EC: Ensure lock is acquired before accessing ec struct members Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 022/116] ACPI / video: Quirk initial backlight level 0 Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 023/116] ACPI / hotplug: Fix handle_root_bridge_removal() Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 024/116] ACPI / hotplug: Do not execute "insert in progress" _OST Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 025/116] Staging: zram: Fix access of NULL pointer Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 026/116] staging: r8188eu: Set device type to wlan Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 027/116] staging: comedi: avoid memleak for subdevice private Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 028/116] lkdtm: isolate stack corruption test Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 029/116] Drivers: hv: vmbus: Fix a bug in channel rescind code Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 030/116] rt2x00: fix a crash bug in the HT descriptor handling fix Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 031/116] rt2x00: check if device is still available on rt2x00mac_flush() Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 032/116] rt2x00: rt2800lib: fix VGC adjustment for RT5592 Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 033/116] rt2x00: fix HT TX descriptor settings regression Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 034/116] Bluetooth: revert: "Bluetooth: Add missing reset_resume dev_pm_ops" Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 035/116] Revert "ima: policy for RAMFS" Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 036/116] exec/ptrace: fix get_dumpable() incorrect tests Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 037/116] ALSA: 6fire: Fix probe of multiple cards Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 038/116] ALSA: compress: fix drain calls blocking other compress functions Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 039/116] ALSA: compress: fix drain calls blocking other compress functions (v6) Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 040/116] ALSA: pcsp: Fix the order of input device unregistration Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 041/116] ALSA: hda - Apply GPIO setup for MacBooks with CS4208 Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 042/116] ALSA: hda - Apply MacBook fixups for CS4208 correctly Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 043/116] ALSA: msnd: Avoid duplicated driver name Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 044/116] ALSA: hda - Add support of ALC255 codecs Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 045/116] ALSA: hda - Introduce the bitmask for excluding output volume Greg Kroah-Hartman
2013-11-27  0:56 ` [PATCH 3.12 046/116] ALSA: hda - Enable SPDIF for Acer TravelMate 6293 Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 047/116] ALSA: hda - Force buffer alignment for Haswell HDMI controllers Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 048/116] ALSA: hda - Make sure mute LEDs stay on during runtime suspend (Realtek) Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 049/116] ALSA: hda - Add support for CX20952 Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 050/116] ALSA: hda - Add pincfg fixup for ASUS W5A Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 051/116] ALSA: hda - Fix Line Out automute on Realtek multifunction jacks Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 052/116] ALSA: hda - Check keep_eapd_on before inv_eapd Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 053/116] ALSA: hda - Dont turn off EAPD for headphone on Lenovo N100 Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 054/116] ALSA: hda - Dont clear the power state at snd_hda_codec_reset() Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 055/116] ALSA: hda - Fix unbalanced runtime PM notification at resume Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 056/116] ALSA: hda - Fix the headphone jack detection on Sony VAIO TX Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 057/116] ALSA: hda - Add headset quirk for Dell Inspiron 3135 Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 058/116] ALSA: hda - Provide missing pin configs for VAIO with ALC260 Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 059/116] NFSv4.2: Fix a mismatch between Linux labeled NFS and the NFSv4.2 spec Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 060/116] NFSv4: Fix a use-after-free situation in _nfs4_proc_getlk() Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 061/116] NFSv4: fix NULL dereference in open recover Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 062/116] NFSv4: dont fail on missing fattr " Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 063/116] NFSv4: dont reprocess cached open CLAIM_PREVIOUS Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 064/116] NFSv4: Fix state reference counting in _nfs4_opendata_reclaim_to_nfs4_state Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 065/116] nfs: fix inverted test for delegation in nfs4_reclaim_open_state Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 066/116] nfs: fix oops when trying to set SELinux label Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 067/116] NFS: Fix a missing initialisation when reading the " Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 068/116] nfsd: return better errors to exportfs Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 069/116] nfsd4: fix discarded security labels on setattr Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 070/116] nfs: dont retry detect_trunking with RPC_AUTH_UNIX more than once Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 071/116] nfsd: split up nfsd_setattr Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 072/116] nfsd: make sure to balance get/put_write_access Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 073/116] nfsd4: fix xdr decoding of large non-write compounds Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 074/116] x86/apic: Disable I/O APIC before shutdown of the local APIC Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 075/116] x86/microcode/amd: Tone down printk(), dont treat a missing firmware file as an error Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 076/116] KVM: x86: fix emulation of "movzbl %bpl, %eax" Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 077/116] ftrace/x86: skip over the breakpoint for ftrace caller Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 078/116] KVM: IOMMU: hva align mapping page size Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 079/116] arm/arm64: KVM: Fix hyp mappings of vmalloc regions Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 080/116] hwmon: (lm90) Fix max6696 alarm handling Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 081/116] drivers/memstick/core/ms_block.c: fix unreachable state in h_msb_read_page() Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 082/116] block: fix race between request completion and timeout handling Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 083/116] block: fix a probe argument to blk_register_region Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 084/116] block: properly stack underlying max_segment_size to DM device Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 085/116] powerpc/52xx: fix build breakage for MPC5200 LPBFIFO module Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 086/116] powerpc/mpc512x: silence build warning upon disabled DIU Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 087/116] powerpc/vio: use strcpy in modalias_show Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 088/116] powerpc/powernv: Add PE to its own PELTV Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 089/116] powerpc: ppc64 address space capped at 32TB, mmap randomisation disabled Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 090/116] powerpc: Fix __get_user_pages_fast() irq handling Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 091/116] powerpc/signals: Mark VSX not saved with small contexts Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 092/116] powerpc/eeh: Enable PCI_COMMAND_MASTER for PCI bridges Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 093/116] powerpc/pseries: Duplicate dtl entries sometimes sent to userspace Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 094/116] slub: Handle NULL parameter in kmem_cache_flags Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 095/116] SUNRPC: gss_alloc_msg - choose _either_ a v0 message or a v1 message Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 096/116] SUNRPC: Fix a data corruption issue when retransmitting RPC calls Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 097/116] SUNRPC: Avoid deep recursion in rpc_release_client Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 098/116] mei: nfc: fix memory leak in error path Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 099/116] usb: Dont enable USB 2.0 Link PM by default Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 100/116] xhci: Enable LPM support only for hardwired or BESL devices Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 101/116] xhci: Set L1 device slot on USB2 LPM enable/disable Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 102/116] usb: Disable USB 2.0 Link PM before device reset Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 103/116] usb: hub: Clear Port Reset Change during init/resume Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 104/116] usb: wusbcore: set the RPIPE wMaxPacketSize value correctly Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 105/116] rt2800usb: slow down TX status polling Greg Kroah-Hartman
2013-11-27  0:57 ` [PATCH 3.12 106/116] usb: musb: cancel work on removal Greg Kroah-Hartman
2013-11-27  0:58 ` [PATCH 3.12 107/116] usb: musb: call musb_start() only once in OTG mode Greg Kroah-Hartman
2013-11-27  0:58 ` [PATCH 3.12 108/116] usb: musb: dsps: move try_idle to start hook Greg Kroah-Hartman
2013-11-27  0:58 ` [PATCH 3.12 109/116] usb: musb: dsps: redo the otg timer Greg Kroah-Hartman
2013-11-27  0:58 ` [PATCH 3.12 110/116] usb: musb: core: properly free host / device structs in err path Greg Kroah-Hartman
2013-11-27  0:58 ` [PATCH 3.12 111/116] s390/time: fix get_tod_clock_ext inline assembly Greg Kroah-Hartman
2013-11-27  0:58 ` [PATCH 3.12 112/116] s390/vtime: correct idle time calculation Greg Kroah-Hartman
2013-11-27  0:58 ` Greg Kroah-Hartman [this message]
2013-11-27  0:58 ` [PATCH 3.12 114/116] GFS2: d_splice_alias() cant return error Greg Kroah-Hartman
2013-11-27  0:58 ` [PATCH 3.12 115/116] GFS2: fix dentry leaks Greg Kroah-Hartman
2013-11-27  0:58 ` [PATCH 3.12 116/116] cris: media platform drivers: fix build Greg Kroah-Hartman
2013-11-27  4:10 ` [PATCH 3.12 000/116] 3.12.2-stable review Guenter Roeck
2013-11-27 22:28 ` Shuah Khan
2013-11-28 10:57 ` Satoru Takeuchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131127005744.754688213@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=jlbec@evilplan.org \
    --cc=junxiao.bi@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).