* [patch 2/5] mm,thp: stop leaking unreleased file pages
[not found] <20200527222015.62ba8592af63dae12ab58ffe@linux-foundation.org>
@ 2020-05-28 5:20 ` Andrew Morton
2020-05-28 5:20 ` [patch 3/5] mm: remove VM_BUG_ON(PageSlab()) from page_mapcount() Andrew Morton
2020-05-28 5:20 ` [patch 4/5] fs/binfmt_elf.c: allocate initialized memory in fill_thread_core_info() Andrew Morton
2 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2020-05-28 5:20 UTC (permalink / raw)
To: akpm, hannes, hughd, kirill.shutemov, linux-mm, mm-commits, riel,
songliubraving, stable, torvalds
From: Hugh Dickins <hughd@google.com>
Subject: mm,thp: stop leaking unreleased file pages
When collapse_file() calls try_to_release_page(), it has already isolated
the page: so if releasing buffers happens to fail (as it sometimes does),
remember to putback_lru_page(): otherwise that page is left unreclaimable
and unfreeable, and the file extent uncollapsible.
Link: http://lkml.kernel.org/r/alpine.LSU.2.11.2005231837500.1766@eggly.anvils
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: <stable@vger.kernel.org> [5.4+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/khugepaged.c | 1 +
1 file changed, 1 insertion(+)
--- a/mm/khugepaged.c~mmthp-stop-leaking-unreleased-file-pages
+++ a/mm/khugepaged.c
@@ -1692,6 +1692,7 @@ static void collapse_file(struct mm_stru
if (page_has_private(page) &&
!try_to_release_page(page, GFP_KERNEL)) {
result = SCAN_PAGE_HAS_PRIVATE;
+ putback_lru_page(page);
goto out_unlock;
}
_
^ permalink raw reply [flat|nested] 4+ messages in thread
* [patch 3/5] mm: remove VM_BUG_ON(PageSlab()) from page_mapcount()
[not found] <20200527222015.62ba8592af63dae12ab58ffe@linux-foundation.org>
2020-05-28 5:20 ` [patch 2/5] mm,thp: stop leaking unreleased file pages Andrew Morton
@ 2020-05-28 5:20 ` Andrew Morton
2020-05-28 5:20 ` [patch 4/5] fs/binfmt_elf.c: allocate initialized memory in fill_thread_core_info() Andrew Morton
2 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2020-05-28 5:20 UTC (permalink / raw)
To: akpm, hughd, khlebnikov, kirill.shutemov, linux-mm, mm-commits,
rientjes, stable, torvalds, vbabka
From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Subject: mm: remove VM_BUG_ON(PageSlab()) from page_mapcount()
Replace superfluous VM_BUG_ON() with comment about correct usage.
Technically reverts commit 1d148e218a0d0566b1c06f2f45f1436d53b049b2
("mm: add VM_BUG_ON_PAGE() to page_mapcount()"), but context have changed.
Function isolate_migratepages_block() runs some checks out of lru_lock
when choose pages for migration. After checking PageLRU() it checks extra
page references by comparing page_count() and page_mapcount(). Between
these two checks page could be removed from lru, freed and taken by slab.
As a result this race triggers VM_BUG_ON(PageSlab()) in page_mapcount().
Race window is tiny. For certain workload this happens around once a year.
page:ffffea0105ca9380 count:1 mapcount:0 mapping:ffff88ff7712c180 index:0x0 compound_mapcount: 0
flags: 0x500000000008100(slab|head)
raw: 0500000000008100 dead000000000100 dead000000000200 ffff88ff7712c180
raw: 0000000000000000 0000000080200020 00000001ffffffff 0000000000000000
page dumped because: VM_BUG_ON_PAGE(PageSlab(page))
------------[ cut here ]------------
kernel BUG at ./include/linux/mm.h:628!
invalid opcode: 0000 [#1] SMP NOPTI
CPU: 77 PID: 504 Comm: kcompactd1 Tainted: G W 4.19.109-27 #1
Hardware name: Yandex T175-N41-Y3N/MY81-EX0-Y3N, BIOS R05 06/20/2019
RIP: 0010:isolate_migratepages_block+0x986/0x9b0
Code in isolate_migratepages_block() was added in commit 119d6d59dcc0
("mm, compaction: avoid isolating pinned pages") before adding VM_BUG_ON
into page_mapcount().
This race has been predicted in 2015 by Vlastimil Babka (see link below).
[akpm@linux-foundation.org: comment tweaks, per Hugh]
Link: http://lkml.kernel.org/r/159032779896.957378.7852761411265662220.stgit@buzz
Link: https://lore.kernel.org/lkml/557710E1.6060103@suse.cz/
Link: https://lore.kernel.org/linux-mm/158937872515.474360.5066096871639561424.stgit@buzz/T/ (v1)
Fixes: 1d148e218a0d ("mm: add VM_BUG_ON_PAGE() to page_mapcount()")
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Acked-by: Hugh Dickins <hughd@google.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
include/linux/mm.h | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
--- a/include/linux/mm.h~mm-remove-vm_bug_onpageslab-from-page_mapcount
+++ a/include/linux/mm.h
@@ -782,6 +782,11 @@ static inline void *kvcalloc(size_t n, s
extern void kvfree(const void *addr);
+/*
+ * Mapcount of compound page as a whole, does not include mapped sub-pages.
+ *
+ * Must be called only for compound pages or any their tail sub-pages.
+ */
static inline int compound_mapcount(struct page *page)
{
VM_BUG_ON_PAGE(!PageCompound(page), page);
@@ -801,10 +806,16 @@ static inline void page_mapcount_reset(s
int __page_mapcount(struct page *page);
+/*
+ * Mapcount of 0-order page; when compound sub-page, includes
+ * compound_mapcount().
+ *
+ * Result is undefined for pages which cannot be mapped into userspace.
+ * For example SLAB or special types of pages. See function page_has_type().
+ * They use this place in struct page differently.
+ */
static inline int page_mapcount(struct page *page)
{
- VM_BUG_ON_PAGE(PageSlab(page), page);
-
if (unlikely(PageCompound(page)))
return __page_mapcount(page);
return atomic_read(&page->_mapcount) + 1;
_
^ permalink raw reply [flat|nested] 4+ messages in thread
* [patch 4/5] fs/binfmt_elf.c: allocate initialized memory in fill_thread_core_info()
[not found] <20200527222015.62ba8592af63dae12ab58ffe@linux-foundation.org>
2020-05-28 5:20 ` [patch 2/5] mm,thp: stop leaking unreleased file pages Andrew Morton
2020-05-28 5:20 ` [patch 3/5] mm: remove VM_BUG_ON(PageSlab()) from page_mapcount() Andrew Morton
@ 2020-05-28 5:20 ` Andrew Morton
2020-05-28 14:41 ` Sasha Levin
2 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2020-05-28 5:20 UTC (permalink / raw)
To: adobriyan, akpm, glider, keescook, linux-mm, mm-commits, stable,
sunhaoyl, torvalds, viro
From: Alexander Potapenko <glider@google.com>
Subject: fs/binfmt_elf.c: allocate initialized memory in fill_thread_core_info()
KMSAN reported uninitialized data being written to disk when dumping core.
As a result, several kilobytes of kmalloc memory may be written to the
core file and then read by a non-privileged user.
Link: http://lkml.kernel.org/r/20200419100848.63472-1-glider@google.com
Link: https://github.com/google/kmsan/issues/76
Signed-off-by: Alexander Potapenko <glider@google.com>
Reported-by: sam <sunhaoyl@outlook.com>
Acked-by: Kees Cook <keescook@chromium.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
fs/binfmt_elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/fs/binfmt_elf.c~fs-binfmt_elfc-allocate-initialized-memory-in-fill_thread_core_info
+++ a/fs/binfmt_elf.c
@@ -1733,7 +1733,7 @@ static int fill_thread_core_info(struct
(!regset->active || regset->active(t->task, regset) > 0)) {
int ret;
size_t size = regset_size(t->task, regset);
- void *data = kmalloc(size, GFP_KERNEL);
+ void *data = kzalloc(size, GFP_KERNEL);
if (unlikely(!data))
return 0;
ret = regset->get(t->task, regset,
_
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch 4/5] fs/binfmt_elf.c: allocate initialized memory in fill_thread_core_info()
2020-05-28 5:20 ` [patch 4/5] fs/binfmt_elf.c: allocate initialized memory in fill_thread_core_info() Andrew Morton
@ 2020-05-28 14:41 ` Sasha Levin
0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2020-05-28 14:41 UTC (permalink / raw)
To: Sasha Levin, Andrew Morton, Alexander Potapenko, adobriyan, akpm,
glider
Cc: Al Viro, Alexey Dobriyan, stable, stable
Hi
[This is an automated email]
This commit has been processed because it contains a -stable tag.
The stable tag indicates that it's relevant for the following trees: all
The bot has tested the following trees: v5.6.14, v5.4.42, v4.19.124, v4.14.181, v4.9.224, v4.4.224.
v5.6.14: Build OK!
v5.4.42: Build OK!
v4.19.124: Build OK!
v4.14.181: Failed to apply! Possible dependencies:
27e64b4be4b8 ("regset: Add support for dynamically sized regsets")
v4.9.224: Failed to apply! Possible dependencies:
27e64b4be4b8 ("regset: Add support for dynamically sized regsets")
v4.4.224: Failed to apply! Possible dependencies:
27e64b4be4b8 ("regset: Add support for dynamically sized regsets")
90954e7b9407 ("x86/coredump: Use pr_reg size, rather that TIF_IA32 flag")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
--
Thanks
Sasha
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-05-28 14:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20200527222015.62ba8592af63dae12ab58ffe@linux-foundation.org>
2020-05-28 5:20 ` [patch 2/5] mm,thp: stop leaking unreleased file pages Andrew Morton
2020-05-28 5:20 ` [patch 3/5] mm: remove VM_BUG_ON(PageSlab()) from page_mapcount() Andrew Morton
2020-05-28 5:20 ` [patch 4/5] fs/binfmt_elf.c: allocate initialized memory in fill_thread_core_info() Andrew Morton
2020-05-28 14:41 ` Sasha Levin
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).