Commit ba741d9e authored by Michal Hocko's avatar Michal Hocko Committed by Greg Kroah-Hartman

mm: do not allow MADV_PAGEOUT for CoW pages

commit 12e967fd8e4e6c3d275b4c69c890adc838891300 upstream.

Jann has brought up a very interesting point [1].  While shared pages
are excluded from MADV_PAGEOUT normally, CoW pages can be easily
reclaimed that way.  This can lead to all sorts of hard to debug
problems.  E.g.  performance problems outlined by Daniel [2].

There are runtime environments where there is a substantial memory
shared among security domains via CoW memory and a easy to reclaim way
of that memory, which MADV_{COLD,PAGEOUT} offers, can lead to either
performance degradation in for the parent process which might be more
privileged or even open side channel attacks.

The feasibility of the latter is not really clear to me TBH but there is
no real reason for exposure at this stage.  It seems there is no real
use case to depend on reclaiming CoW memory via madvise at this stage so
it is much easier to simply disallow it and this is what this patch
does.  Put it simply MADV_{PAGEOUT,COLD} can operate only on the
exclusively owned memory which is a straightforward semantic.

[1][email protected]om
[2][email protected]om

Fixes: 9c276cc6 ("mm: introduce MADV_COLD")
Reported-by: default avatarJann Horn <[email protected]>
Signed-off-by: default avatarMichal Hocko <[email protected]>
Signed-off-by: default avatarAndrew Morton <[email protected]>
Acked-by: default avatarVlastimil Babka <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Daniel Colascione <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "Joel Fernandes (Google)" <[email protected]>
Cc: <[email protected]>
Link:[email protected]Signed-off-by: default avatarLinus Torvalds <[email protected]>
Signed-off-by: default avatarGreg Kroah-Hartman <[email protected]>
parent f9c06770
......@@ -335,12 +335,14 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
page = pmd_page(orig_pmd);
/* Do not interfere with other mappings of this page */
if (page_mapcount(page) != 1)
goto huge_unlock;
if (next - addr != HPAGE_PMD_SIZE) {
int err;
if (page_mapcount(page) != 1)
goto huge_unlock;
......@@ -426,6 +428,10 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
/* Do not interfere with other mappings of this page */
if (page_mapcount(page) != 1)
VM_BUG_ON_PAGE(PageTransCompound(page), page);
if (pte_young(ptent)) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment