public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk,
	Russell King <rmk+kernel@arm.linux.org.uk>,
	Dominik Brodowski <linux@dominikbrodowski.net>
Subject: [patch 39/55] pcmcia: fix socket refcount decrementing on each resume
Date: Fri, 10 Feb 2012 14:33:43 -0800	[thread overview]
Message-ID: <20120210223443.703814554@clark.kroah.org> (raw)
In-Reply-To: <20120210223500.GA24178@kroah.com>

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

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

From: Russell King <rmk+kernel@arm.linux.org.uk>

commit 025e4ab3db07fcbf62c01e4f30d1012234beb980 upstream.

This fixes a memory-corrupting bug: not only does it cause the warning,
but as a result of dropping the refcount to zero, it causes the
pcmcia_socket0 device structure to be freed while it still has
references, causing slab caches corruption.  A fatal oops quickly
follows this warning - often even just a 'dmesg' following the warning
causes the kernel to oops.

While testing suspend/resume on an ARM device with PCMCIA support, and a
CF card inserted, I found that after five suspend and resumes, the
kernel would complain, and shortly die after with slab corruption.

  WARNING: at include/linux/kref.h:41 kobject_get+0x28/0x50()

As the message doesn't give a clue about which kobject, and the built-in
debugging in drivers/base/power/main.c happens too late, this was added
right before each get_device():

  printk("%s: %p [%s] %u\n", __func__, dev, kobject_name(&dev->kobj), atomic_read(&dev->kobj.kref.refcount));

and on the 3rd s2ram cycle, the following behaviour observed:

On the 3rd suspend/resume cycle:

  dpm_prepare: c1a0d998 [pcmcia_socket0] 3
  dpm_suspend: c1a0d998 [pcmcia_socket0] 3
  dpm_suspend_noirq: c1a0d998 [pcmcia_socket0] 3
  dpm_resume_noirq: c1a0d998 [pcmcia_socket0] 3
  dpm_resume: c1a0d998 [pcmcia_socket0] 3
  dpm_complete: c1a0d998 [pcmcia_socket0] 2

4th:

  dpm_prepare: c1a0d998 [pcmcia_socket0] 2
  dpm_suspend: c1a0d998 [pcmcia_socket0] 2
  dpm_suspend_noirq: c1a0d998 [pcmcia_socket0] 2
  dpm_resume_noirq: c1a0d998 [pcmcia_socket0] 2
  dpm_resume: c1a0d998 [pcmcia_socket0] 2
  dpm_complete: c1a0d998 [pcmcia_socket0] 1

5th:

  dpm_prepare: c1a0d998 [pcmcia_socket0] 1
  dpm_suspend: c1a0d998 [pcmcia_socket0] 1
  dpm_suspend_noirq: c1a0d998 [pcmcia_socket0] 1
  dpm_resume_noirq: c1a0d998 [pcmcia_socket0] 1
  dpm_resume: c1a0d998 [pcmcia_socket0] 1
  dpm_complete: c1a0d998 [pcmcia_socket0] 0
  ------------[ cut here ]------------
  WARNING: at include/linux/kref.h:41 kobject_get+0x28/0x50()
  Modules linked in: ucb1x00_core
  Backtrace:
  [<c0212090>] (dump_backtrace+0x0/0x110) from [<c04799dc>] (dump_stack+0x18/0x1c)
  [<c04799c4>] (dump_stack+0x0/0x1c) from [<c021cba0>] (warn_slowpath_common+0x50/0x68)
  [<c021cb50>] (warn_slowpath_common+0x0/0x68) from [<c021cbdc>] (warn_slowpath_null+0x24/0x28)
  [<c021cbb8>] (warn_slowpath_null+0x0/0x28) from [<c0335374>] (kobject_get+0x28/0x50)
  [<c033534c>] (kobject_get+0x0/0x50) from [<c03804f4>] (get_device+0x1c/0x24)
  [<c0388c90>] (dpm_complete+0x0/0x1a0) from [<c0389cc0>] (dpm_resume_end+0x1c/0x20)
  ...

[changelog edited to make quilt mail happy...]

