All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH for 2.6.18rc2] [1/7] i386/x86-64: Don't randomize stack top when...
@ 2006-07-25  9:06 Chuck Ebbert
  2006-07-25 11:38 ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Chuck Ebbert @ 2006-07-25  9:06 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Ingo Molnar, linux-kernel, Linus Torvalds, Andi Kleen

In-Reply-To: <1153815124.8932.15.camel@laptopd505.fenrus.org>

On Tue, 25 Jul 2006 10:12:04 +0200, Arjan van de Ven wrote:
> > >  unsigned long arch_align_stack(unsigned long sp)
> > >  {
> > > -     if (randomize_va_space)
> > > +     if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
> > >               sp -= get_random_int() % 8192;
> > >       return sp & ~0xf;
> > >  }
> > 
> > I think this needs to be done always, at least on P4.  It really isn't
> > 'randomization' at the same high level as the rest -- more like a small
> > adjustment.  And the offset should be a multiple of 128 and < 7K (not
> > 8K.) Something like this:
> 
> the 8K was what Intel proposed for 2.4 quite a while ago and has been in
> use in linux for years and years... Can you explain why you are saying
> 7Kb? throwing away that 1Kb of cache associativity is unfortunate and
> shouldn't be done unless there's a good reason, so I'm quite interested
> in finding out your reason ;)

Well that's what the Intel IA-32 optimization manual says:

        To establish a suitable stack offset for two instances of the same
        application running on two logical processors in the same physical
        processor package, the stack pointer can be adjusted in the entry
        function of the application using the technique shown in Example 7-5.

        Example 7-5 Adding a Pseudo-random Offset to the Stack Pointer
        in the Entry Function

        void main()
        {
        char * pPrivate = NULL;
        long myOffset = GetMod7Krandom128X()
        // A pseudo-random number that is a multiple
        // of 128 and less than 7K.
        // Use runtime library routine to reposition.
        _alloca(myOffset); // The stack pointer.
        }

        IA-32 Intel Architecture Optimization Reference Manual, Ch. 7
        June 2005
-- 
Chuck


^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH for 2.6.18rc2] [1/7] i386/x86-64: Don't randomize stack top when...
@ 2006-07-25  7:46 Chuck Ebbert
  2006-07-25  8:12 ` Arjan van de Ven
  0 siblings, 1 reply; 5+ messages in thread
From: Chuck Ebbert @ 2006-07-25  7:46 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Linus Torvalds, linux-kernel, Ingo Molnar, Arjan van de Ven

In-Reply-To: <44c514a8.6HlRR82y133O2bd0%ak@suse.de>

On Mon, 24 Jul 2006 20:42:48 +0200, Andi Kleen wrote:
> 
> --- linux.orig/arch/i386/kernel/process.c
> +++ linux/arch/i386/kernel/process.c
> @@ -37,6 +37,7 @@
>  #include <linux/kallsyms.h>
>  #include <linux/ptrace.h>
>  #include <linux/random.h>
> +#include <linux/personality.h>
>  
>  #include <asm/uaccess.h>
>  #include <asm/pgtable.h>
> @@ -905,7 +906,7 @@ asmlinkage int sys_get_thread_area(struc
>  
>  unsigned long arch_align_stack(unsigned long sp)
>  {
> -     if (randomize_va_space)
> +     if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
>               sp -= get_random_int() % 8192;
>       return sp & ~0xf;
>  }

I think this needs to be done always, at least on P4.  It really isn't
'randomization' at the same high level as the rest -- more like a small
adjustment.  And the offset should be a multiple of 128 and < 7K (not
8K.) Something like this:

        unsigned int r = get_random_int();
        sp &= ~0x7f;
        sp -= 128 * ((r % 32) + (r / 32 % 16));
        return sp;

-- 
Chuck


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-07-25 11:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-25  9:06 [PATCH for 2.6.18rc2] [1/7] i386/x86-64: Don't randomize stack top when Chuck Ebbert
2006-07-25 11:38 ` Andi Kleen
2006-07-25 11:48   ` Arjan van de Ven
  -- strict thread matches above, loose matches on Subject: below --
2006-07-25  7:46 Chuck Ebbert
2006-07-25  8:12 ` Arjan van de Ven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.