* [PATCH v1] hugetlbfs: don't access uninitialized memmaps in pfn_range_valid_gigantic()
@ 2019-10-15 12:07 David Hildenbrand
2019-10-15 12:12 ` Michal Hocko
2019-10-15 18:34 ` Mike Kravetz
0 siblings, 2 replies; 3+ messages in thread
From: David Hildenbrand @ 2019-10-15 12:07 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, David Hildenbrand, Michal Hocko, stable,
Anshuman Khandual, Mike Kravetz, Andrew Morton
Uninitialized memmaps contain garbage and in the worst case trigger
kernel BUGs, especially with CONFIG_PAGE_POISONING. They should not get
touched.
Let's make sure that we only consider online memory (managed by the
buddy) that has initialized memmaps. ZONE_DEVICE is not applicable.
page_zone() will call page_to_nid(), which will trigger
VM_BUG_ON_PGFLAGS(PagePoisoned(page), page) with CONFIG_PAGE_POISONING
and CONFIG_DEBUG_VM_PGFLAGS when called on uninitialized memmaps. This
can be the case when an offline memory block (e.g., never onlined) is
spanned by a zone.
Note: As explained by Michal in [1], alloc_contig_range() will verify
the range. So it boils down to the wrong access in this function.
[1] http://lkml.kernel.org/r/20180423000943.GO17484@dhcp22.suse.cz
Reported-by: Michal Hocko <mhocko@kernel.org>
Fixes: f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") # visible after d0dc12e86b319
Cc: stable@vger.kernel.org # v4.13+
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
mm/hugetlb.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index ef37c85423a5..b45a95363a84 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1084,11 +1084,10 @@ static bool pfn_range_valid_gigantic(struct zone *z,
struct page *page;
for (i = start_pfn; i < end_pfn; i++) {
- if (!pfn_valid(i))
+ page = pfn_to_online_page(i);
+ if (!page)
return false;
- page = pfn_to_page(i);
-
if (page_zone(page) != z)
return false;
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] hugetlbfs: don't access uninitialized memmaps in pfn_range_valid_gigantic()
2019-10-15 12:07 [PATCH v1] hugetlbfs: don't access uninitialized memmaps in pfn_range_valid_gigantic() David Hildenbrand
@ 2019-10-15 12:12 ` Michal Hocko
2019-10-15 18:34 ` Mike Kravetz
1 sibling, 0 replies; 3+ messages in thread
From: Michal Hocko @ 2019-10-15 12:12 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, linux-mm, stable, Anshuman Khandual, Mike Kravetz,
Andrew Morton
On Tue 15-10-19 14:07:17, David Hildenbrand wrote:
> Uninitialized memmaps contain garbage and in the worst case trigger
> kernel BUGs, especially with CONFIG_PAGE_POISONING. They should not get
> touched.
>
> Let's make sure that we only consider online memory (managed by the
> buddy) that has initialized memmaps. ZONE_DEVICE is not applicable.
>
> page_zone() will call page_to_nid(), which will trigger
> VM_BUG_ON_PGFLAGS(PagePoisoned(page), page) with CONFIG_PAGE_POISONING
> and CONFIG_DEBUG_VM_PGFLAGS when called on uninitialized memmaps. This
> can be the case when an offline memory block (e.g., never onlined) is
> spanned by a zone.
>
> Note: As explained by Michal in [1], alloc_contig_range() will verify
> the range. So it boils down to the wrong access in this function.
>
> [1] http://lkml.kernel.org/r/20180423000943.GO17484@dhcp22.suse.cz
>
> Reported-by: Michal Hocko <mhocko@kernel.org>
> Fixes: f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") # visible after d0dc12e86b319
> Cc: stable@vger.kernel.org # v4.13+
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Signed-off-by: David Hildenbrand <david@redhat.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Thanks!
> ---
> mm/hugetlb.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index ef37c85423a5..b45a95363a84 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1084,11 +1084,10 @@ static bool pfn_range_valid_gigantic(struct zone *z,
> struct page *page;
>
> for (i = start_pfn; i < end_pfn; i++) {
> - if (!pfn_valid(i))
> + page = pfn_to_online_page(i);
> + if (!page)
> return false;
>
> - page = pfn_to_page(i);
> -
> if (page_zone(page) != z)
> return false;
>
> --
> 2.21.0
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] hugetlbfs: don't access uninitialized memmaps in pfn_range_valid_gigantic()
2019-10-15 12:07 [PATCH v1] hugetlbfs: don't access uninitialized memmaps in pfn_range_valid_gigantic() David Hildenbrand
2019-10-15 12:12 ` Michal Hocko
@ 2019-10-15 18:34 ` Mike Kravetz
1 sibling, 0 replies; 3+ messages in thread
From: Mike Kravetz @ 2019-10-15 18:34 UTC (permalink / raw)
To: David Hildenbrand, linux-kernel
Cc: linux-mm, Michal Hocko, stable, Anshuman Khandual, Andrew Morton
On 10/15/19 5:07 AM, David Hildenbrand wrote:
> Uninitialized memmaps contain garbage and in the worst case trigger
> kernel BUGs, especially with CONFIG_PAGE_POISONING. They should not get
> touched.
>
> Let's make sure that we only consider online memory (managed by the
> buddy) that has initialized memmaps. ZONE_DEVICE is not applicable.
>
> page_zone() will call page_to_nid(), which will trigger
> VM_BUG_ON_PGFLAGS(PagePoisoned(page), page) with CONFIG_PAGE_POISONING
> and CONFIG_DEBUG_VM_PGFLAGS when called on uninitialized memmaps. This
> can be the case when an offline memory block (e.g., never onlined) is
> spanned by a zone.
>
> Note: As explained by Michal in [1], alloc_contig_range() will verify
> the range. So it boils down to the wrong access in this function.
>
> [1] http://lkml.kernel.org/r/20180423000943.GO17484@dhcp22.suse.cz
>
> Reported-by: Michal Hocko <mhocko@kernel.org>
> Fixes: f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") # visible after d0dc12e86b319
> Cc: stable@vger.kernel.org # v4.13+
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Signed-off-by: David Hildenbrand <david@redhat.com>
Thanks David,
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
--
Mike Kravetz
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-15 18:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-15 12:07 [PATCH v1] hugetlbfs: don't access uninitialized memmaps in pfn_range_valid_gigantic() David Hildenbrand
2019-10-15 12:12 ` Michal Hocko
2019-10-15 18:34 ` Mike Kravetz
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).