As can be seen, the original function called pcmcia_get_socket() and
pcmcia_put_socket() around the guts, whereas the replacement code
calls pcmcia_put_socket() only in one path.  This creates an imbalance
in the refcounting.

Testing with pcmcia_put_socket() put removed shows that the bug is gone:

  dpm_suspend: c1a10998 [pcmcia_socket0] 5
  dpm_suspend_noirq: c1a10998 [pcmcia_socket0] 5
  dpm_resume_noirq: c1a10998 [pcmcia_socket0] 5
  dpm_resume: c1a10998 [pcmcia_socket0] 5
  dpm_complete: c1a10998 [pcmcia_socket0] 5

Tested-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
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>

---
 drivers/pcmcia/ds.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -1269,10 +1269,8 @@ static int pcmcia_bus_add(struct pcmcia_
 
 static int pcmcia_bus_early_resume(struct pcmcia_socket *skt)
 {
-	if (!verify_cis_cache(skt)) {
-		pcmcia_put_socket(skt);
+	if (!verify_cis_cache(skt))
 		return 0;
-	}
 
 	dev_dbg(&skt->dev, "cis mismatch - different card\n");
 



  parent reply	other threads:[~2012-02-10 22:57 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10 22:35 [patch 00/55] 3.0.21-stable review Greg KH
2012-02-10 22:33 ` [patch 01/55] readahead: fix pipeline break caused by block plug Greg KH
2012-02-10 22:33 ` [patch 02/55] ALSA: HDA: Fix duplicated output to more than one codec Greg KH
2012-02-10 22:33 ` [patch 03/55] ASoC: wm_hubs: Enable line out VMID buffer for single ended line outputs Greg KH
2012-02-10 22:33 ` [patch 04/55] ASoC: wm_hubs: fix wrong bits for LINEOUT2 N/P mixer Greg KH
2012-02-10 22:33 ` [patch 05/55] ARM: 7306/1: vfp: flush thread hwstate before restoring context from sigframe Greg KH
2012-02-10 22:33 ` [patch 06/55] ARM: 7307/1: vfp: fix ptrace regset modification race Greg KH
2012-02-10 22:33 ` [patch 07/55] ARM: 7308/1: vfp: flush thread hwstate before copying ptrace registers Greg KH
2012-02-10 22:33 ` [patch 08/55] ARM: OMAP2+: GPMC: fix device size setup Greg KH
2012-02-10 22:33 ` [patch 09/55] drivers/tty/vt/vt_ioctl.c: fix KDFONTOP 32bit compatibility layer Greg KH
2012-02-10 22:33 ` [patch 10/55] proc: mem_release() should check mm != NULL Greg KH
2012-02-10 22:33 ` [patch 11/55] proc: unify mem_read() and mem_write() Greg KH
2012-02-10 22:33 ` [patch 12/55] proc: make sure mem_open() doesnt pin the targets memory Greg KH
2012-02-10 22:33 ` [patch 13/55] firewire: ohci: add reset packet quirk for SB Audigy Greg KH
2012-02-10 22:33 ` [patch 14/55] firewire: ohci: disable MSI on Ricoh controllers Greg KH
2012-02-10 22:33 ` [patch 15/55] IB/mlx4: pass SMP vendor-specific attribute MADs to firmware Greg KH
2012-02-10 22:33 ` [patch 16/55] kprobes: fix a memory leak in function pre_handler_kretprobe() Greg KH
2012-02-10 22:33 ` [patch 17/55] at_hdmac: bugfix for enabling channel irq Greg KH
2012-02-10 22:33 ` [patch 18/55] mm/filemap_xip.c: fix race condition in xip_file_fault() Greg KH
2012-02-10 22:33 ` [patch 19/55] mm: compaction: check pfn_valid when entering a new MAX_ORDER_NR_PAGES block during isolation for migration Greg KH
2012-02-10 22:33 ` [patch 20/55] drm/radeon: Set DESKTOP_HEIGHT register to the framebuffer (not mode) height Greg KH
2012-02-10 22:33 ` [patch 21/55] drm/nouveau/gem: fix fence_sync race / oops Greg KH
2012-02-10 22:33 ` [patch 22/55] drm/radeon/kms: disable output polling when suspended Greg KH
2012-02-10 22:33 ` [patch 23/55] sched/rt: Fix task stack corruption under __ARCH_WANT_INTERRUPTS_ON_CTXSW Greg KH
2012-02-10 22:33 ` [patch 24/55] ASoC: Ensure we generate a driver name Greg KH
2012-02-10 22:33 ` [patch 25/55] udf: Mark LVID buffer as uptodate before marking it dirty Greg KH
2012-02-10 22:33 ` [patch 26/55] drm/i915: HDMI hot remove notification to audio driver Greg KH
2012-02-10 22:33 ` [patch 27/55] drm/i915: DisplayPort " Greg KH
2012-02-10 22:33 ` [patch 28/55] drm/i915: check ACTHD of all rings Greg KH
2012-02-10 22:33 ` [patch 29/55] drm/i915: Fix TV Out refresh rate Greg KH
2012-02-10 22:33 ` [patch 30/55] drm/i915: handle 3rd pipe Greg KH
2012-02-10 22:33 ` [patch 31/55] eCryptfs: Infinite loop due to overflow in ecryptfs_write() Greg KH
2012-02-10 22:33 ` [patch 32/55] cifs: Fix oops in session setup code for null user mounts Greg KH
2012-02-10 22:33 ` [patch 33/55] atmel_lcdfb: fix usage of CONTRAST_CTR in suspend/resume Greg KH
2012-02-10 22:33 ` [patch 34/55] lockdep, bug: Exclude TAINT_FIRMWARE_WORKAROUND from disabling lockdep Greg KH
2012-02-10 22:33 ` [patch 35/55] hwmon: (w83627ehf) Fix number of fans for NCT6776F Greg KH
2012-02-10 22:33 ` [patch 36/55] ASoC: wm_hubs: Fix routing of input PGAs to line output mixer Greg KH
2012-02-10 22:33 ` [patch 37/55] ASoC: wm_hubs: Correct line input to line output 2 paths Greg KH
2012-02-10 22:33 ` [patch 38/55] ASoC: wm8962: Fix word length configuration Greg KH
2012-02-10 22:33 ` Greg KH [this message]
2012-02-10 22:33 ` [patch 40/55] mm: compaction: check for overlapping nodes during isolation for migration Greg KH
2012-02-10 22:33 ` [patch 41/55] mm: fix UP THP spin_is_locked BUGs Greg KH
2012-02-10 22:33 ` [patch 42/55] target: Use correct preempted registration sense code Greg KH
2012-02-10 22:33 ` [patch 43/55] target: Allow PERSISTENT RESERVE IN for non-reservation holder Greg KH
2012-02-10 22:33 ` [patch 44/55] target: Correct sense key for INVALID FIELD IN {PARAMETER LIST,CDB} Greg KH
2012-02-10 22:33 ` [patch 45/55] Staging: asus_oled: fix image processing Greg KH
2012-02-10 22:33 ` [patch 46/55] Staging: asus_oled: fix NULL-ptr crash on unloading Greg KH
2012-02-10 22:33 ` [patch 47/55] staging: r8712u: Add new Sitecom UsB ID Greg KH
2012-02-10 22:33 ` [patch 48/55] usb: gadget: zero: fix bug in loopback autoresume handling Greg KH
2012-02-10 22:33 ` [patch 49/55] usb: Skip PCI USB quirk handling for Netlogic XLP Greg KH
2012-02-10 22:33 ` [patch 50/55] USB: usbserial: add new PID number (0xa951) to the ftdi driver Greg KH
2012-02-10 22:33 ` [patch 51/55] USB: add new zte 3g-dongles pid to option.c Greg KH
2012-02-10 22:33 ` [patch 52/55] mmc: cb710 core: Add missing spin_lock_init for irq_lock of struct cb710_chip Greg KH
2012-02-10 22:33 ` [patch 53/55] [CPUFREQ] powernow-k8: Avoid Pstate MSR accesses on systems supporting CPB Greg KH
2012-02-10 22:33 ` [patch 54/55] [CPUFREQ] powernow-k8: Fix indexing issue Greg KH
2012-02-10 22:33 ` [patch 55/55] [PATCH] net: fix NULL dereferences in check_peer_redir() Greg KH

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=20120210223443.703814554@clark.kroah.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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