
There's a fair amount of code in the vsyscall page. It contains a syscall instruction (in the gettimeofday fallback) and who knows what will happen if an exploit jumps into the middle of some other code. Reduce the risk by replacing the vsyscalls with short magic incantations that cause the kernel to emulate the real vsyscalls. These incantations are useless if entered in the middle. This causes vsyscalls to be a little more expensive than real syscalls. Fortunately sensible programs don't use them. The only exception is time() which is still called by glibc through the vsyscall - but calling time() millions of times per second is not sensible. glibc has this fixed in the development tree. This patch is not perfect: the vread_tsc and vread_hpet functions are still at a fixed address. Fixing that might involve making alternative patching work in the vDSO. Signed-off-by: Andy Lutomirski <luto@mit.edu> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Jesper Juhl <jj@chaosbits.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Arjan van de Ven <arjan@infradead.org> Cc: Jan Beulich <JBeulich@novell.com> Cc: richard -rw- weinberger <richard.weinberger@gmail.com> Cc: Mikael Pettersson <mikpe@it.uu.se> Cc: Andi Kleen <andi@firstfloor.org> Cc: Brian Gerst <brgerst@gmail.com> Cc: Louis Rilling <Louis.Rilling@kerlabs.com> Cc: Valdis.Kletnieks@vt.edu Cc: pageexec@freemail.hu Link: http://lkml.kernel.org/r/e64e1b3c64858820d12c48fa739efbd1485e79d5.1307292171.git.luto@mit.edu [ Removed the CONFIG option - it's simpler to just do it unconditionally. Tidied up the code as well. ] Signed-off-by: Ingo Molnar <mingo@elte.hu>
49 lines
996 B
C
49 lines
996 B
C
#ifndef _ASM_X86_VSYSCALL_H
|
|
#define _ASM_X86_VSYSCALL_H
|
|
|
|
enum vsyscall_num {
|
|
__NR_vgettimeofday,
|
|
__NR_vtime,
|
|
__NR_vgetcpu,
|
|
};
|
|
|
|
#define VSYSCALL_START (-10UL << 20)
|
|
#define VSYSCALL_SIZE 1024
|
|
#define VSYSCALL_END (-2UL << 20)
|
|
#define VSYSCALL_MAPPED_PAGES 1
|
|
#define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
|
|
|
|
#ifdef __KERNEL__
|
|
#include <linux/seqlock.h>
|
|
|
|
/* Definitions for CONFIG_GENERIC_TIME definitions */
|
|
#define __vsyscall_fn \
|
|
__attribute__ ((unused, __section__(".vsyscall_fn"))) notrace
|
|
|
|
#define VGETCPU_RDTSCP 1
|
|
#define VGETCPU_LSL 2
|
|
|
|
/* kernel space (writeable) */
|
|
extern int vgetcpu_mode;
|
|
extern struct timezone sys_tz;
|
|
|
|
#include <asm/vvar.h>
|
|
|
|
extern void map_vsyscall(void);
|
|
|
|
/* Emulation */
|
|
|
|
static inline bool is_vsyscall_entry(unsigned long addr)
|
|
{
|
|
return (addr & ~0xC00UL) == VSYSCALL_START;
|
|
}
|
|
|
|
static inline int vsyscall_entry_nr(unsigned long addr)
|
|
{
|
|
return (addr & 0xC00UL) >> 10;
|
|
}
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
#endif /* _ASM_X86_VSYSCALL_H */
|