[PATCH 2/5] [ARM] add address randomization to mmap()

Kyungmin Park kmpark at infradead.org
Wed Jun 16 20:25:41 EDT 2010


On Thu, Jun 17, 2010 at 9:05 AM, Nicolas Pitre <nico at fluxnic.net> wrote:
> On Thu, 17 Jun 2010, Kyungmin Park wrote:
>
>> Hi,
>>
>> On Thu, Jun 17, 2010 at 5:33 AM, Nicolas Pitre <nico at fluxnic.net> wrote:
>> > Signed-off-by: Nicolas Pitre <nicolas.pitre at linaro.org>
>> > ---
>> >  arch/arm/mm/mmap.c |    4 ++++
>> >  1 files changed, 4 insertions(+), 0 deletions(-)
>> >
>> > diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
>> > index f5abc51..4f5b396 100644
>> > --- a/arch/arm/mm/mmap.c
>> > +++ b/arch/arm/mm/mmap.c
>> > @@ -7,6 +7,7 @@
>> >  #include <linux/shm.h>
>> >  #include <linux/sched.h>
>> >  #include <linux/io.h>
>> > +#include <linux/random.h>
>> >  #include <asm/cputype.h>
>> >  #include <asm/system.h>
>> >
>> > @@ -80,6 +81,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
>> >                start_addr = addr = TASK_UNMAPPED_BASE;
>> >                mm->cached_hole_size = 0;
>> >        }
>> > +       /* 8 bits of randomness in 20 address space bits */
>> > +       if (current->flags & PF_RANDOMIZE)
>> > +               addr += (get_random_int() % (1 << 8)) << PAGE_SHIFT;
>>
>> Doesn't better to use mask operation?
>>                    addr += (get_random_int() & ((1 << 8) - 1)) << PAGE_SHIFT;
>
> GCC is smart enough to optimize the modulus into a mask, effectively
> generating the exact same assembly code in both cases.
>

Right, Good to know

  1c:   e0822003        add     r2, r2, r3
  20:   e20220ff        and     r2, r2, #255    ; 0xff

Thank you,
Kyungmin Park



More information about the linux-arm-kernel mailing list