linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] x86: Don't randomize stack unless current->personality permits it
@ 2006-07-19 17:02 Chuck Ebbert
  2006-07-20 17:23 ` Al Boldi
  0 siblings, 1 reply; 24+ messages in thread
From: Chuck Ebbert @ 2006-07-19 17:02 UTC (permalink / raw)
  To: Al Boldi
  Cc: Paulo Marques, linux-kernel, Arjan van de Ven, Frank van Maarseveen

In-Reply-To: <200607180821.45346.a1426z@gawab.com>

On Tue, 18 Jul 2006 08:21:45 +0300. Al Boldi wrote:

> Going one step further,
> with #define arch_stack_align(x) (x)
> all blips/hits/weirdness are gone
> 
> Which means that either arch_stack_align isn't necessary at all, or 
> randomization isn't working as intended.
> 
> Can somebody prove me wrong here?

Your program seems highly sensitive to any changes, e.g. with the
following code, results with and without the commented lines are
different.  (I changed i to 5555555 because my cpu is slower than
yours and changed main() to call it 10 times.)  This on an AMD
Turion64 1.6GHz running an i386 kernel with stock arch_stack_align()
and randomize_va_space == 1.

void fn()
{
        double x = 0.0, y = 0.0;
        long i = 5555555;
//      static int printed = 0;
//
//      if (!printed) {
//              printed++;
//              printf("&x = %p, &y = %p\n", &x, &y);
//      }

        elapsed(1);
        while (i--)
                fn2(&x,&y);
        printf("%4lu ", elapsed(0));
}

$ ./tst.ex
&x = 0xbfb32d90, &y = 0xbfb32d98
  10    6   10   10    6   10    7   10   10   10   10   10   10   10   10   10   10   10   10   10 msec
$ ./tst.ex
   7   10    6    6    6    6   10   10    6    6    6   10   10    6    6    6    6   10    6    6 msec

BTW when compiled with gcc 4.1.1 using -O3 it just prints all zeros,
so I had to use 3.3.3.
-- 
Chuck

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: [PATCH] x86: Don't randomize stack unless current->personality permits it
@ 2006-07-25  0:21 Chuck Ebbert
  2006-07-25  4:57 ` Al Boldi
  0 siblings, 1 reply; 24+ messages in thread
From: Chuck Ebbert @ 2006-07-25  0:21 UTC (permalink / raw)
  To: Al Boldi
  Cc: Paulo Marques, linux-kernel, Arjan van de Ven, Frank van Maarseveen

In-Reply-To: <200607241857.46594.a1426z@gawab.com>

On Mon, 24 Jul 2006 18:57:46 +0300, Al Boldi wrote:
>
> > With your changes on:
> >
> > stock kernel, randomize_va_space=0, gcc.322 -Os tstExec.c,
> > while :; do ./a.out; done
> > &x = 0xbffff874, &y = 0xbffff86c   28   28
> > &x = 0xbffff874, &y = 0xbffff86c   27   27  
> > &x = 0xbffff874, &y = 0xbffff86c   27   27
> > &x = 0xbffff874, &y = 0xbffff86c   28   27
> > &x = 0xbffff874, &y = 0xbffff86c   27   30
> > &x = 0xbffff874, &y = 0xbffff86c   27   29
> >
> > stock kernel, randomize_va_space=1, gcc.322 -Os tstExec.c,
> > while :; do ./a.out; done
> > &x = 0xbfe2e614, &y = 0xbfe2e60c   29   28
> > &x = 0xbfd6a104, &y = 0xbfd6a0fc   55   56  
> > &x = 0xbf91d454, &y = 0xbf91d44c   27   27
> > &x = 0xbf941e84, &y = 0xbf941e7c   55   56
> > &x = 0xbfa75834, &y = 0xbfa7582c   28   27
> > &x = 0xbfb58634, &y = 0xbfb5862c   27   30
>
> After closer inspection, it looks like addresses ending with 3c,7c,bc,fc 
> cause a slowdown on P4, while addresses ending with 1c,3c,5c,7c,9c,bc,dc,fc 
> cause a slowdown on P2.
>

Those addresses cause 'y' to span a cacheline (P4 = 64 bytes, P2 = 32.)
Even when the kernel aligns to 128 bytes this could happen depending
on how deeply you nest functions.

> Any easy way to instruct the kernel to skip those addresses?

First, I think you need to define locals in order of decreasing size.
IOW 'x' and 'y' need to be first inside fn(), but that may not work
when things get inlined.  So using the '-malign-double' GCC option,
or forcing alignment with '__attribute__ ((aligned(8)))' for each variable
might be better.

Then you have to make sure the stack is aligned. See
'-mpreferred-stack-boundary'.

I still think the kernel should be aligning the stack to 128 bytes anyway.

-- 
Chuck


