From: "Pekka Enberg" <penberg@cs.helsinki.fi>
To: "Andrew Morton" <akpm@linux-foundation.org>
Cc: "Cyrill Gorcunov" <gorcunov@gmail.com>,
npiggin@suse.de, riel@redhat.com, linux-kernel@vger.kernel.org,
jirislaby@gmail.com
Subject: Re: [PATCH] mm: __nr_to_section - make it safe against overflow v2
Date: Tue, 6 Jan 2009 12:51:47 +0200 [thread overview]
Message-ID: <84144f020901060251l697052b9udd92a4a04f830ea7@mail.gmail.com> (raw)
In-Reply-To: <20090105163742.08777d73.akpm@linux-foundation.org>
Hi Andrew,
On Tue, Jan 6, 2009 at 2:37 AM, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Mon, 5 Jan 2009 13:31:32 +0300
> Cyrill Gorcunov <gorcunov@gmail.com> wrote:
>
>> __nr_to_section should check for array bound overflow.
>> We should better get NULL dereference then silently
>> pass some memory snippet out of bounds to a caller.
>>
>
> Are there actually any known problems here?
>
>>
>> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
>> ---
>> include/linux/mmzone.h | 15 +++++++++++++--
>> 1 file changed, 13 insertions(+), 2 deletions(-)
>>
>> Index: linux-2.6.git/include/linux/mmzone.h
>> ===================================================================
>> --- linux-2.6.git.orig/include/linux/mmzone.h
>> +++ linux-2.6.git/include/linux/mmzone.h
>> @@ -935,6 +935,12 @@ static inline unsigned long early_pfn_to
>>
>> struct page;
>> struct page_cgroup;
>> +
>> +/*
>> + * NOTE: sizeof(struct mem_section) _must_ be power of 2
>> + * otherwise SECTION_ROOT_MASK will be broken so be
>> + * really cautious while modifying this structure
>> + */
>> struct mem_section {
>> /*
>> * This is, logically, a pointer to an array of struct
>> @@ -980,9 +986,14 @@ extern struct mem_section mem_section[NR
>>
>> static inline struct mem_section *__nr_to_section(unsigned long nr)
>> {
>> - if (!mem_section[SECTION_NR_TO_ROOT(nr)])
>> + unsigned long idx = SECTION_NR_TO_ROOT(nr);
>> +
>> + if (WARN_ON(idx >= NR_SECTION_ROOTS))
>> + return NULL;
>> +
>> + if (!mem_section[idx])
>> return NULL;
>> - return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK];
>> + return &mem_section[idx][nr & SECTION_ROOT_MASK];
>> }
>
> The patch adds nearly 300 bytes of stuff to mm/sparse.o, and for what??
I was thinking of things like commit
bead9a3abd15710b0bdfd418daef606722d86282 ("mm: sparsemem
memory_present() fix") and such but missed the fact that
__nr_to_section() inlined all over the place. So yeah, it's not worth
it.
Pekka
prev parent reply other threads:[~2009-01-06 10:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-05 10:31 Cyrill Gorcunov
2009-01-05 10:33 ` Pekka Enberg
2009-01-06 0:37 ` Andrew Morton
2009-01-06 5:57 ` KAMEZAWA Hiroyuki
2009-01-06 6:30 ` KAMEZAWA Hiroyuki
2009-01-06 7:49 ` Cyrill Gorcunov
2009-01-06 9:46 ` Cyrill Gorcunov
2009-01-06 10:51 ` Pekka Enberg [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=84144f020901060251l697052b9udd92a4a04f830ea7@mail.gmail.com \
--to=penberg@cs.helsinki.fi \
--cc=akpm@linux-foundation.org \
--cc=gorcunov@gmail.com \
--cc=jirislaby@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=npiggin@suse.de \
--cc=riel@redhat.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
Powered by JetHome