Undo some of the pseudo-security madness
Subsystems (2)
Quoted 18 lines · David Wagner
Quoted 10 lines · Samium Gromoff
the core of the problem are the cores which are customarily dumped by lisps during the environment generation (or modification) stage, and then mapped back, every time the environment is invoked.
at the current step of evolution, those core files are not relocatable in certain natively compiling lisp systems.
in an even smaller subset of them, these cores are placed after the shared libraries and the executable.
Quoted 6 lines
which obviously breaks when the latter are placed unpredictably. (yes, i know, currently
mmap_base()varies over a 1MB range, but who says it will last indefinitely -- probably one day these people from full-disclosure will prevail and it will become, like, 256MB ;-)so, what do you propose?
Quoted 8 lines
The obvious solution is: Don't make them setuid root. Then this issue disappears.
If there is some strong reason why they need to be setuid root, then you'll need to explain that reason and your requirements in more detail. But, based on your explanation so far, I have serious doubts about whether it is a good idea to make such core-dumps setuid root in the first place.
not "core-dumps" but "core files", in the lispspeak, but anyway.
the reason is trivial -- if i can write programs enjoying setuid privileges in C, i want to be able to do the same in Lisp.
the only way to achieve this i see, is to directly setuid root the lisp system executable itself -- because the lisp code is read, compiled and executed in the process of the lisp system executable.
there is such a thing as suid-perl -- for precise same reasons.
regards, Samium Gromoff
Quoted 1 line · Samium Gromoff
[...] directly setuid root the lisp system executable itself [...]
Like I said, that sounds like a bad idea to me. Sounds like a recipe for privilege escalation vulnerabilities. Was the lisp system executable really implemented to be secure even when you make it setuid root? Setting the setuid-root bit on programs that didn't expect to be setuid-root is generally not a very safe thing to do. [1]
The more I hear, the more unconvinced I am by this use case.
If you don't care about the security issues created by (mis)using the lisp interpreter in this way, then like I suggested before, you can always write a tiny setuid-root wrapper program that turns off address space randomization and exec()s the lisp system executable, and leave the lisp system executable non-setuid and don't touch the code in the Linux kernel. That strikes me as a better solution: those who don't mind the security risks can take all the risks they want, without forcing others to take unwanted and unnecessary risks.
It's not that I'm wedded to address space randomization of setuid programs, or that I think it would be a disaster if this patch were accepted. Local privilege escalation attacks aren't the end of the world; in all honesty, they're pretty much irrelevant to many or most users. It's just that the arguments I'm hearing advanced in support of this change seem dubious, and the change does eliminate one of the defenses against a certain (narrow) class of attacks.
[1] In comparison, suidperl was designed to be installed setuid-root, and it takes special precautions to be safe in this usage. (And even it has had some security vulnerabilities, despite its best efforts, which illustrates how tricky this business can be.) Setting the setuid-root bit on a large complex interpreter that wasn't designed to be setuid-root seems like a pretty dubious proposition to me.
Quoted 1 line · David Wagner
[1] In comparison, suidperl was designed to be installed setuid-root, and it takes special precautions to be safe in this usage. (And even it has had some security vulnerabilities, despite its best efforts, which illustrates how tricky this business can be.) Setting the setuid-root bit on a large complex interpreter that wasn't designed to be setuid-root seems like a pretty dubious proposition to me.
Well, there's also the fact that Linux does *NOT* need suidperl, as it has proper secure support for suid pound-bang scripts anyways. The only reason for suidperl in the first place was broken operating systems which had a race condition between the operating system checking the suid bits and reading the '#! /usr/bin/perl' line in the file, and the interpreter getting executed and opening a different file (think symlink redirection attacks). I believe Linux jumps through some special hoops to ensure that can't happen.
Cheers,
Kyle Moffett
At Sun, 21 Jan 2007 19:36:27 -0500,
Quoted 10 lines · Kyle Moffett
Quoted 7 lines · David Wagner
[1] In comparison, suidperl was designed to be installed setuid- root, and it takes special precautions to be safe in this usage. (And even it has had some security vulnerabilities, despite its best efforts, which illustrates how tricky this business can be.) Setting the setuid-root bit on a large complex interpreter that wasn't designed to be setuid-root seems like a pretty dubious proposition to me.
Quoted 8 lines
Well, there's also the fact that Linux does *NOT* need suidperl, as it has proper secure support for suid pound-bang scripts anyways. The only reason for suidperl in the first place was broken operating systems which had a race condition between the operating system checking the suid bits and reading the '#!
/usr/bin/perl' line in the file, and the interpreter getting executed and opening a different file (think symlink redirection attacks). I believe Linux jumps through some special hoops to ensure that can't happen.
Uh, this does not work, unfortunately in the Lisp case.
Lisp environments can produce standalone executables, which are
1. supposed to be runnable like a usual binary, without any additions
2. will suffer from the very same problem, as it merely is a runtime bundled with the core file
(and the core file is unrelocatable)
Quoted 1 line
Kyle Moffett
regards, Samium Gromoff
* Samium Gromoff:
Quoted 1 line
Lisp environments can produce standalone executables
If you've got a stand-alone executable, you don't need MAP_FIXED. The ELF loader maps the program at a fixed address anyway (at least on i386 and x86_64, I haven't checked others).
AFAIK, PolyML has recently made the switch to stand-alone executables for this reason.
At Sat, 24 Feb 2007 10:40:51 +0100,
Quoted 8 lines · Florian Weimer
* Samium Gromoff:
Quoted 1 line
Lisp environments can produce standalone executables
If you've got a stand-alone executable, you don't need
MAP_FIXED. The ELF loader maps the program at a fixed address anyway (at least on i386 andx86_64, I haven't checked others).
Not so.
The thing is that the picture is of two pieces:
- the executable
- the unrelocatable lisp core (which is unrelocatable by the virtue of non-PIC code) which is mapped into the AS of the executable.
It is the latter which breaks, as its map can overlap with randomized pieces of the executable (along with its libraries).
Quoted 2 lines
AFAIK, PolyML has recently made the switch to stand-alone executables for this reason.
regards, Samium Gromoff
* Samium Gromoff:
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Lisp environments can produce standalone executables
If you've got a stand-alone executable, you don't need
MAP_FIXED. The ELF loader maps the program at a fixed address anyway (at least on i386 andx86_64, I haven't checked others).Not so.
Quoted 8 lines
The thing is that the picture is of two pieces:
- the executable
- the unrelocatable lisp core (which is unrelocatable by the virtue of non-PIC code) which is mapped into the AS of the executable.It is the latter which breaks, as its map can overlap with randomized pieces of the executable (along with its libraries).
I think it boils down to the question if you can use ELF relocations to create a relocatable (but not necessarily position-independent) object that ld can link with the SBCL run-time system to produce an executable. This executable would truly be stand-alone because no separate core file is required anymore.
Quoted 5 lines · Samium Gromoff
not "core-dumps" but "core files", in the lispspeak, but anyway.
the reason is trivial -- if i can write programs enjoying setuid privileges in C, i want to be able to do the same in Lisp.
Go read up on how the XEmacs crew designed their "portable dumper", specifically to get around a lot of these sorts of problems because the old Emacs 'unexec' code was incredibly fragile.
Quoted 4 lines
the only way to achieve this i see, is to directly setuid root the lisp system executable itself -- because the lisp code is read, compiled and executed in the process of the lisp system executable.
If that's the only way you can see to do it, maybe you should think a bit harder before making kernel hacks to do something.
At Mon, 22 Jan 2007 10:20:21 -0500,
Quoted 10 lines · [email protected] wrote:
Quoted 5 lines · Samium Gromoff
not "core-dumps" but "core files", in the lispspeak, but anyway.
the reason is trivial -- if i can write programs enjoying setuid privileges in C, i want to be able to do the same in Lisp.
Go read up on how the XEmacs crew designed their "portable dumper", specifically to get around a lot of these sorts of problems because the old Emacs 'unexec' code was incredibly fragile.
I should take the freedom to respond in your manner :-)
Are you saying that the usefulness of AS randomisation is overall exceeding that of MAP_FIXED, and the latter should be abolished?
Did we silently enter an era where support for buggy software is more important than a basic mmap feature?
Quoted 7 lines
Quoted 4 lines
the only way to achieve this i see, is to directly setuid root the lisp system executable itself -- because the lisp code is read, compiled and executed in the process of the lisp system executable.
If that's the only way you can see to do it, maybe you should think a bit harder before making kernel hacks to do something.
I want equal grounds for platforms, that`s all.
regards, Samium Gromoff
Hi!
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
not "core-dumps" but "core files", in the lispspeak, but anyway.
the reason is trivial -- if i can write programs enjoying setuid privileges in C, i want to be able to do the same in Lisp.
Go read up on how the XEmacs crew designed their "portable dumper", specifically to get around a lot of these sorts of problems because the old Emacs 'unexec' code was incredibly fragile.
Quoted 5 lines
I should take the freedom to respond in your manner :-)
Are you saying that the usefulness of AS randomisation is overall exceeding that of
MAP_FIXED, and the latter should be abolished?
MAP_FIXED still works. You just have to be more careful where you map.
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
the only way to achieve this i see, is to directly setuid root the lisp system executable itself -- because the lisp code is read, compiled and executed in the process of the lisp system executable.
If that's the only way you can see to do it, maybe you should think a bit harder before making kernel hacks to do something.
I want equal grounds for platforms, that`s all.
Well, noone ever said all languages are equal. You have crappy lisp interpreters, and you want to break kernel because you are too lazy to fix them, and insist they must do suid in any way you choose. We won't break kernel because lisp is misdesigned.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
At Tue, 23 Jan 2007 08:48:07 +0000,
Quoted 5 lines · Pavel Machek
Quoted 3 lines
Are you saying that the usefulness of AS randomisation is overall exceeding that of
MAP_FIXED, and the latter should be abolished?
MAP_FIXEDstill works. You just have to be more careful where you map.
No amount of carefulness will prevent vendors stick arbitrarily damaging values of stack and mmap base randomisation, severely reducing the usefullness of MAP_FIXED.
And they actively take this freedom -- Arjan must know this first-hand.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
the only way to achieve this i see, is to directly setuid root the lisp system executable itself -- because the lisp code is read, compiled and executed in the process of the lisp system executable.
If that's the only way you can see to do it, maybe you should think a bit harder before making kernel hacks to do something.
Quoted 6 lines
Quoted 1 line
I want equal grounds for platforms, that`s all.
Well, noone ever said all languages are equal. You have crappy lisp interpreters, and you want to break kernel because you are too lazy to fix them, and insist they must do suid in any way you choose. We won't break kernel because lisp is misdesigned.
SBCL is the most actively developed open source Common Lisp implementation, which has an optimising native compiler built in, so it is not an interpreter, and is, most certainly, not crappy.
Speaking on the matter, how would you regard a patch which enhances the ELF loader with interpretation of an x86-specific e_flags bit which would mean a mandatory AS randomisation disable?
this has the following properties:
1. cannot serve as a vehicle for exploitation for binaries unmarked with this flag
2. serve the application deployment cause -- abolish the need for application-specific system tweaks
3. remove the need for the ugly self-reexecution tweak people needing an absolutely unadulterated memory map have to resort to /now/, even in a non-setuid case
Quoted 1 line
Pavel
P.S.:
Please, shrug off that C-esque center-of-the-world attitude, the fact there are thousand times as many C programmers does not automatically mean there is a free-for-all no-questions-asked licence to raise the implementation complexity bar for other languages.
regards, Samium Gromoff
Quoted 3 lines
SBCL is the most actively developed open source Common Lisp implementation, which has an optimising native compiler built in, so it is not an interpreter, and is, most certainly, not crappy.
If it requires MAP_FIXED I would beg to disagree.
Quoted 7 lines
1. cannot serve as a vehicle for exploitation for binaries unmarked with this flag
2. serve the application deployment cause -- abolish the need for application-specific system tweaks
3. remove the need for the ugly self-reexecution tweak people needing an absolutely unadulterated memory map have to resort to /now/, even in a non-setuid case
Seems sensible to me. If you specifically need that mapping behaviour and ask for it then it wouldn't be hard to provide.
Quoted 2 lines
Please, shrug off that C-esque center-of-the-world attitude, the fact there are thousand times as many C programmers does not
Randomisation has nothing to do with C. In fact from a C perspective the compiler and linker do a lot of work to deal with ELF and loading code at arbitary addresses for dynamic linking and the like, not the user and not as language constructs. Perhaps the Lisp universe should wake up and meet the 1980s 8)
Alan
cover Mechanism to turn of ASR on a per-ELF binary basis
These patches allow the binaries which absolutely require that their address space layout to be unaffected by address space randomisation to specify that in their ELF header.
The first part defines the ELF header flag, the second implements the corresponding part of the interpreter functionality.
regards, Samium Gromoff
PATCH 1/2 Define the EF_AS_NO_RANDOM e_flag bit
In reply to AlanAuthor: Samium Gromoff <[email protected]> Date: Tue Jan 23 22:31:13 2007 +0300
Define the ELF binary header flag EF_AS_NO_RANDOM
EF_AS_NO_RANDOM should mean that the binary requests to not apply randomisation to address spaces of its processes.
include/linux/elf.h +2 -0
@@ -172,6 +172,8 @@ typedef struct elf64_sym {#define EI_NIDENT 16 +#define EF_AS_NO_RANDOM 0x1/* do not randomise the address space */ + typedef struct elf32_hdr{ unsigned char e_ident[EI_NIDENT]; Elf32_Half e_type;
Re: [PATCH 1/2] Define the EF_AS_NO_RANDOM e_flag bit
Quoted 13 lines · Samium Gromoff
Author: Samium Gromoff <[email protected]> Date: Tue Jan 23 22:31:13 2007 +0300Define the ELF binary header flag
EF_AS_NO_RANDOM
EF_AS_NO_RANDOMshould mean that the binary requests to not apply randomisation to address spaces of its processes.include/linux/elf.h +0
-0
include/linux/elf.h typedef struct elf64_sym { · line 176
Quoted 5 lines
include/linux/elf.h +2
-0@@ -172,6 +172,8 @@ typedef struct elf64_sym {#define EI_NIDENT 16 +#define EF_AS_NO_RANDOM 0x1/* do not randomise the address space */ +
You can't make up EF_* flags this way, they are arch specific, the LSB bit (but many others too) are already used on many architectures. E.g.:
elf/mt.h:#define EF_MT_CPU_MRISC 0x00000001 /* default */ elf/sparc.h:#define EF_SPARCV9_PSO 0x1 /* partial store ordering */ elf/bfin.h:#define EF_BFIN_PIC 0x00000001 /* -fpic */ elf/alpha.h:#define EF_ALPHA_32BIT 0x00000001
elf/mips.h:#define EF_MIPS_NOREORDER 0x00000001
elf/m68k.h:#define EF_M68K_CF_ISA_A_NODIV 0x01 /* ISA A except for div */
elf/sh.h:#define EF_SH1 1
elf/arm.h:#define EF_ARM_RELEXEC 0x01
elf/cris.h:#define EF_CRIS_UNDERSCORE 0x00000001 elf/ia64.h:#define EF_IA_64_TRAPNIL (1 << 0) /* Trap NIL pointer dereferences. */ elf/vax.h:#define EF_VAX_NONPIC 0x0001 /* Object contains non-PIC code */ elf/iq2000.h:#define EF_IQ2000_CPU_IQ2000 0x00000001 /* default */ elf/frv.h:#define EF_FRV_GPR_32 0x00000001 /* -mgpr-32 */
to name just a few.
Jakub
Re: [PATCH 1/2] Define the EF_AS_NO_RANDOM e_flag bit
At Tue, 23 Jan 2007 15:50:18 -0500,
Quoted 32 lines · Jakub Jelinek
Quoted 13 lines · Samium Gromoff
Author: Samium Gromoff <[email protected]> Date: Tue Jan 23 22:31:13 2007 +0300Define the ELF binary header flag
EF_AS_NO_RANDOM
EF_AS_NO_RANDOMshould mean that the binary requests to not apply randomisation to address spaces of its processes.include/linux/elf.h +0
-0include/linux/elf.h typedef struct elf64_sym { · line 176
Quoted 5 lines
include/linux/elf.h +2
-0@@ -172,6 +172,8 @@ typedef struct elf64_sym {#define EI_NIDENT 16 +#define EF_AS_NO_RANDOM 0x1/* do not randomise the address space */ +You can't make up EF_* flags this way, they are arch specific, the LSB bit (but many others too) are already used on many architectures. E.g.:
elf/mt.h:#define EF_MT_CPU_MRISC 0x00000001 /* default */ elf/sparc.h:#define EF_SPARCV9_PSO 0x1 /* partial store ordering */ elf/bfin.h:#define EF_BFIN_PIC 0x00000001 /* -fpic */ elf/alpha.h:#define EF_ALPHA_32BIT 0x00000001elf/mips.h:#define
EF_MIPS_NOREORDER0x00000001
elf/m68k.h:#defineEF_M68K_CF_ISA_A_NODIV0x01/* ISA A except for div */
elf/sh.h:#defineEF_SH11
elf/arm.h:#defineEF_ARM_RELEXEC0x01
Quoted 6 lines
elf/cris.h:#define EF_CRIS_UNDERSCORE 0x00000001 elf/ia64.h:#define EF_IA_64_TRAPNIL (1 << 0) /* Trap NIL pointer dereferences. */ elf/vax.h:#define EF_VAX_NONPIC 0x0001 /* Object contains non-PIC code */ elf/iq2000.h:#define EF_IQ2000_CPU_IQ2000 0x00000001 /* default */ elf/frv.h:#define EF_FRV_GPR_32 0x00000001 /* -mgpr-32 */to name just a few.
Should we introduce per-arch asm/elf.h files to hold the relevant flag definitions then?
Quoted 1 line
Jakub
regards, Samium Gromoff
Re: [PATCH 1/2] Define the EF_AS_NO_RANDOM e_flag bit
Quoted 1 line · Samium Gromoff
Should we introduce per-arch
asm/elf.hfiles to hold the relevant flag definitions then?
On some architectures there are no bits left. On others you'd need to go through whomever maintains the relevant psABI to get a bit officially allocated. Really, it is very bad idea to use e_flags for this.
If all you care about is running setuid LISP programs, you'd much better put your energy into fixing the buggy ELF dumper in it.
Jakub
Re: [PATCH 1/2] Define the EF_AS_NO_RANDOM e_flag bit
At Tue, 23 Jan 2007 16:16:12 -0500,
Quoted 7 lines · Jakub Jelinek
Quoted 1 line · Samium Gromoff
Should we introduce per-arch
asm/elf.hfiles to hold the relevant flag definitions then?On some architectures there are no bits left. On others you'd need to go through whomever maintains the relevant psABI to get a bit officially allocated. Really, it is very bad idea to use
e_flagsfor this.
Currently arch_align_stack() and mmap_base() perform randomisation only on x86 and x86_64, so it is only two architectures anyway...
Quoted 4 lines
If all you care about is running setuid LISP programs, you'd much better put your energy into fixing the buggy ELF dumper in it.
Jakub
regards, Samium Gromoff
Re: [PATCH 1/2] Define the EF_AS_NO_RANDOM e_flag bit
In reply to Jakub JelinekAt Tue, 23 Jan 2007 16:16:12 -0500,
Quoted 7 lines · Jakub Jelinek
Quoted 1 line · Samium Gromoff
Should we introduce per-arch
asm/elf.hfiles to hold the relevant flag definitions then?On some architectures there are no bits left. On others you'd need to go through whomever maintains the relevant psABI to get a bit officially allocated. Really, it is very bad idea to use
e_flagsfor this.
How does one find the relevant maintainers?
Even just the specs are harder to find in the authoritative location, given the OSDL and FSG merge: the psabi documents at
http://www.linux-foundation.org/spec/refspecs/
all 404...
Quoted 4 lines
If all you care about is running setuid LISP programs, you'd much better put your energy into fixing the buggy ELF dumper in it.
Jakub
regards, Samium Gromoff
Re: [PATCH 1/2] Define the EF_AS_NO_RANDOM e_flag bit
Hi!
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Should we introduce per-arch
asm/elf.hfiles to hold the relevant flag definitions then?On some architectures there are no bits left. On others you'd need to go through whomever maintains the relevant psABI to get a bit officially allocated. Really, it is very bad idea to use
e_flagsfor this.How does one find the relevant maintainers?
Andi Kleen maintains both i386 and x86-64, so it should be easy.
(Ouch and make it one patch, it is too short to split...)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/2] Define the EF_AS_NO_RANDOM e_flag bit
In reply to Samium GromoffQuoted 7 lines · Samium Gromoff
Author: Samium Gromoff <[email protected]> Date: Tue Jan 23 22:31:13 2007 +0300Define the ELF binary header flag
EF_AS_NO_RANDOM
EF_AS_NO_RANDOMshould mean that the binary requests to not apply randomisation to address spaces of its processes.
sounds like it's not the right approach; better to follow the PT_GNU_STACK example and do it that way.....
(assuming you even need it... I personally consider every binary that would need this flag as broken)
PATCH 2/2 Make the EF_AS_NO_RANDOM e_flag bit disable PF_RANDOMIZE
In reply to AlanAuthor: Samium Gromoff <[email protected]> Date: Tue Jan 23 23:12:16 2007 +0300
load_elf_binary: do not set PF_RANDOMIZE if the ELF file has EF_AS_NO_RANDOM s
et
fs/binfmt_elf.c +0 -0
@@ -780,7 +780,8 @@ static int load_elf_binary(struct linux_binprm *bprm, struct p
t_regs *regs)
if (elf_read_implies_exec(loc->elf_ex, executable_stack))
current->personality |= READ_IMPLIES_EXEC;- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
+ if (!(current->personality & ADDR_NO_RANDOMIZE) &&
+ !(loc->elf_ex.e_flags & EF_AS_NO_RANDOM) && randomize_va_space)
current->flags |= PF_RANDOMIZE;
arch_pick_mmap_layout(current->mm);Quoted 5 lines
Randomisation has nothing to do with C. In fact from a C perspective the compiler and linker do a lot of work to deal with ELF and loading code at arbitary addresses for dynamic linking and the like, not the user and not as language constructs. Perhaps the Lisp universe should wake up and meet the 1980s 8)
Uhm, C++ folks and others have run into loader performance issues due to the way DSOs are handled. The problem is more severe in the lisp context because a typical image contains hundreds of thousands of small objects on startup.
At Sat, 24 Feb 2007 10:51:20 +0100,
Quoted 11 lines · Florian Weimer
Quoted 6 lines
Randomisation has nothing to do with C. In fact from a C perspective the compiler and linker do a lot of work to deal with ELF and loading code at arbitary addresses for dynamic linking and the like, not the user and not as language constructs. Perhaps the Lisp universe should wake up and meet the 1980s 8)
Uhm, C++ folks and others have run into loader performance issues due to the way DSOs are handled. The problem is more severe in the lisp context because a typical image contains hundreds of thousands of small objects on startup.
Well:
root@betelheise:/mnt/shared/video1 # cat /proc/pgrep sbcl | head -n1/maps | wc -l 1378
regards, Samium Gromoff
Quoted 4 lines
No amount of carefulness will prevent vendors stick arbitrarily damaging values of stack and mmap base randomisation, severely reducing the usefullness of
MAP_FIXED.
MAP_FIXED is useful still. The only safe way is to use addresses you got from mmap(), eg you overmap something.
Anything else is madness, with or without randomization. The C library for example is free, and does, allocate memory and stacks etc etc.
Same for many other libraries; in addition libraries change in size all the time... MAP_FIXED of an address you don't KNOW is free is a bug. Period.
(using an address previously obtained from mmap() is safest, but you could in theory also parse /proc/self/maps, although that is racey, since nothing guarantees that the C library didn't spawn a background thread that allocates memory)
* Arjan van de Ven:
Quoted 8 lines
Quoted 3 lines
No amount of carefulness will prevent vendors stick arbitrarily damaging values of stack and mmap base randomisation, severely reducing the usefullness of
MAP_FIXED.
MAP_FIXEDis useful still. The only safe way is to use addresses you got frommmap(), eg you overmap something.
Anything else is madness, with or without randomization. The C library for example is free, and does, allocate memory and stacks etc etc.
This reminds me of a different matter: What is the recommended way to reserve address space (so that libc etc. won't use it) *without* increasing the VM committed memory counter? In other words, without allocating backing store for it?
IIRC, mmap(PROT_NONE) followed by mprotect(PROT_READ | PROT_WRITE) seems to work, but I wonder if this is just an accident, or if this is part of the API.
This is an interesting topic because such functionality is required to make many virtual machines work with address space randomization and (especially) vm.overcommit_memory=2. They don't need the backing store from the beginning, but they really like (if not need, even) huge regions of continuous address space.