mm/mempolicy.c: do not put mempolicy before using its nodemask
Subsystems (3)
PATCH 1/1 mm/mempolicy.c: do not put mempolicy before using its nodemask
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.
--- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mempolicy.c +1 -1
@@ -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;
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Vlastimil Babka
Since commit
be97a41b291e("mm/mempolicy.c: mergealloc_hugepage_vmatoalloc_pages_vma")alloc_pages_vma()can potentially free a mempolicy bympol_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 doingmpol_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.
Quoted 7 lines
Fixes be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to alloc_pages_vma")Signed-off-by Vlastimil Babka <[email protected]>Cc Aneesh Kumar K.V <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc David Rientjes <[email protected]>Cc Andrea Arcangeli <[email protected]>
Looks good to me.
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Vlastimil Babka
Since commit
be97a41b291e("mm/mempolicy.c: mergealloc_hugepage_vmatoalloc_pages_vma")alloc_pages_vma()can potentially free a mempolicy bympol_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 doingmpol_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.
Quoted 7 lines
Fixes be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to alloc_pages_vma")Signed-off-by Vlastimil Babka <[email protected]>Cc Aneesh Kumar K.V <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc David Rientjes <[email protected]>Cc Andrea Arcangeli <[email protected]>
Quoted 26 lines
--- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/mempolicy.c +1
-1@@ -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;Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Vlastimil Babka
Since commit
be97a41b291e("mm/mempolicy.c: mergealloc_hugepage_vmatoalloc_pages_vma")alloc_pages_vma()can potentially free a mempolicy bympol_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 doingmpol_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.
Quoted 7 lines
Fixes be97a41b291e ("mm/mempolicy.c: merge alloc_hugepage_vma to alloc_pages_vma")Signed-off-by Vlastimil Babka <[email protected]>Cc Aneesh Kumar K.V <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc David Rientjes <[email protected]>Cc Andrea Arcangeli <[email protected]>
I think this deserves Cc: [email protected] [4.0+]
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>