tmpfs: fix shared mempolicy leak
This fixes a regression in 3.7-rc, which has since gone into stable. Commit00442ad04a
("mempolicy: fix a memory corruption by refcount imbalance in alloc_pages_vma()") changed get_vma_policy() to raise the refcount on a shmem shared mempolicy; whereas shmem_alloc_page() went on expecting alloc_page_vma() to drop the refcount it had acquired. This deserves a rework: but for now fix the leak in shmem_alloc_page(). Hugh: shmem_swapin() did not need a fix, but surely it's clearer to use the same refcounting there as in shmem_alloc_page(), delete its onstack mempolicy, and the strange mpol_cond_copy() and __mpol_cond_copy() - those were invented to let swapin_readahead() make an unknown number of calls to alloc_pages_vma() with one mempolicy; but since00442ad04a
, alloc_pages_vma() has kept refcount in balance, so now no problem. Reported-and-tested-by: Tommi Rantala <tt.rantala@gmail.com> Signed-off-by: Mel Gorman <mgorman@suse.de> Signed-off-by: Hugh Dickins <hughd@google.com> Cc: stable@vger.kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
c702418f8a
commit
18a2f371f5
@@ -2037,28 +2037,6 @@ struct mempolicy *__mpol_dup(struct mempolicy *old)
|
||||
return new;
|
||||
}
|
||||
|
||||
/*
|
||||
* If *frompol needs [has] an extra ref, copy *frompol to *tompol ,
|
||||
* eliminate the * MPOL_F_* flags that require conditional ref and
|
||||
* [NOTE!!!] drop the extra ref. Not safe to reference *frompol directly
|
||||
* after return. Use the returned value.
|
||||
*
|
||||
* Allows use of a mempolicy for, e.g., multiple allocations with a single
|
||||
* policy lookup, even if the policy needs/has extra ref on lookup.
|
||||
* shmem_readahead needs this.
|
||||
*/
|
||||
struct mempolicy *__mpol_cond_copy(struct mempolicy *tompol,
|
||||
struct mempolicy *frompol)
|
||||
{
|
||||
if (!mpol_needs_cond_ref(frompol))
|
||||
return frompol;
|
||||
|
||||
*tompol = *frompol;
|
||||
tompol->flags &= ~MPOL_F_SHARED; /* copy doesn't need unref */
|
||||
__mpol_put(frompol);
|
||||
return tompol;
|
||||
}
|
||||
|
||||
/* Slow path of a mempolicy comparison */
|
||||
bool __mpol_equal(struct mempolicy *a, struct mempolicy *b)
|
||||
{
|
||||
|
Reference in New Issue
Block a user