From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755340AbZAEPMF (ORCPT ); Mon, 5 Jan 2009 10:12:05 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1750988AbZAEPLz (ORCPT ); Mon, 5 Jan 2009 10:11:55 -0500 Received: from nlpi053.sbcis.sbc.com ([207.115.36.82]:47424 "EHLO nlpi053.prodigy.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750965AbZAEPLy (ORCPT ); Mon, 5 Jan 2009 10:11:54 -0500 Date: Mon, 5 Jan 2009 09:10:57 -0600 (CST) From: Christoph Lameter X-X-Sender: cl@quilx.com To: Cyrill Gorcunov cc: Andrew Morton , Nick Piggin , Rik van Riel , LKML , Jiri Slaby Subject: Re: [PATCH] mm: __nr_to_section - make it safe against overflow In-Reply-To: <20090105094034.GA7645@localhost> Message-ID: References: <20090105094034.GA7645@localhost> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Score: -2.6 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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?