Bug 12813

Summary: Linux x86_64: glibc should prefer the vDSO over vsyscalls
Product: glibc Reporter: Andy Lutomirski <luto>
Component: libcAssignee: Ulrich Drepper <drepper.fsp>
Status: RESOLVED FIXED    
Severity: normal Flags: fweimer: security-
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Andy Lutomirski 2011-05-26 21:24:41 UTC
As of right now, all functionality in the vsyscall page is available through the vDSO on x86_64.  The missing function was time(), but that landed here:

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=f144a6b4d1688675d88990e29567b2335b48205e

and is faster than the vsyscall version because of

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=973aa8181e10050809b56ecbaadd01495766a19e

Currently (AFAICT), glibc will use the gettimeofday vsyscall in static builds due to:

#ifdef SHARED
        movq    __vdso_gettimeofday(%rip), %rax
        PTR_DEMANGLE (%rax)
#else
        movq    $VSYSCALL_ADDR_vgettimeofday, %rax
#endif

and will unconditionally use the vsyscall versions of time and getcpu.


It would be nice to kill off the vsyscall page entirely and replace it with some kind of emulation layer that keeps old code working (with a performance penalty) but doesn't leave a syscall instruction sitting at a fixed address.

Before doing that, glibc should stop using it in new code, at least on kernels that have a vDSO.
Comment 1 Andy Lutomirski 2011-05-27 15:04:46 UTC
As an added benefit of the vDSO over vsyscalls: things like UML can replace the vDSO if they want to.  This means that sched_getcpu and gettimeofday would have a better chance of returning the guest's answer (instead of the host's) on UML.
Comment 2 Ulrich Drepper 2011-05-28 12:13:32 UTC
I did add code to use the vdso in dynamically linked code.  But I don't change the static code.  Just go ahead, make the vsyscalls slow.  Noone should use statically linked code at all.  It's OK to be slower.