stable.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, Weijie Yang <weijie.yang@samsung.com>,
	Hugh Dickins <hughd@google.com>,
	Krzysztof Kozlowski <k.kozlowski@samsung.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 3.13 22/40] mm/swap: fix race on swap_info reuse between swapoff and swapon
Date: Tue, 18 Feb 2014 14:47:23 -0800	[thread overview]
Message-ID: <20140218224433.962806819@linuxfoundation.org> (raw)
In-Reply-To: <20140218224433.337299968@linuxfoundation.org>

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

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

From: Weijie Yang <weijie.yang@samsung.com>

commit f893ab41e4dae2fe8991faf5d86d029068d1ef3a upstream.

swapoff clear swap_info's SWP_USED flag prematurely and free its
resources after that.  A concurrent swapon will reuse this swap_info
while its previous resources are not cleared completely.

These late freed resources are:
 - p->percpu_cluster
 - swap_cgroup_ctrl[type]
 - block_device setting
 - inode->i_flags &= ~S_SWAPFILE

This patch clears the SWP_USED flag after all its resources are freed,
so that swapon can reuse this swap_info by alloc_swap_info() safely.

[akpm@linux-foundation.org: tidy up code comment]
Signed-off-by: Weijie Yang <weijie.yang@samsung.com>
Acked-by: Hugh Dickins <hughd@google.com>
Cc: Krzysztof Kozlowski <k.kozlowski@samsung.com>
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>

---
 mm/swapfile.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1922,7 +1922,6 @@ SYSCALL_DEFINE1(swapoff, const char __us
 	p->swap_map = NULL;
 	cluster_info = p->cluster_info;
 	p->cluster_info = NULL;
-	p->flags = 0;
 	frontswap_map = frontswap_map_get(p);
 	spin_unlock(&p->lock);
 	spin_unlock(&swap_lock);
@@ -1948,6 +1947,16 @@ SYSCALL_DEFINE1(swapoff, const char __us
 		mutex_unlock(&inode->i_mutex);
 	}
 	filp_close(swap_file, NULL);
+
+	/*
+	 * Clear the SWP_USED flag after all resources are freed so that swapon
+	 * can reuse this swap_info in alloc_swap_info() safely.  It is ok to
+	 * not hold p->lock after we cleared its SWP_WRITEOK.
+	 */
+	spin_lock(&swap_lock);
+	p->flags = 0;
+	spin_unlock(&swap_lock);
+
 	err = 0;
 	atomic_inc(&proc_poll_event);
 	wake_up_interruptible(&proc_poll_wait);



  parent reply	other threads:[~2014-02-18 22:47 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-18 22:47 [PATCH 3.13 00/40] 3.13.4-stable review Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 01/40] SELinux: Fix kernel BUG on empty security contexts Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 02/40] Btrfs: disable snapshot aware defrag for now Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 03/40] crypto: s390 - fix concurrency issue in aes-ctr mode Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 04/40] crypto: s390 - fix des and des3_ede cbc concurrency issue Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 05/40] crypto: s390 - fix des and des3_ede ctr " Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 06/40] NFSv4.1: nfs4_destroy_session must call rpc_destroy_waitqueue Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 07/40] NFSv4: Fix memory corruption in nfs4_proc_open_confirm Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 08/40] regulator: core: Correct default return value for full constraints Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 09/40] irqchip: armada-370-xp: fix IPI race condition Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 10/40] irqchip: armada-370-xp: fix MSI " Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 11/40] arm64: vdso: update wtm fields for CLOCK_MONOTONIC_COARSE Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 12/40] arm64: atomics: fix use of acquire + release for full barrier semantics Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 13/40] arm64: vdso: prevent ld from aligning PT_LOAD segments to 64k Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 14/40] arm64: Invalidate the TLB when replacing pmd entries during boot Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 15/40] arm64: vdso: fix coarse clock handling Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 16/40] arm64: add DSB after icache flush in __flush_icache_all() Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 17/40] ALSA: usb-audio: Add missing kconfig dependecy Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 18/40] ALSA: hda - Fix missing VREF setup for Mac Pro 1,1 Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 19/40] ALSA: hda - Fix silent output on Toshiba Satellite L40 Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 20/40] ALSA: hda - Add missing mixer widget for AD1983 Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 21/40] ALSA: hda - Improve loopback path lookups " Greg Kroah-Hartman
2014-02-18 22:47 ` Greg Kroah-Hartman [this message]
2014-02-18 22:47 ` [PATCH 3.13 23/40] mm: __set_page_dirty_nobuffers() uses spin_lock_irqsave() instead of spin_lock_irq() Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 24/40] mm: __set_page_dirty uses spin_lock_irqsave instead of spin_lock_irq Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 25/40] x86: mm: change tlb_flushall_shift for IvyBridge Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 26/40] [media] af9035: add ID [2040:f900] Hauppauge WinTV-MiniStick 2 Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 27/40] [media] mxl111sf: Fix unintentional garbage stack read Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 29/40] [media] Revert "[media] videobuf_vm_{open,close} race fixes" Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 30/40] [media] cx24117: use a valid dev pointer for dev_err printout Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 31/40] x86, hweight: Fix BUG when booting with CONFIG_GCOV_PROFILE_ALL=y Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 32/40] genirq: Generic irq chip requires IRQ_DOMAIN Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 33/40] pinctrl: at91: use locked variant of irq_set_handler Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 34/40] pinctrl: imx27: fix wrong offset to ICONFB Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 35/40] pinctrl: imx27: fix offset calculation in imx_read_2bit Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 36/40] pinctrl: vt8500: Change devicetree data parsing Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 37/40] pinctrl: protect pinctrl_list add Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 38/40] bcache: fix BUG_ON due to integer overflow with GC_SECTORS_USED Greg Kroah-Hartman
2014-02-18 22:47 ` [PATCH 3.13 39/40] intel_pstate: Take core C0 time into account for core busy calculation Greg Kroah-Hartman
2014-02-19 12:52   ` Stefan Lippers-Hollmann
2014-02-19 16:41     ` Dirk Brandewie
2014-02-18 22:47 ` [PATCH 3.13 40/40] ARM: imx6: Initialize low-power mode early again Greg Kroah-Hartman
2014-02-19  4:30 ` [PATCH 3.13 00/40] 3.13.4-stable review Guenter Roeck
2014-02-20 18:32   ` Greg Kroah-Hartman
2014-02-20 23:23     ` Guenter Roeck
2014-02-20 23:32       ` Greg Kroah-Hartman
2014-02-21  2:49         ` Guenter Roeck
2014-02-20  0:16 ` Shuah Khan
2014-02-20  0:36   ` Mark Brown
2014-02-20  1:20     ` Shuah Khan
2014-02-20  2:34       ` Mark Brown
2014-02-20 13:40         ` Shuah Khan
2014-02-20 14:45           ` Mark Brown
2014-02-20 18:29   ` Greg Kroah-Hartman
2014-02-20 10:26 ` Satoru Takeuchi
2014-02-20 18:31   ` Greg Kroah-Hartman

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=20140218224433.962806819@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=k.kozlowski@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=weijie.yang@samsung.com \
    /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).