Skip to contentSkip to conversation

x86: Don't randomize stack unless current->personality permits it

PATCH Chuck Ebbert 2 participants 2 messages Jul 25, 2006

lore
Share & tools
lore
#0 lore raw

In-Reply-To: <[email protected]>

Quoted 21 lines · Al Boldi
Quoted 12 lines

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
Quoted 8 lines

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
Quoted 4 lines

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.

Quoted 1 line

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.

Signature · 1 line
Chuck
#1 lore raw
Quoted 31 lines · Chuck Ebbert
Quoted 20 lines · Al Boldi
Quoted 11 lines

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
Quoted 8 lines

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
Quoted 3 lines

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.

Quoted 1 line

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

Quoted 8 lines

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'.

This would imply a recompile, what about precompiled dists? Do they compile the sources this way?

Quoted 1 line

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

I think so too, but can you see how randomization aggravates the situation?

Thanks!

--
Al