lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180305094601.GA25231@rapoport-lnx>
Date:   Mon, 5 Mar 2018 10:46:02 +0100
From:   Mike Rapoport <rppt@...ux.vnet.ibm.com>
To:     "Huang, Ying" <ying.huang@...el.com>
Cc:     Andrew Morton <akpm@...ux-foundation.org>, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org, Minchan Kim <minchan@...nel.org>,
        Michal Hocko <mhocko@...e.com>,
        Johannes Weiner <hannes@...xchg.org>,
        Mel Gorman <mgorman@...hsingularity.net>,
        Dave Hansen <dave.hansen@...el.com>,
        Chen Liqin <liqin.linux@...il.com>,
        Russell King <linux@...linux.org.uk>,
        Yoshinori Sato <ysato@...rs.sourceforge.jp>,
        "James E.J. Bottomley" <jejb@...isc-linux.org>,
        Guan Xuetao <gxt@...c.pku.edu.cn>,
        "David S. Miller" <davem@...emloft.net>,
        Chris Zankel <chris@...kel.net>,
        Vineet Gupta <vgupta@...opsys.com>,
        Ley Foon Tan <lftan@...era.com>,
        Ralf Baechle <ralf@...ux-mips.org>,
        Andi Kleen <ak@...ux.intel.com>
Subject: Re: [PATCH -V2 -mm] mm: Fix races between swapoff and flush dcache

On Mon, Mar 05, 2018 at 04:36:34PM +0800, Huang, Ying wrote:
> From: Huang Ying <ying.huang@...el.com>
> 
> From commit 4b3ef9daa4fc ("mm/swap: split swap cache into 64MB
> trunks") on, after swapoff, the address_space associated with the swap
> device will be freed.  So page_mapping() users which may touch the
> address_space need some kind of mechanism to prevent the address_space
> from being freed during accessing.
> 
> The dcache flushing functions (flush_dcache_page(), etc) in
> architecture specific code may access the address_space of swap device
> for anonymous pages in swap cache via page_mapping() function.  But in
> some cases there are no mechanisms to prevent the swap device from
> being swapoff, for example,
> 
> CPU1					CPU2
> __get_user_pages()			swapoff()
>   flush_dcache_page()
>     mapping = page_mapping()
>       ...				  exit_swap_address_space()
>       ...				    kvfree(spaces)
>       mapping_mapped(mapping)
> 
> The address space may be accessed after being freed.
> 
> But from cachetlb.txt and Russell King, flush_dcache_page() only care
> about file cache pages, for anonymous pages, flush_anon_page() should
> be used.  The implementation of flush_dcache_page() in all
> architectures follows this too.  They will check whether
> page_mapping() is NULL and whether mapping_mapped() is true to
> determine whether to flush the dcache immediately.  And they will use
> interval tree (mapping->i_mmap) to find all user space mappings.
> While mapping_mapped() and mapping->i_mmap isn't used by anonymous
> pages in swap cache at all.
> 
> So, to fix the race between swapoff and flush dcache, __page_mapping()
> is add to return the address_space for file cache pages and NULL
> otherwise.  All page_mapping() invoking in flush dcache functions are
> replaced with __page_mapping().
> 
> Signed-off-by: "Huang, Ying" <ying.huang@...el.com>
> Cc: Minchan Kim <minchan@...nel.org>
> Cc: Michal Hocko <mhocko@...e.com>
> Cc: Johannes Weiner <hannes@...xchg.org>
> Cc: Mel Gorman <mgorman@...hsingularity.net>
> Cc: Dave Hansen <dave.hansen@...el.com>
> Cc: Chen Liqin <liqin.linux@...il.com>
> Cc: Russell King <linux@...linux.org.uk>
> Cc: Yoshinori Sato <ysato@...rs.sourceforge.jp>
> Cc: "James E.J. Bottomley" <jejb@...isc-linux.org>
> Cc: Guan Xuetao <gxt@...c.pku.edu.cn>
> Cc: "David S. Miller" <davem@...emloft.net>
> Cc: Chris Zankel <chris@...kel.net>
> Cc: Vineet Gupta <vgupta@...opsys.com>
> Cc: Ley Foon Tan <lftan@...era.com>
> Cc: Ralf Baechle <ralf@...ux-mips.org>
> Cc: Andi Kleen <ak@...ux.intel.com>
> 
> Changes:
> 
> v2:
> 
> - Rename __page_mapping() to page_mapping_file() and simplified
>   implementation as suggested by Andrew Morton.
> ---
>  arch/arc/mm/cache.c           |  2 +-
>  arch/arm/mm/copypage-v4mc.c   |  2 +-
>  arch/arm/mm/copypage-v6.c     |  2 +-
>  arch/arm/mm/copypage-xscale.c |  2 +-
>  arch/arm/mm/fault-armv.c      |  2 +-
>  arch/arm/mm/flush.c           |  6 +++---
>  arch/mips/mm/cache.c          |  2 +-
>  arch/nios2/mm/cacheflush.c    |  4 ++--
>  arch/parisc/kernel/cache.c    |  5 +++--
>  arch/score/mm/cache.c         |  5 +++--
>  arch/sh/mm/cache-sh4.c        |  2 +-
>  arch/sh/mm/cache-sh7705.c     |  2 +-
>  arch/sparc/kernel/smp_64.c    |  8 ++++----
>  arch/sparc/mm/init_64.c       |  6 +++---
>  arch/sparc/mm/tlb.c           |  2 +-
>  arch/unicore32/mm/flush.c     |  2 +-
>  arch/unicore32/mm/mmu.c       |  2 +-
>  arch/xtensa/mm/cache.c        |  2 +-
>  include/linux/mm.h            |  1 +
>  mm/util.c                     | 11 +++++++++++
>  20 files changed, 42 insertions(+), 28 deletions(-)
 
...

> diff --git a/mm/util.c b/mm/util.c
> index d800ce40816c..252f4748f00b 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -515,6 +515,17 @@ struct address_space *page_mapping(struct page *page)
>  }
>  EXPORT_SYMBOL(page_mapping);
> 
> +/*
> + * For file cache pages, return the address_space, otherwise return NULL
> + */
> +struct address_space *page_mapping_file(struct page *page)
> +{
> +	if (unlikely(PageSwapCache(page)))
> +		return NULL;
> +	else

Nit: you can drop the 'else' and just fall through to return
page_mapping(page).

> +		return page_mapping(page);
> +}
> +
>  /* Slow path of page_mapcount() for compound pages */
>  int __page_mapcount(struct page *page)
>  {
> -- 
> 2.15.1
> 

-- 
Sincerely yours,
Mike.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