^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: [PATCH] x86: Don't randomize stack unless current->personality permits it
@ 2006-07-16  3:58 Chuck Ebbert
  2006-07-16 19:49 ` Al Boldi
  0 siblings, 1 reply; 24+ messages in thread
From: Chuck Ebbert @ 2006-07-16  3:58 UTC (permalink / raw)
  To: Al Boldi; +Cc: Frank van Maarseveen, linux-kernel, Arjan van de Ven, Andi Kleen

In-Reply-To: <200607151709.45870.a1426z@gawab.com>

On Sat, 15 Jul 2006 17:09:45 +0300, Al Boldi wrote:

> Randomization on.  Executable runs with 8x blips/hits.
> Randomization off.  Executable runs without blips/hits.
> With randomization off, a mere rename causes an 8x-slowdown to occur.  Run 
> this renamed executable through sh -c ./tstExec, and the slowdown 
> disappears.  Really weired :)

Does this help at all?  I don't have a space heater^W^WPentium IV
to test on.

--- 2.6.18-rc1-nb.orig/arch/i386/kernel/process.c
+++ 2.6.18-rc1-nb/arch/i386/kernel/process.c
@@ -890,5 +890,5 @@ unsigned long arch_align_stack(unsigned 
 {
 	if (randomize_va_space)
 		sp -= get_random_int() % 8192;
-	return sp & ~0xf;
+	return sp & ~0x7f;
 }
-- 
Chuck
 "You can't read a newspaper if you can't read."  --George W. Bush

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: [PATCH] x86: Don't randomize stack unless current->personality permits it
@ 2006-07-11 19:57 Al Boldi
  2006-07-12 16:03 ` Andi Kleen
  0 siblings, 1 reply; 24+ messages in thread
From: Al Boldi @ 2006-07-11 19:57 UTC (permalink / raw)
  To: Frank van Maarseveen; +Cc: linux-kernel

Frank van Maarseveen wrote:
>
> Do not randomize stack location unless current->personality permits it.
>
> Signed-off-by: Frank van Maarseveen <frankvm@frankvm.com>
> ---
>
> The problem seems also present in
>
>         arch/um/kernel/process_kern.c
>         arch/x86_64/kernel/process.c
>
>  arch/i386/kernel/process.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletion(-)
>
> diff -rup a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
> --- a/arch/i386/kernel/process.c        2006-06-23 16:08:13.000000000
> +0200 +++ b/arch/i386/kernel/process.c        2006-07-11
> 14:39:20.000000000 +0200 @@ -38,6 +38,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>
> @@ -898,7 +899,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;
>  }

It still blips on my system.

echo 0 > /proc/sys/kernel/randomize_va_space makes the blips go away.

???

Thanks!

--
Al


^ permalink raw reply	[flat|nested] 24+ messages in thread
* [PATCH] x86: Don't randomize stack unless current->personality permits it
@ 2006-07-11 15:22 Frank van Maarseveen
  2006-07-11 20:11 ` Arjan van de Ven
  0 siblings, 1 reply; 24+ messages in thread
From: Frank van Maarseveen @ 2006-07-11 15:22 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

Do not randomize stack location unless current->personality permits it.

Signed-off-by: Frank van Maarseveen <frankvm@frankvm.com>
---

The problem seems also present in

	arch/um/kernel/process_kern.c
	arch/x86_64/kernel/process.c

 arch/i386/kernel/process.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)

diff -rup a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
--- a/arch/i386/kernel/process.c	2006-06-23 16:08:13.000000000 +0200
+++ b/arch/i386/kernel/process.c	2006-07-11 14:39:20.000000000 +0200
@@ -38,6 +38,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>
@@ -898,7 +899,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;
 }


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

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

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-19 17:02 [PATCH] x86: Don't randomize stack unless current->personality permits it Chuck Ebbert
2006-07-20 17:23 ` Al Boldi
2006-07-24 15:57   ` Al Boldi
  -- strict thread matches above, loose matches on Subject: below --
2006-07-25  0:21 Chuck Ebbert
2006-07-25  4:57 ` Al Boldi
2006-07-16  3:58 Chuck Ebbert
2006-07-16 19:49 ` Al Boldi
2006-07-11 19:57 Al Boldi
2006-07-12 16:03 ` Andi Kleen
2006-07-12 20:12   ` Al Boldi
2006-07-12 20:27     ` Arjan van de Ven
2006-07-12 21:13       ` Al Boldi
2006-07-13  9:44   ` Frank van Maarseveen
2006-07-13 20:51     ` Al Boldi
2006-07-13 20:54       ` Arjan van de Ven
2006-07-15 11:29         ` Al Boldi
2006-07-15 12:22           ` Arjan van de Ven
2006-07-15 14:09             ` Al Boldi
2006-07-15 16:15               ` Arjan van de Ven
2006-07-15 17:39               ` Al Boldi
2006-07-17 15:50               ` Paulo Marques
2006-07-18  5:21                 ` Al Boldi
2006-07-11 15:22 Frank van Maarseveen
2006-07-11 20:11 ` Arjan van de Ven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).