lkml.org 
[lkml]   [2009]   [Jan]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH] mm: __nr_to_section - make it safe against overflow
    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?



    \
     
     \ /
      Last update: 2009-01-05 16:15    [W:0.033 / U:58.340 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site