[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20090105152848.GG7645@localhost>
Date: Mon, 5 Jan 2009 18:28:48 +0300
From: Cyrill Gorcunov <gorcunov@...il.com>
To: Christoph Lameter <cl@...ux-foundation.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Nick Piggin <npiggin@...e.de>, Rik van Riel <riel@...hat.com>,
LKML <linux-kernel@...r.kernel.org>,
Jiri Slaby <jirislaby@...il.com>
Subject: Re: [PATCH] mm: __nr_to_section - make it safe against overflow
[Christoph Lameter - Mon, Jan 05, 2009 at 09:10:57AM -0600]
| On Mon, 5 Jan 2009, Cyrill Gorcunov wrote:
|
| > /*
| > * This is, logically, a pointer to an array of struct
| > @@ -980,9 +986,12 @@ 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);
| > + WARN_ON_ONCE(idx >= NR_SECTION_ROOTS);
| > +
| > + if (idx >=NR_SECTION_ROOTS || !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];
| > }
| > extern int __section_nr(struct mem_section* ms);
| > extern unsigned long usemap_size(void);
|
| Not that you are adding code to numerous hot code path. Plus this is a
| frequently used inline. Code size is going to increase if you do this.
yes, I know, that is why I've changed WARN_ON_ONCE to plain WARN_ON.
|
| I would think that the code does not have the tests because of performance
| and code size concerns. Can we just say that a sane nr must be passed to
| __nr_section?
|
If you mean did I test this patch for speed regresson then to be fair --
no, I didn't. BUT we have a number of macros wich are self protective
like present_section which is used havily too. On the other hand --
bad argument passed to __nr_to_section will be (and it is now) really
harmfull -- since it would allow to reference a memory outside the
valid bounds. The second -- SECTION_ROOT_MASK wich is fragile, any
attempt to modify mem_section structure will silently lead to insane
referencing, that is why it deserve a comment on top of structure.
Don't know Christoph, if it really that important to not spend a few
cycles here in a sake of safety -- we could easily drop this patch.
- Cyrill -
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists