All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: fix a overflow in test_pages_in_a_zone()
@ 2017-02-07 11:34 zhongjiang
  2017-02-07 17:35 ` Kani, Toshimitsu
  0 siblings, 1 reply; 3+ messages in thread
From: zhongjiang @ 2017-02-07 11:34 UTC (permalink / raw)
  To: akpm, toshi.kani; +Cc: vbabka, mgorman, linux-mm

From: zhong jiang <zhongjiang@huawei.com>

when the mailline introduce the commit a96dfddbcc04
("base/memory, hotplug: fix a kernel oops in show_valid_zones()"),
it obtains the valid start and end pfn from the given pfn range.
The valid start pfn can fix the actual issue, but it introduce
another issue. The valid end pfn will may exceed the given end_pfn.

Ahthough the incorrect overflow will not result in actual problem
at present, but I think it need to be fixed.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 mm/memory_hotplug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index b8c11e0..f611584 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1521,7 +1521,7 @@ int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn,
 
 	if (zone) {
 		*valid_start = start;
-		*valid_end = end;
+		*valid_end = min(end, end_pfn);
 		return 1;
 	} else {
 		return 0;
-- 
1.8.3.1

--
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>

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: fix a overflow in test_pages_in_a_zone()
  2017-02-07 11:34 [PATCH] mm: fix a overflow in test_pages_in_a_zone() zhongjiang
@ 2017-02-07 17:35 ` Kani, Toshimitsu
  2017-02-08  6:12   ` zhong jiang
  0 siblings, 1 reply; 3+ messages in thread
From: Kani, Toshimitsu @ 2017-02-07 17:35 UTC (permalink / raw)
  To: zhongjiang, akpm; +Cc: linux-mm, mgorman, vbabka

On Tue, 2017-02-07 at 19:34 +0800, zhongjiang wrote:
> From: zhong jiang <zhongjiang@huawei.com>
> 
> when the mailline introduce the commit a96dfddbcc04
> ("base/memory, hotplug: fix a kernel oops in show_valid_zones()"),
> it obtains the valid start and end pfn from the given pfn range.
> The valid start pfn can fix the actual issue, but it introduce
> another issue. The valid end pfn will may exceed the given end_pfn.
> 
> Ahthough the incorrect overflow will not result in actual problem
> at present, but I think it need to be fixed.

Yes, test_pages_in_a_zone() assumes that end_pfn is aligned by
MAX_ORDER_NR_PAGES.  This is true for both callers, show_valid_zones()
and __offline_pages().  I did not introduce this assumption. :-)

As you pointed out, it is prudent to remove this assumption for future
usages.  In this case, I think we need the following change as well.

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index a40c0c2..09c8b99 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1513,7 +1513,7 @@ int test_pages_in_a_zone(unsigned long start_pfn,
unsigned long end_pfn,
                while ((i < MAX_ORDER_NR_PAGES) &&
                        !pfn_valid_within(pfn + i))
                        i++;
-               if (i == MAX_ORDER_NR_PAGES)
+               if ((i == MAX_ORDER_NR_PAGES) || (pfn + i >= end_pfn))
                        continue;
                page = pfn_to_page(pfn + i);
                if (zone && page_zone(page) != zone)


Thanks,
-Toshi


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: fix a overflow in test_pages_in_a_zone()
  2017-02-07 17:35 ` Kani, Toshimitsu
@ 2017-02-08  6:12   ` zhong jiang
  0 siblings, 0 replies; 3+ messages in thread
From: zhong jiang @ 2017-02-08  6:12 UTC (permalink / raw)
  To: Kani, Toshimitsu; +Cc: akpm, linux-mm, mgorman, vbabka

On 2017/2/8 1:35, Kani, Toshimitsu wrote:
> On Tue, 2017-02-07 at 19:34 +0800, zhongjiang wrote:
>> From: zhong jiang <zhongjiang@huawei.com>
>>
>> when the mailline introduce the commit a96dfddbcc04
>> ("base/memory, hotplug: fix a kernel oops in show_valid_zones()"),
>> it obtains the valid start and end pfn from the given pfn range.
>> The valid start pfn can fix the actual issue, but it introduce
>> another issue. The valid end pfn will may exceed the given end_pfn.
>>
>> Ahthough the incorrect overflow will not result in actual problem
>> at present, but I think it need to be fixed.
> Yes, test_pages_in_a_zone() assumes that end_pfn is aligned by
> MAX_ORDER_NR_PAGES.  This is true for both callers, show_valid_zones()
> and __offline_pages().  I did not introduce this assumption. :-)
>
> As you pointed out, it is prudent to remove this assumption for future
> usages.  In this case, I think we need the following change as well.
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index a40c0c2..09c8b99 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1513,7 +1513,7 @@ int test_pages_in_a_zone(unsigned long start_pfn,
> unsigned long end_pfn,
>                 while ((i < MAX_ORDER_NR_PAGES) &&
>                         !pfn_valid_within(pfn + i))
>                         i++;
> -               if (i == MAX_ORDER_NR_PAGES)
> +               if ((i == MAX_ORDER_NR_PAGES) || (pfn + i >= end_pfn))
>                         continue;
>                 page = pfn_to_page(pfn + i);
>                 if (zone && page_zone(page) != zone)
>
>
> Thanks,
> -Toshi
>
 Indeed, sorry, I forget the change.

 Thanks
 zhongjiang

--
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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-08  6:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-07 11:34 [PATCH] mm: fix a overflow in test_pages_in_a_zone() zhongjiang
2017-02-07 17:35 ` Kani, Toshimitsu
2017-02-08  6:12   ` zhong jiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.