From: Andrew Morton <akpm@linux-foundation.org>
To: zhong jiang <zhongjiang@huawei.com>
Cc: ebiederm@xmission.com, linux-mm@kvack.org, mm-commits@vger.kernel.org
Subject: Re: [PATCH] kexec: add restriction on kexec_load() segment sizes
Date: Wed, 27 Jul 2016 13:03:13 -0700 [thread overview]
Message-ID: <20160727130313.c9afc876d405cc2e10da976c@linux-foundation.org> (raw)
In-Reply-To: <57983425.4090901@huawei.com>
On Wed, 27 Jul 2016 12:10:13 +0800 zhong jiang <zhongjiang@huawei.com> wrote:
> >> + for (i = 0; i < nr_segments; i++) {
> >> + if (PAGE_COUNT(image->segment[i].memsz) > totalram_pages / 2
> >> + || PAGE_COUNT(total_segments) > totalram_pages / 2)
> >> + return result;
> > And I don't think we need this? Unless we're worried about the sum of
> > all segments overflowing an unsigned long, which I guess is possible.
> > But if we care about that we should handle it in the next statement:
> >
> >> + total_segments += image->segment[i].memsz;
> > Should this be
> >
> > total_pages += PAGE_COUNT(image->segment[i].memsz);
> ok
> > ? I think "yes", if the segments are allocated separately and "no" if
> > they are all allocated in a big blob.
> There is a possible that most of segments size will exceed half of the real memory.
>
> if (PAGE_COUNT(image->segment[i].memsz) > totalram_pages / 2
> || total_pages > totalram_pages / 2)
> I guess that it is ok , we should bail out timely when it happens to the condition.
>
> is right ?
>
> your mean that above condition is no need. In the end, we check the overflow just one time.
> or I misunderstand.
It doesn't matter much. Actually I misread the code a bit. How about
for (i = 0; i < nr_segments; i++) {
unsigned long seg_pages = PAGE_COUNT(image->segment[i].memsz);
if (seg_pages > totalram_pages / 2))
return -EINVAL;
total_pages += seg_pages;
if (total_pages > totalram_pages / 2)
return -EINVAL;
}
--
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>
prev parent reply other threads:[~2016-07-27 20:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-26 3:03 [PATCH] kexec: add restriction on kexec_load() segment sizes zhongjiang
2016-07-26 19:55 ` Andrew Morton
2016-07-27 4:10 ` zhong jiang
2016-07-27 20:03 ` Andrew Morton [this message]
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=20160727130313.c9afc876d405cc2e10da976c@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=linux-mm@kvack.org \
--cc=mm-commits@vger.kernel.org \
--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).