From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Junil Lee <junil0814.lee@lge.com>,
Minchan Kim <minchan@kernel.org>,
Vlastimil Babka <vbabka@suse.cz>,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 4.4 117/117] zsmalloc: fix migrate_zspage-zs_free race condition
Date: Sun, 14 Feb 2016 14:22:34 -0800 [thread overview]
Message-ID: <20160214222144.942363390@linuxfoundation.org> (raw)
In-Reply-To: <20160214222141.393531627@linuxfoundation.org>
4.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junil Lee <junil0814.lee@lge.com>
commit c102f07ca0b04f2cb49cfc161c83f6239d17f491 upstream.
record_obj() in migrate_zspage() does not preserve handle's
HANDLE_PIN_BIT, set by find_aloced_obj()->trypin_tag(), and implicitly
(accidentally) un-pins the handle, while migrate_zspage() still performs
an explicit unpin_tag() on the that handle. This additional explicit
unpin_tag() introduces a race condition with zs_free(), which can pin
that handle by this time, so the handle becomes un-pinned.
Schematically, it goes like this:
CPU0 CPU1
migrate_zspage
find_alloced_obj
trypin_tag
set HANDLE_PIN_BIT zs_free()
pin_tag()
obj_malloc() -- new object, no tag
record_obj() -- remove HANDLE_PIN_BIT set HANDLE_PIN_BIT
unpin_tag() -- remove zs_free's HANDLE_PIN_BIT
The race condition may result in a NULL pointer dereference:
Unable to handle kernel NULL pointer dereference at virtual address 00000000
CPU: 0 PID: 19001 Comm: CookieMonsterCl Tainted:
PC is at get_zspage_mapping+0x0/0x24
LR is at obj_free.isra.22+0x64/0x128
Call trace:
get_zspage_mapping+0x0/0x24
zs_free+0x88/0x114
zram_free_page+0x64/0xcc
zram_slot_free_notify+0x90/0x108
swap_entry_free+0x278/0x294
free_swap_and_cache+0x38/0x11c
unmap_single_vma+0x480/0x5c8
unmap_vmas+0x44/0x60
exit_mmap+0x50/0x110
mmput+0x58/0xe0
do_exit+0x320/0x8dc
do_group_exit+0x44/0xa8
get_signal+0x538/0x580
do_signal+0x98/0x4b8
do_notify_resume+0x14/0x5c
This patch keeps the lock bit in migration path and update value
atomically.
Signed-off-by: Junil Lee <junil0814.lee@lge.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.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/zsmalloc.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -309,7 +309,12 @@ static void free_handle(struct zs_pool *
static void record_obj(unsigned long handle, unsigned long obj)
{
- *(unsigned long *)handle = obj;
+ /*
+ * lsb of @obj represents handle lock while other bits
+ * represent object value the handle is pointing so
+ * updating shouldn't do store tearing.
+ */
+ WRITE_ONCE(*(unsigned long *)handle, obj);
}
/* zpool driver */
@@ -1635,6 +1640,13 @@ static int migrate_zspage(struct zs_pool
free_obj = obj_malloc(d_page, class, handle);
zs_object_copy(free_obj, used_obj, class);
index++;
+ /*
+ * record_obj updates handle's value to free_obj and it will
+ * invalidate lock bit(ie, HANDLE_PIN_BIT) of handle, which
+ * breaks synchronization using pin_tag(e,g, zs_free) so
+ * let's keep the lock bit.
+ */
+ free_obj |= BIT(HANDLE_PIN_BIT);
record_obj(handle, free_obj);
unpin_tag(handle);
obj_free(pool, class, used_obj);
next prev parent reply other threads:[~2016-02-14 22:22 UTC|newest]
Thread overview: 122+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-14 22:20 [PATCH 4.4 000/117] 4.4.2-stable review Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 001/117] crypto: sun4i-ss - add missing statesize Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 002/117] NFSv4.1/pnfs: Fixup an lo->plh_block_lgets imbalance in layoutreturn Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 003/117] block: split bios to max possible length Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 004/117] ocfs2: NFS hangs in __ocfs2_cluster_lock due to race with ocfs2_unblock_lock Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 005/117] HID: usbhid: fix recursive deadlock Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 006/117] base/platform: Fix platform drivers with no probe callback Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 007/117] block: fix bio splitting on max sectors Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 008/117] ALSA: hda - Implement loopback control switch for Realtek and other codecs Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 009/117] ocfs2/dlm: ignore cleaning the migration mle that is inuse Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 010/117] ocfs2/dlm: clear refmap bit of recovery lock while doing local recovery cleanup Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 011/117] wlcore/wl12xx: spi: fix oops on firmware load Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 012/117] wlcore/wl12xx: spi: fix NULL pointer dereference (Oops) Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 013/117] mtd: nand: assign reasonable default name for NAND drivers Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 015/117] PCI: Fix minimum allocation address overwrite Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 016/117] tracing: Fix stacktrace skip depth in trace_buffer_unlock_commit_regs() Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 017/117] tracing/stacktrace: Show entire trace if passed in function not found Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 018/117] printk: do cond_resched() between lines while outputting to consoles Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 019/117] parisc: Protect huge page pte changes with spinlocks Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 020/117] parisc: Fix __ARCH_SI_PREAMBLE_SIZE Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 021/117] [media] media: i2c: Dont export ir-kbd-i2c module alias Greg Kroah-Hartman
2016-02-14 22:20 ` [PATCH 4.4 022/117] md/raid: only permit hot-add of compatible integrity profiles Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 023/117] hrtimer: Handle remaining time proper for TIME_LOW_RES Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 024/117] ALSA: usb-audio: Fix TEAC UD-501/UD-503/NT-503 usb delay Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 025/117] ALSA: usb-audio: Add quirk for Microsoft LifeCam HD-6000 Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 026/117] ALSA: usb-audio: Fix OPPO HA-1 vendor ID Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 027/117] ALSA: usb-audio: Add native DSD support for PS Audio NuWave DAC Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 028/117] ALSA: usb-audio: avoid freeing umidi object twice Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 029/117] ALSA: bebob: Use a signed return type for get_formation_index Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 030/117] ALSA: Add missing dependency on CONFIG_SND_TIMER Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 031/117] ALSA: hda - disable dynamic clock gating on Broxton before reset Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 032/117] ALSA: compress: Disable GET_CODEC_CAPS ioctl for some architectures Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 033/117] ALSA: dummy: Disable switching timer backend via sysfs Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 034/117] ALSA: seq: Fix incorrect sanity check at snd_seq_oss_synth_cleanup() Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 035/117] ALSA: seq: Degrade the error message for too many opens Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 036/117] ALSA: rawmidi: Make snd_rawmidi_transmit() race-free Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 037/117] ALSA: rawmidi: Remove kernel WARNING for NULL user-space buffer check Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 038/117] ALSA: rawmidi: Fix race at copying & updating the position Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 039/117] ALSA: hda/realtek - New codec support of ALC225 Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 040/117] ALSA: hda/realtek - Support headset mode for ALC225 Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 041/117] ALSA: hda/realtek - Support Dell " Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 042/117] ALSA: pcm: Fix potential deadlock in OSS emulation Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 043/117] ASoC: dpcm: fix the BE state on hw_free Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 044/117] ALSA: seq: Fix yet another races among ALSA timer accesses Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 045/117] ALSA: seq: Fix race at closing in virmidi driver Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 046/117] ALSA: seq: Fix lockdep warnings due to double mutex locks Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 047/117] ALSA: timer: Code cleanup Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 048/117] ALSA: timer: Fix leftover link at closing Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 049/117] ALSA: timer: Fix link corruption due to double start or stop Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 050/117] ALSA: timer: Fix race at concurrent reads Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 051/117] ALSA: timer: Fix wrong instance passed to slave callbacks Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 052/117] ALSA: timer: Fix race between stop and interrupt Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 053/117] ALSA: hda - Add fixup for Mac Mini 7,1 model Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 054/117] ALSA: hda - Fix static checker warning in patch_hdmi.c Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 055/117] Revert "ALSA: hda - Fix noise on Gigabyte Z170X mobo" Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 056/117] ALSA: hda - Fix speaker output from VAIO AiO machines Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 057/117] ALSA: hda - Fix bad dereference of jack object Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 058/117] ALSA: dummy: Implement timer backend switching more safely Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 059/117] [media] saa7134-alsa: Only frees registered sound cards Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 060/117] ASoC: rt5645: fix the shift bit of IN1 boost Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 061/117] USB: serial: visor: fix crash on detecting device without write_urbs Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 062/117] USB: visor: fix null-deref at probe Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 063/117] usb: hub: do not clear BOS field during reset device Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 064/117] USB: serial: ftdi_sio: add support for Yaesu SCU-18 cable Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 065/117] USB: cp210x: add ID for IAI USB to RS485 adaptor Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 066/117] USB: serial: option: Adding support for Telit LE922 Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 067/117] USB: option: fix Cinterion AHxx enumeration Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 068/117] usb: cdc-acm: handle unlinked urb in acm read callback Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 069/117] usb: cdc-acm: send zero packet for intel 7260 modem Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 070/117] usb: phy: msm: fix error handling in probe Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 071/117] usb: xhci: handle both SSIC ports in PME stuck quirk Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 072/117] usb: xhci: apply XHCI_PME_STUCK_QUIRK to Intel Broxton-M platforms Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 073/117] n_tty: Fix unsafe reference to "other" ldisc Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 074/117] tty: Wait interruptibly for tty lock on reopen Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 075/117] tty: Retry failed reopen if tty teardown in-progress Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 076/117] tty: Fix unsafe ldisc reference via ioctl(TIOCGETD) Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 077/117] iommu/io-pgtable-arm: Ensure we free the final level on teardown Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 078/117] ext4 crypto: add missing locking for keyring_key access Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 079/117] sched: Fix crash in sched_init_numa() Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 080/117] crypto: algif_skcipher - Require setkey before accept(2) Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 081/117] crypto: af_alg - Disallow bind/setkey/... after accept(2) Greg Kroah-Hartman
2016-02-14 22:21 ` [PATCH 4.4 082/117] crypto: af_alg - Fix socket double-free when accept fails Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 083/117] crypto: af_alg - Add nokey compatibility path Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 084/117] crypto: algif_skcipher " Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 085/117] crypto: hash - Add crypto_ahash_has_setkey Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 086/117] crypto: algif_hash - Require setkey before accept(2) Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 087/117] crypto: skcipher - Add crypto_skcipher_has_setkey Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 088/117] crypto: algif_skcipher - Add key check exception for cipher_null Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 089/117] libata: disable forced PORTS_IMPL for >= AHCI 1.3 Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 090/117] ahci: Intel DNV device IDs SATA Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 091/117] crypto: af_alg - Allow af_af_alg_release_parent to be called on nokey path Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 092/117] crypto: algif_hash - Remove custom release parent function Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 093/117] crypto: algif_skcipher " Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 094/117] crypto: af_alg - Forbid bind(2) when nokey child sockets are present Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 095/117] crypto: algif_hash - Fix race condition in hash_check_key Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 096/117] crypto: algif_skcipher - Fix race condition in skcipher_check_key Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 097/117] crypto: crc32c - Fix crc32c soft dependency Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 098/117] crypto: algif_skcipher - Load TX SG list after waiting Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 099/117] crypto: algif_skcipher - sendmsg SG marking is off by one Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 100/117] crypto: caam - make write transactions bufferable on PPC platforms Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 101/117] crypto: chacha20-ssse3 - Align stack pointer to 64 bytes Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 102/117] crypto: shash - Fix has_key setting Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 103/117] crypto: algif_hash - wait for crypto_ahash_init() to complete Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 104/117] EVM: Use crypto_memneq() for digest comparisons Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 105/117] crypto: user - lock crypto_alg_list on alg dump Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 106/117] crypto: algif_skcipher - Do not assume that req is unchanged Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 107/117] crypto: algif_skcipher - Do not dereference ctx without socket lock Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 108/117] crypto: algif_skcipher - Do not set MAY_BACKLOG on the async path Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 109/117] crypto: atmel-sha - fix atmel_sha_remove() Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 110/117] crypto: atmel-sha - remove calls of clk_prepare() from atomic contexts Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 111/117] crypto: marvell/cesa - fix test in mv_cesa_dev_dma_init() Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 112/117] rtlwifi: rtl8821ae: Fix errors in parameter initialization Greg Kroah-Hartman
2016-02-16 18:46 ` Ben Hutchings
2016-02-16 20:21 ` Luis Henriques
2016-02-18 2:31 ` Larry Finger
2016-02-14 22:22 ` [PATCH 4.4 113/117] rtlwifi: rtl8821ae: Fix 5G failure when EEPROM is incorrectly encoded Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 114/117] zram/zcomp: use GFP_NOIO to allocate streams Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 115/117] zram: try vmalloc() after kmalloc() Greg Kroah-Hartman
2016-02-14 22:22 ` [PATCH 4.4 116/117] zram: dont call idr_remove() from zram_remove() Greg Kroah-Hartman
2016-02-14 22:22 ` Greg Kroah-Hartman [this message]
2016-02-15 15:50 ` [PATCH 4.4 000/117] 4.4.2-stable review Guenter Roeck
2016-02-15 17:08 ` Shuah Khan
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=20160214222144.942363390@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=junil0814.lee@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vbabka@suse.cz \
/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).