* [PATCH] mm/mempolicy.c: do not put mempolicy before using its nodemask
@ 2017-01-18 14:11 Vlastimil Babka
2017-01-18 17:04 ` Kirill A. Shutemov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Vlastimil Babka @ 2017-01-18 14:11 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-mm, linux-kernel, Vlastimil Babka, stable,
Aneesh Kumar K . V, Kirill A . Shutemov, David Rientjes,
Andrea Arcangeli
Since commit be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to
alloc_pages_vma") alloc_pages_vma() can potentially free a mempolicy by
mpol_cond_put() before accessing the embedded nodemask by
__alloc_pages_nodemask(). The commit log says it's so "we can use a single
exit path within the function" but that's clearly wrong. We can still do that
when doing mpol_cond_put() after the allocation attempt.
Make sure the mempolicy is not freed prematurely, otherwise
__alloc_pages_nodemask() can end up using a bogus nodemask, which could lead
e.g. to premature OOM.
Fixes: be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to alloc_pages_vma")
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Cc: stable@vger.kernel.org
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
---
mm/mempolicy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 2e346645eb80..1e7873e40c9a 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2017,8 +2017,8 @@ alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
nmask = policy_nodemask(gfp, pol);
zl = policy_zonelist(gfp, pol, node);
- mpol_cond_put(pol);
page = __alloc_pages_nodemask(gfp, order, zl, nmask);
+ mpol_cond_put(pol);
out:
if (unlikely(!page && read_mems_allowed_retry(cpuset_mems_cookie)))
goto retry_cpuset;
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mempolicy.c: do not put mempolicy before using its nodemask
2017-01-18 14:11 [PATCH] mm/mempolicy.c: do not put mempolicy before using its nodemask Vlastimil Babka
@ 2017-01-18 17:04 ` Kirill A. Shutemov
2017-01-18 19:03 ` Michal Hocko
2017-01-18 21:34 ` David Rientjes
2 siblings, 0 replies; 4+ messages in thread
From: Kirill A. Shutemov @ 2017-01-18 17:04 UTC (permalink / raw)
To: Vlastimil Babka
Cc: Andrew Morton, linux-mm, linux-kernel, stable,
Aneesh Kumar K . V, David Rientjes, Andrea Arcangeli
On Wed, Jan 18, 2017 at 03:11:24PM +0100, Vlastimil Babka wrote:
> Since commit be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to
> alloc_pages_vma") alloc_pages_vma() can potentially free a mempolicy by
> mpol_cond_put() before accessing the embedded nodemask by
> __alloc_pages_nodemask(). The commit log says it's so "we can use a single
> exit path within the function" but that's clearly wrong. We can still do that
> when doing mpol_cond_put() after the allocation attempt.
>
> Make sure the mempolicy is not freed prematurely, otherwise
> __alloc_pages_nodemask() can end up using a bogus nodemask, which could lead
> e.g. to premature OOM.
>
> Fixes: be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to alloc_pages_vma")
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> Cc: stable@vger.kernel.org
> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
Looks good to me.
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
--
Kirill A. Shutemov
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mempolicy.c: do not put mempolicy before using its nodemask
2017-01-18 14:11 [PATCH] mm/mempolicy.c: do not put mempolicy before using its nodemask Vlastimil Babka
2017-01-18 17:04 ` Kirill A. Shutemov
@ 2017-01-18 19:03 ` Michal Hocko
2017-01-18 21:34 ` David Rientjes
2 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2017-01-18 19:03 UTC (permalink / raw)
To: Vlastimil Babka
Cc: Andrew Morton, linux-mm, linux-kernel, stable,
Aneesh Kumar K . V, Kirill A . Shutemov, David Rientjes,
Andrea Arcangeli
On Wed 18-01-17 15:11:24, Vlastimil Babka wrote:
> Since commit be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to
> alloc_pages_vma") alloc_pages_vma() can potentially free a mempolicy by
> mpol_cond_put() before accessing the embedded nodemask by
> __alloc_pages_nodemask(). The commit log says it's so "we can use a single
> exit path within the function" but that's clearly wrong. We can still do that
> when doing mpol_cond_put() after the allocation attempt.
>
> Make sure the mempolicy is not freed prematurely, otherwise
> __alloc_pages_nodemask() can end up using a bogus nodemask, which could lead
> e.g. to premature OOM.
>
> Fixes: be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to alloc_pages_vma")
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> Cc: stable@vger.kernel.org
> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
> mm/mempolicy.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 2e346645eb80..1e7873e40c9a 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -2017,8 +2017,8 @@ alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
>
> nmask = policy_nodemask(gfp, pol);
> zl = policy_zonelist(gfp, pol, node);
> - mpol_cond_put(pol);
> page = __alloc_pages_nodemask(gfp, order, zl, nmask);
> + mpol_cond_put(pol);
> out:
> if (unlikely(!page && read_mems_allowed_retry(cpuset_mems_cookie)))
> goto retry_cpuset;
> --
> 2.11.0
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mempolicy.c: do not put mempolicy before using its nodemask
2017-01-18 14:11 [PATCH] mm/mempolicy.c: do not put mempolicy before using its nodemask Vlastimil Babka
2017-01-18 17:04 ` Kirill A. Shutemov
2017-01-18 19:03 ` Michal Hocko
@ 2017-01-18 21:34 ` David Rientjes
2 siblings, 0 replies; 4+ messages in thread
From: David Rientjes @ 2017-01-18 21:34 UTC (permalink / raw)
To: Vlastimil Babka
Cc: Andrew Morton, linux-mm, linux-kernel, stable,
Aneesh Kumar K . V, Kirill A . Shutemov, Andrea Arcangeli
On Wed, 18 Jan 2017, Vlastimil Babka wrote:
> Since commit be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to
> alloc_pages_vma") alloc_pages_vma() can potentially free a mempolicy by
> mpol_cond_put() before accessing the embedded nodemask by
> __alloc_pages_nodemask(). The commit log says it's so "we can use a single
> exit path within the function" but that's clearly wrong. We can still do that
> when doing mpol_cond_put() after the allocation attempt.
>
> Make sure the mempolicy is not freed prematurely, otherwise
> __alloc_pages_nodemask() can end up using a bogus nodemask, which could lead
> e.g. to premature OOM.
>
> Fixes: be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to alloc_pages_vma")
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> Cc: stable@vger.kernel.org
> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
Acked-by: David Rientjes <rientjes@google.com>
I think this deserves Cc: stable@vger.kernel.org [4.0+]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-01-18 21:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-18 14:11 [PATCH] mm/mempolicy.c: do not put mempolicy before using its nodemask Vlastimil Babka
2017-01-18 17:04 ` Kirill A. Shutemov
2017-01-18 19:03 ` Michal Hocko
2017-01-18 21:34 ` David Rientjes
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).