Skip to contentSkip to conversation

i386/x86-64: Don't randomize stack top when...

PATCH Chuck Ebbert 3 participants 3 messages Jul 25, 2006

lore
Share & tools
lore
#0 lore raw

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

Quoted 13 lines · Arjan van de Ven
Quoted 8 lines

Review

Quoted 7 lines

unsigned long arch_align_stack(unsigned long sp)
{

(quoted diff) +1 -1
-     if (randomize_va_space)
+     if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
              sp -= get_random_int() % 8192;
      return sp & ~0xf;
 }
Quoted 4 lines

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:

Quoted 5 lines

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

Signature · 1 line
Chuck
#1 lore raw
Quoted 16 lines · Chuck Ebbert

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

Quoted 13 lines · Arjan van de Ven
Quoted 12 lines
Quoted 7 lines

unsigned long arch_align_stack(unsigned long sp)
{

(quoted diff) +1 -1
-     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:

Quoted 7 lines
Quoted 5 lines

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:

The reason I allowed to disable it is that it is sometimes very useful for debugging if you can get 100% reproducible addresses.

-Andi

#2 lore raw
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

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 ;)

Quoted 4 lines
Quoted 1 line

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

The reason I allowed to disable it is that it is sometimes very useful for debugging if you can get 100% reproducible addresses.

that I fully agree with; if you say as user "hey I don't care about anything but give me no randomization" we should give the user no randomization.

Signature · 1 line
if you want to mail me at work (you don't), use arjan (at) linux.intel.com