linux-2.6.2-rc2_vsyscall-gtod_B1.patch
A message that is not in the archive (sent off-list or not yet received): 1075344395.1592.87.camel@cog.beaverton.ibm.com.suse.lists.linux.kernel
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20040203085224.GA15738@mail.shareable.org.suse.lists.linux.kernel
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20040203173716.GC17895@mail.shareable.org.suse.lists.linux.kernel
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20040203182310.GA18326@mail.shareable.org.suse.lists.linux.kernel
Quoted 9 lines · Jamie Lokier
Quoted 3 lines · Andrea Arcangeli
vsyscalls will never execute anything like execve. They can at most modify userspace memory a fixed address, so if the userspace isn't fixed, then nothing can be done with a vsyscall.
Are we talking about the same
x86_64?I see this in
arch/x86_64/vsyscall.S:
Quoted 8 lines
__kernel_vsyscall:
.LSTART_vsyscall:
push %ebp
.Lpush_ebp:movl %ecx, %ebp syscallIs that page not mapped into userspace?
It is. It is needed for the vsyscall fallback for UML (UML cannot support fixed address vsyscalls) and when we have to disable user space vgettimeofday for other reasons (e.g. to use alternative time sources that cannot be mapped to user space or doing time workarounds that require real locks)
But any security advantages of not having it are at best illusionary. If you don't believe me just grep any random executable for 0xf 0x05 (= syscall) or 0xcd 0x80 (= int $0x80). Even if it wasn't in the vsyscall page you just have to find these two bytes somewhere (doesn't have to be an own instruction, they occur commonly as part of other instructions or data) and jump to them. Executables are at fixed addresses.
-Andi
Quoted 18 lines · Andi Kleen
Quoted 16 lines · Jamie Lokier
Quoted 3 lines · Andrea Arcangeli
vsyscalls will never execute anything like execve. They can at most modify userspace memory a fixed address, so if the userspace isn't fixed, then nothing can be done with a vsyscall.
Are we talking about the same
x86_64?I see this in
arch/x86_64/vsyscall.S:
__kernel_vsyscall:
.LSTART_vsyscall:
push %ebp
.Lpush_ebp:movl %ecx, %ebp syscall
Quoted 7 lines
Quoted 1 line
Is that page not mapped into userspace?
It is. It is needed for the vsyscall fallback for UML (UML cannot support fixed address vsyscalls) and when we have to disable user space vgettimeofday for other reasons (e.g. to use alternative time sources that cannot be mapped to user space or doing time workarounds that require real locks)
the fallback in gettimeofday which may be needed in some system would require a syscall instruction at fixed address too indeed (however in most systems that is not necessary so the uml fallback seems to be the one inserting the syscall instruction in common hardware).
Quoted 7 lines
But any security advantages of not having it are at best illusionary. If you don't believe me just grep any random executable for
0xf0x05(= syscall) or0xcd0x80(= int $0x80). Even if it wasn't in the vsyscall page you just have to find these two bytes somewhere (doesn't have to be an own instruction, they occur commonly as part of other instructions or data) and jump to them. Executables are at fixed addresses.
agreed.
And if they really want to relocate the vsyscall page, it's possible to implement with a new syscall without having to slowdown or change the API. We simply need to change the pte during context switch, but it will force some invlpg at every context switch. I agree it doesn't worth as far as the executable is the same on all systems.
Quoted 1 line · Andi Kleen
Executables are at fixed addresses.
No, they are not.
Look up PIE - Position Independent Executable.
That's the point: on a hardened system _all_ objects, executable and libraries, are mapped at randomised addresses. Therefore the simple overwrite-return-address exploit is no longer reliable and tends to crash the program.
That's what this desire for randomised VDSO address is all about. The executable and all the libraries are at random addresses in security-hardened PIE systems.
(Actually even when executables are at fixed addresses, they can be mapped at an address which is harder to exploit because the address contains a zero byte - something which is harder to get into a buffer overflow - but only a little harder).
[ Ulrich: I see randomised prelinking with PIE mentioned, to give per-box random addresses instead of per process. I guess I wasn't far wrong in suggesting prelinked random VDSO positions :) ]
If you are not running PIE and randomised executable and library positions, then I agree there is nothing to gain from varying the VDSO position, and it is a slight performance loss so should be disabled.
-- Jamie
Quoted 4 lines · Jamie Lokier
Quoted 1 line · Andi Kleen
Executables are at fixed addresses.
No, they are not.
this won't happen without some cost, the vsyscalls relocation syscall (the current API extension) as well won't happen without some cost. And the idea of having the vsyscall fixed per-system makes little sense since it doesn't protect against the local exploits, so if we add it, it has to be relocated per-task, so it will have some real cost (doing it fixed per-system would have zerocost instead).
However I'm unsure if you want all applications to be relocated ranodmly, and in turn if you want the vsyscalls relocated for all apps, exactly because this carry a cost. I think it should be optional. I don't think I want to slowdown to have all my applications relocated.
And really before you can ever care about the relocation, for the security-critical-apps you should recompile the app with stackguard immediatly so that you will trap when functions returns and pop an address, rendering the vsyscall relocation useless too since it'll never jump there. So before I can ever care about the vsyscalls relocation I want all security related apps compiled with stackguard, and secondly I want the ELF executable binary image relocated as well at runtime randomly. Only then I will bother to add the vsyscall relocation syscall that will simply allow userspace to define the address where to move the vsyscall and it'll flush the tlb and allocate a new pte to map the vsyscall page in there and it'll do the tlb flush and pte update during context switch. So in short there are a lot higher prio things to take care of IMHO, before going down to the vsyscall address level.
Quoted 3 lines · Andrea Arcangeli
However I'm unsure if you want all applications to be relocated ranodmly, and in turn if you want the vsyscalls relocated for all apps, exactly because this carry a cost. I think it should be optional.
If you think extra security should be optional, please don't argue against it completely.
Signature · 3 lines
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan
Quoted 8 lines · Rik van Riel
Quoted 3 lines · Andrea Arcangeli
However I'm unsure if you want all applications to be relocated ranodmly, and in turn if you want the vsyscalls relocated for all apps, exactly because this carry a cost. I think it should be optional.
If you think extra security should be optional, please don't argue against it completely.
I don't think I was arguing against it completely, exactly because I'm just saying it should be optional.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 2 lines · Andrea Arcangeli
I don't think I was arguing against it completely, exactly because I'm just saying it should be optional.
And the result is that the current fast syscall handling on x86-64 is completely unacceptable. If it's not change security enhancements are not possible since the libc has to hardcode the address.
- --
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖ -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAI10P2ijCOnn/RHQRAuegAKCtk8W1cXWKlTWkDrmfJfykzvqATQCfRX4Q cUVAR4+yIue/MFRL2xNbwfQ=
=VHoF
-----END PGP SIGNATURE-----
Quoted 11 lines · Ulrich Drepper
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 2 lines · Andrea Arcangeli
I don't think I was arguing against it completely, exactly because I'm just saying it should be optional.
And the result is that the current fast syscall handling on x86-64 is completely unacceptable. If it's not change security enhancements are not possible since the libc has to hardcode the address.
by the same argument the 2.6 i386 vsyscall is not acceptable too since it has an hardcoded address too that is the same for all binary kernels that you ship, and furthmore it has the sysenter or int 0x80 hardcoded at a fixed address to jump into. In short either you claim the 2.6.2 i386 code as broken the way glibc calls into it, or x86-64 is perfectly fine too. so your claims makes very little sense to me.
Quoted 4 lines · Andrea Arcangeli
by the same argument the 2.6 i386 vsyscall is not acceptable too since it has an hardcoded address too that is the same for all binary kernels that you ship, and furthmore it has the sysenter or int
0x80hardcoded at a fixed address to jump into.
You don't read what I write.
The official kernel might have the vdso at a fixed address part no part of the ABI requires this address and so anybody with some security conscience can change the kernel to randomize the vdso address. It's not my or Ingo's fault that Linus doesn't like the exec-shield code which would introduce the randomization. The important aspect is that we can add vdso randomization and nothing else needs changing. The same libc will run6 on a stock kernel and the one with the randomized vdso. This is not the case on x86-64 where the absolute address for the gettimeofday is used.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Quoted 8 lines · Ulrich Drepper
Quoted 4 lines · Andrea Arcangeli
by the same argument the 2.6 i386 vsyscall is not acceptable too since it has an hardcoded address too that is the same for all binary kernels that you ship, and furthmore it has the sysenter or int
0x80hardcoded at a fixed address to jump into.You don't read what I write.
not sure if it's just me, and if what you write is obvious to everyone on the list.
Quoted 9 lines
The official kernel might have the vdso at a fixed address part no part of the ABI requires this address and so anybody with some security conscience can change the kernel to randomize the vdso address. It's not my or Ingo's fault that Linus doesn't like the exec-shield code which would introduce the randomization. The important aspect is that we can add vdso randomization and nothing else needs changing. The same libc will run6 on a stock kernel and the one with the randomized vdso. This is not the case on x86-64 where the absolute address for the gettimeofday is used.
I don't know exactly what your "randomization exec-shield" code is doing either. the way I understand what you wrote is that you want to relocate the vsyscall trasparently without glibc knowledge, so in short you're saying that you don't care to randomize everything in the userspace executable address space, you only care to relocate the vgettimeofday bytecode, not the rest of the vsyscall pieces. So with your solution you'll still have "fixed" addresses in the address space that will allow an attacker to execute vgettimeofday, just like glibc can execute it without noticing the actual function was relocated. As far as glibc won't notice that vgettimeofday has been relocated by your "exec-shield", it means the attacker as well can execute it just fine. So your solution that doesn't randomize everything look less secure because you still have a "fixed address executable vgettimeofday", and most important it's less efficient in terms of performance too since the cpu will have to lookup the address at runtime every time you run a vsyscall (or even a syscall like in john's example), instead of doing it only once for all at execve time in glibc.
in short the problem with what you're proposing is that as far as you refuse to choose the "random" address in glibc instead of in kernel, it means you're not randomizing all the vsyscall code (less secure), and it also means, you'll have to find out what the kernel has choosen at runtime at every vsyscall (and in turn potentially at every syscall on x86 where kernel chooses between sysenter and int 0x80).
If you take my approch of choosing the address in glibc (possibly only when a certain environment variable is set to avoid randomizing for performance critical apps in not networked trusted enviroments) and passing it to the kernel with a new syscall "mremap_vsyscall", you'll solve those problems, and there will be no difference at all between x86 and x86-64. We may even use mremap by teaching it the potential vsyscall space.
BTW, on both x86 and x86-64 brute forcing won't be too hard, there's only a few mbytes on x86 and 2G on x86-64 to randomize, that means on x86-64 you'll break it in mean after 524288 tries, that means 8 minutes if each try takes 1msec or 6 days if each try takes 1sec. On x86 instead (due the too short address space already allocated for the direct mapping and vmalloc areas) it will take next to nothing to brute force it, infact I'm unsure if it even worth to try to randomize it on x86, it probably makes sense for the network daemons that after a non successful exploit, will segfault and won't be reachable anymore (hoping it's not a service restarted automatically by xinetd, in such case the brute force will take a few minutes ;). So by having say 16 chances you'll decrease of 15/16 the possibility of being exploited, and you'll turn the exploit in a segfault.
Comments welcome.
Quoted 10 lines · Andrea Arcangeli
Quoted 9 lines
The official kernel might have the vdso at a fixed address part no part of the ABI requires this address and so anybody with some security conscience can change the kernel to randomize the vdso address. It's not my or Ingo's fault that Linus doesn't like the exec-shield code which would introduce the randomization. The important aspect is that we can add vdso randomization and nothing else needs changing. The same libc will run6 on a stock kernel and the one with the randomized vdso. This is not the case on x86-64 where the absolute address for the gettimeofday is used.
Quoted 11 lines
I don't know exactly what your "randomization exec-shield" code is doing either. the way I understand what you wrote is that you want to relocate the vsyscall trasparently without glibc knowledge, so in short you're saying that you don't care to randomize everything in the userspace executable address space, you only care to relocate the vgettimeofday bytecode, not the rest of the vsyscall pieces. So with your solution you'll still have "fixed" addresses in the address space that will allow an attacker to execute vgettimeofday, just like glibc can execute it without noticing the actual function was relocated. As far as glibc won't notice that vgettimeofday has been relocated by your "exec-shield", it means the attacker as well can execute it just fine.
You might want to stop and take a look at the way this works on i386 before you argue with Ulrich any more about it.
Specifically, the vsyscall DSO is constructed as a normal ELF image, and its base address is passed to glibc as an AT_SYSINFO tag in the application's auxv vector. Glibc source code has absolutely no knowledge of the base address, which in fact has changed at least three times since it was created.
Signature · 2 lines
Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer
Quoted 23 lines · Daniel Jacobowitz
Quoted 10 lines · Andrea Arcangeli
Quoted 9 lines
The official kernel might have the vdso at a fixed address part no part of the ABI requires this address and so anybody with some security conscience can change the kernel to randomize the vdso address. It's not my or Ingo's fault that Linus doesn't like the exec-shield code which would introduce the randomization. The important aspect is that we can add vdso randomization and nothing else needs changing. The same libc will run6 on a stock kernel and the one with the randomized vdso. This is not the case on x86-64 where the absolute address for the gettimeofday is used.
Quoted 11 lines
I don't know exactly what your "randomization exec-shield" code is doing either. the way I understand what you wrote is that you want to relocate the vsyscall trasparently without glibc knowledge, so in short you're saying that you don't care to randomize everything in the userspace executable address space, you only care to relocate the vgettimeofday bytecode, not the rest of the vsyscall pieces. So with your solution you'll still have "fixed" addresses in the address space that will allow an attacker to execute vgettimeofday, just like glibc can execute it without noticing the actual function was relocated. As far as glibc won't notice that vgettimeofday has been relocated by your "exec-shield", it means the attacker as well can execute it just fine.
Quoted 8 lines
You might want to stop and take a look at the way this works on i386 before you argue with Ulrich any more about it.
Specifically, the vsyscall DSO is constructed as a normal ELF image, and its base address is passed to glibc as an
AT_SYSINFOtag in the application's auxv vector. Glibc source code has absolutely no knowledge of the base address, which in fact has changed at least three times since it was created.
(changing three times is worthless in terms of security, all computers runs the same bzImage so it's not changing, anyways as Ulrich said this can be fixed transparently in "their" kernel)
The idea of randomizing the base address in kernel is not different from generating it in glibc and asking the kernel to relocate. this mean it probably won't be an environment variable but a root system wide sysctl to control the randomization (so I find it less flexible, though it's probably simpler to implement). But regardless my point is that the last patch posted by john is not the way to go. glibc should call into a fixed _offset_, the base address after all doesn't matter much if it's generated by kernel or glibc, so I don't care if it's the kernel randomizing, my whole point is that glibc must keep calling vgettimeofday _direct_ without passing through the vsyscall wrapper where all the other syscalls are passing through. there is not point to pass through a wrapper when you can speed it up using a _fixed_ offset.
Glibc needs an hardcoded _fixed_ like in a stone table of offsets (yeah they're not "addresses" like in x86-64, but still they're fixed and glibc knows about each vsyscall). If we want to implement it the same way in x86-64 too (randomizing in kernel and passing down the random base address from kernel instead of generating it in glibc), it maybe troublesome for compatibility, however I don't care that much about it, as far as there is a table of hardcoded like in a stone offsets for each vsyscall, to call it directly, without a table or wrapper. I preferred the generation of the address in glibc (where the randomizing code must already exist to randomize everything else including the .text of the normally non relocatable binary) that was also backwards compatible, but this is not the bit I care about. The bit I care about is that glibc should know about the vsyscall to be efficient, and that the offsets should be fixed.
And as said the randomization in x86 will be a joke to bruce force so this randomization issue mostly matters for x86-64.
I'd like to know if people dislikes the mremap for the vsyscalls, and if they prefer the randomization code duplicated in kernel breaking backwards compatibility with current production x86-64 glibc.
Quoted 3 lines · Andrea Arcangeli
(changing three times is worthless in terms of security, all computers runs the same bzImage so it's not changing, anyways as Ulrich said this can be fixed transparently in "their" kernel)
Andrea, please stop mixing the different arguments. The three changes were for technical reasons, not security.
Quoted 2 lines
The bit I care about is that glibc should know about the vsyscall to be efficient,
This I agree with,
Quoted 1 line
and that the offsets should be fixed.
If the vdso position can vary between kernels, there is no real technical reason why the offsets have to be fixed. At the simplest, just like there is AT_SYSINFO to get the generic syscall entry point, pass an AT_SYSINFO_GTOD for the gettimeofday syscall. Glibc can use that with no significant changes to its existing mechanism.
(Although I prefer to use symbols in the vdso because it's cleaner, AT_SYSINFO_GTOD works. Another alternative is to have a table of offsets in the vsyscall page which Glibc can read - future extensible without the overhead of symbol lookups which Ulrich doesn't like).
-- Jamie