linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Kani, Toshimitsu" <toshi.kani@hpe.com>
To: "zhongjiang@huawei.com" <zhongjiang@huawei.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"mgorman@techsingularity.net" <mgorman@techsingularity.net>,
	"vbabka@suse.cz" <vbabka@suse.cz>
Subject: Re: [PATCH] mm: fix a overflow in test_pages_in_a_zone()
Date: Tue, 7 Feb 2017 17:35:34 +0000	[thread overview]
Message-ID: <1486492248.2029.34.camel@hpe.com> (raw)
In-Reply-To: <1486467299-22648-1-git-send-email-zhongjiang@huawei.com>

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


  reply	other threads:[~2017-02-07 17:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-07 11:34 [PATCH] mm: fix a overflow in test_pages_in_a_zone() zhongjiang
2017-02-07 17:35 ` Kani, Toshimitsu [this message]
2017-02-08  6:12   ` zhong jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1486492248.2029.34.camel@hpe.com \
    --to=toshi.kani@hpe.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=vbabka@suse.cz \
    --cc=zhongjiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).