Skip to contentSkip to conversation

Updates to compat VDSOs

PATCH In review Jeremy Fitzhardinge 4 participants 14 messages Apr 5, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Updates to compat VDSOs

Hi Andi,

Here's a couple of patches to fix up COMPAT_VDSO:

The first is a straightforward implementation of Jan's original idea of relocating the VDSO to match its mapped location. Unlike Jan and Zach's version, I changed it to relocate based on the phdrs rather than the sections; the result is pleasantly compact.

The second patch takes advantage of the fact that all the COMPAT_VDSO work happens at runtime now, and allows compat mode to be enabled dynamically. If you specify vdso=2 on the kernel command line, it comes up in compat mode; vdso=1 is normal vdso mode, and vdso=0 disables vdso altogether. You can also switch modes with sysctl.

Thanks,
J

#1 lore raw

PATCH 1/2 Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

Some versions of libc can't deal with a VDSO which doesn't have its ELF headers matching its mapped address. COMPAT_VDSO maps the VDSO at a specific system-wide fixed address. Previously this was all done at build time, on the grounds that the fixed VDSO address is always at the top of the address space. However, a hypervisor may reserve some of that address space, pushing the fixmap address down.

This patch does the adjustment dynamically at runtime, depending on the runtime location of the VDSO fixmap.

[ Patch has been through several hands: Jan Beulich wrote the orignal
version; Zach reworked it, and Jeremy converted it to relocate phdrs rather than sections. ]

Cc Zachary Amsden <[email protected]>
Cc "Jan Beulich" <[email protected]>
Cc Eric W. Biederman <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Roland McGrath <[email protected]>
---
 arch/i386/kernel/entry.S    |    4 -
 arch/i386/kernel/sysenter.c |   95 ++++++++++++++++++++++++++++++++++++-------
 arch/i386/mm/pgtable.c      |    6 --
 include/asm-i386/elf.h      |   28 ++++--------
 include/asm-i386/fixmap.h   |    8 ---
 include/linux/elf.h         |    3 +
 6 files changed, 95 insertions(+), 49 deletions(-)

===================================================================

arch/i386/kernel/entry.S +0 -4
@@ -305,16 +305,12 @@ sysenter_past_esp:
 	pushl $(__USER_CS)
 	CFI_ADJUST_CFA_OFFSET 4
 	/*CFI_REL_OFFSET cs, 0*/
-#ifndef CONFIG_COMPAT_VDSO
 	/*
 	 * Push current_thread_info()->sysenter_return to the stack.
 	 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
 	 * pushed above; +8 corresponds to copy_thread's esp0 setting.
 	 */
 	pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
-#else
-	pushl $SYSENTER_RETURN
-#endif
 	CFI_ADJUST_CFA_OFFSET 4
 	CFI_REL_OFFSET eip, 0
 

===================================================================

arch/i386/kernel/sysenter.c +80 -15

125 lines not on this page · raw message

===================================================================

arch/i386/mm/pgtable.c +0 -6
@@ -144,10 +144,8 @@ void set_pmd_pfn(unsigned long vaddr, un
 }
 
 static int fixmaps;
-#ifndef CONFIG_COMPAT_VDSO
 unsigned long __FIXADDR_TOP = 0xfffff000;
 EXPORT_SYMBOL(__FIXADDR_TOP);
-#endif
 
 void __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t flags)
 {
@@ -173,12 +171,8 @@ void reserve_top_address(unsigned long r
 	BUG_ON(fixmaps > 0);
 	printk(KERN_INFO "Reserving virtual address space above 0x%08x\n",
 	       (int)-reserve);
-#ifdef CONFIG_COMPAT_VDSO
-	BUG_ON(reserve != 0);
-#else
 	__FIXADDR_TOP = -reserve - PAGE_SIZE;
 	__VMALLOC_RESERVE += reserve;
-#endif
 }
 
 pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)

===================================================================

include/asm-i386/elf.h +10 -18
@@ -133,39 +133,31 @@ extern int dump_task_extended_fpu (struc
 #define ELF_CORE_COPY_XFPREGS(tsk, elf_xfpregs) dump_task_extended_fpu(tsk, elf_xfpregs)
 
 #define VDSO_HIGH_BASE		(__fix_to_virt(FIX_VDSO))
-#define VDSO_BASE		((unsigned long)current->mm->context.vdso)
-
-#ifdef CONFIG_COMPAT_VDSO
-# define VDSO_COMPAT_BASE	VDSO_HIGH_BASE
-# define VDSO_PRELINK		VDSO_HIGH_BASE
-#else
-# define VDSO_COMPAT_BASE	VDSO_BASE
-# define VDSO_PRELINK		0
-#endif
+#define VDSO_CURRENT_BASE	((unsigned long)current->mm->context.vdso)
+#define VDSO_PRELINK		0
 
 #define VDSO_SYM(x) \
-		(VDSO_COMPAT_BASE + (unsigned long)(x) - VDSO_PRELINK)
+		(VDSO_CURRENT_BASE + (unsigned long)(x) - VDSO_PRELINK)
 
 #define VDSO_HIGH_EHDR		((const struct elfhdr *) VDSO_HIGH_BASE)
-#define VDSO_EHDR		((const struct elfhdr *) VDSO_COMPAT_BASE)
+#define VDSO_EHDR		((const struct elfhdr *) VDSO_CURRENT_BASE)
 
 extern void __kernel_vsyscall;
 
 #define VDSO_ENTRY		VDSO_SYM(&__kernel_vsyscall)
 
-#ifndef CONFIG_COMPAT_VDSO
+struct linux_binprm;
+
 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
-struct linux_binprm;
 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
                                        int executable_stack);
-#endif
 
 extern unsigned int vdso_enabled;
 
-#define ARCH_DLINFO						\
-do if (vdso_enabled) {						\
-		NEW_AUX_ENT(AT_SYSINFO,	VDSO_ENTRY);		\
-		NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_COMPAT_BASE);	\
+#define ARCH_DLINFO							\
+do if (vdso_enabled) {							\
+		NEW_AUX_ENT(AT_SYSINFO,	VDSO_ENTRY);			\
+		NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_CURRENT_BASE);	\
 } while (0)
 
 #endif

===================================================================

include/asm-i386/fixmap.h +2 -6
@@ -19,13 +19,9 @@
  * Leave one empty page between vmalloc'ed areas and
  * the start of the fixmap.
  */
-#ifndef CONFIG_COMPAT_VDSO
 extern unsigned long __FIXADDR_TOP;
-#else
-#define __FIXADDR_TOP  0xfffff000
-#define FIXADDR_USER_START	__fix_to_virt(FIX_VDSO)
-#define FIXADDR_USER_END	__fix_to_virt(FIX_VDSO - 1)
-#endif
+#define FIXADDR_USER_START     __fix_to_virt(FIX_VDSO)
+#define FIXADDR_USER_END       __fix_to_virt(FIX_VDSO - 1)
 
 #ifndef __ASSEMBLY__
 #include <linux/kernel.h>

===================================================================

include/linux/elf.h +3 -0
@@ -83,6 +83,9 @@ typedef __s64	Elf64_Sxword;
 #define DT_DEBUG	21
 #define DT_TEXTREL	22
 #define DT_JMPREL	23
+#define DT_VERSYM	0x6ffffff0
+#define DT_VERDEF	0x6ffffffc
+#define DT_VERNEED	0x6ffffffe
 #define DT_LOPROC	0x70000000
 #define DT_HIPROC	0x7fffffff
 
#2 lore raw

Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

The patch looks nice and clean. However, it does not relocate the symbol table(s) values. I thought that was done in an earlier version of this I saw, but I might be misremembering. Though not fatal, this is a regression from the previous CONFIG_COMPAT_VDSO behavior. It will show up in things like __kernel_* name display in backtraces. If with your other patch CONFIG_COMPAT_VDSO will become other than a rarely-used compatibility option, then this should be fixed. Note that with your second patch this will also break the symbol values in the randomly-located vma vdso; non-ancient glibc doesn't care if the vdso isn't mapped where its phdrs say, but everything does still care that the symbol tables in an ELF file use addresses matching the phdrs in the same file.

Thanks,
Roland

#3 lore raw

Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

Quoted 5 lines · Roland McGrath

The patch looks nice and clean. However, it does not relocate the symbol table(s) values. I thought that was done in an earlier version of this I saw, but I might be misremembering. Though not fatal, this is a regression from the previous CONFIG_COMPAT_VDSO behavior. It will show up in things like __kernel_* name display in backtraces.

Hm, OK. It does, but I wasn't sure if it would matter. It should be fairly simple to fix up.

Quoted 8 lines

If with your other patch
CONFIG_COMPAT_VDSO will become other than a rarely-used compatibility option, then this should be fixed. Note that with your second patch this will also break the symbol values in the randomly-located vma vdso; non-ancient glibc doesn't care if the vdso isn't mapped where its phdrs say, but everything does still care that the symbol tables in an ELF file use addresses matching the phdrs in the same file.

I did the second patch because I could, and to see if it would provoke some comment. But effectively removing a kernel config option seems like a good idea to me.

J

#4 lore raw

Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

Quoted 3 lines

I did the second patch because I could, and to see if it would provoke some comment. But effectively removing a kernel config option seems like a good idea to me.

Well, it provoked me to care whether the first patch the relocation "really right".

Thanks,
Roland

#5 lore raw

Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

In reply to Jeremy Fitzhardinge
Quoted 11 lines
arch/i386/kernel/sysenter.c +11 -0
+static __cpuinit void reloc_dyn(Elf32_Ehdr *ehdr, unsigned offset)
+{
+	Elf32_Dyn *dyn = (void *)ehdr + offset;
+
+	for(; dyn->d_tag != DT_NULL; dyn++)
+		switch(dyn->d_tag) {
+		case DT_PLTGOT:
+		case DT_HASH:
+		case DT_STRTAB:
+		case DT_SYMTAB:
+		case DT_RELA:

arch/i386/kernel/sysenter.c __setup("vdso=", vdso_setup); · line 67

Quoted 10 lines
arch/i386/kernel/sysenter.c +10 -0
+		case DT_INIT:
+		case DT_FINI:
+		case DT_REL:
+		case DT_JMPREL:
+		case DT_VERSYM:
+		case DT_VERDEF:
+		case DT_VERNEED:
+			dyn->d_un.d_val += VDSO_HIGH_BASE;
+		}
+}

While there's a certain level of control on what DT_* may appear in the vDSO, not even considering other than the above types seems fragile to me. Since future additions to the set are supposedly following a fixed scheme (distinguishing pointers and values via the low bit when below OLD_DT_LOOS, and using sub-ranges when between DT_HIOS and OLD_DT_HIOS), at least also handling those would seem like a good idea, as would warning about unrecognized types.

Also, even though it shouldn't matter for the final result, if doing things spec-conforming here you should use d_un.d_ptr.

In addition to Roland's remarks about missing symbol table relocation, I would also assume section headers, if present, should be relocated.

Jan

#6 lore raw

Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

Quoted 8 lines · Jan Beulich

While there's a certain level of control on what DT_* may appear in the vDSO, not even considering other than the above types seems fragile to me. Since future additions to the set are supposedly following a fixed scheme (distinguishing pointers and values via the low bit when below OLD_DT_LOOS, and using sub-ranges when between DT_HIOS and OLD_DT_HIOS), at least also handling those would seem like a good idea, as would warning about unrecognized types.

I wasn't aware of this scheme. Where is it documented?

Quoted 3 lines

Also, even though it shouldn't matter for the final result, if doing things spec-conforming here you should use d_un.d_ptr.

Yes, I've already fixed that.

Quoted 3 lines

In addition to Roland's remarks about missing symbol table relocation, I would also assume section headers, if present, should be relocated.

Yes, I suppose that's easy enough to add.

J

#7 lore raw

RE: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

Dear All,
In this few days, I got emails from this list. I tried to exclude thru majordomo, but it failed.
Kindly need your help to exclude me from this list.

Thank You,
CR

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jeremy Fitzhardinge
Sent: Thursday, April 05, 2007 2:32 PM
To: Jan Beulich
Cc: Ingo Molnar; Andrew Morton; [email protected]; Roland McGrath; Andi Kleen; lkml; Zachary Amsden; Eric W. Biederman
Subject: Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

Quoted 9 lines · Jan Beulich

While there's a certain level of control on what DT_* may appear in the vDSO, not even considering other than the above types seems fragile to me. Since future additions to the set are supposedly following a fixed scheme (distinguishing pointers and values via the low bit when below OLD_DT_LOOS, and using sub-ranges when between DT_HIOS and OLD_DT_HIOS), at least also handling those would seem like

a good idea, as would warning about unrecognized types.

I wasn't aware of this scheme. Where is it documented?

Quoted 3 lines

Also, even though it shouldn't matter for the final result, if doing things spec-conforming here you should use d_un.d_ptr.

Yes, I've already fixed that.

Quoted 4 lines

In addition to Roland's remarks about missing symbol table relocation,

I would also assume section headers, if present, should be relocated.

Yes, I suppose that's easy enough to add.

J
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#8 lore raw

Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

In reply to Jeremy Fitzhardinge
Quoted 11 lines
Quoted 1 line
Quoted 1 line

Jeremy Fitzhardinge <[email protected]> 05.04.07 09:31 >>>

Quoted 7 lines · Jan Beulich

While there's a certain level of control on what DT_* may appear in the vDSO, not even considering other than the above types seems fragile to me. Since future additions to the set are supposedly following a fixed scheme (distinguishing pointers and values via the low bit when below OLD_DT_LOOS, and using sub-ranges when between DT_HIOS and OLD_DT_HIOS), at least also handling those would seem like a good idea, as would warning about unrecognized types.

I wasn't aware of this scheme. Where is it documented?

Regarding the low bit part, quoting from working gABI chapter 5: "To make it simpler for tools to interpret the contents of dynamic section entries, the value of each tag, except for those in two special compatibility ranges, will determine the interpretation of the d_un union. A tag whose value is an even number indicates a dynamic section entry that uses d_ptr. A tag whose value is an odd number indicates a dynamic section entry that uses d_val or that uses neither d_ptr nor d_val. Tags whose values are less than the special value DT_ENCODING and tags whose values fall between DT_HIOS and DT_LOPROC do not follow these rules."

Regarding the OS range, all I can point you to is binutils' include/elf/common.h.

Jan

#9 lore raw

Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

In reply to Jan Beulich
Quoted 2 lines

In addition to Roland's remarks about missing symbol table relocation, I would also assume section headers, if present, should be relocated.

Yes, and also the .symtab as well as .dynsym just in case one ever has one (though I think they are built stripped now, it's not hard to check sh_type for SHT_SYMTAB and call the same routine that works from DT_SYMTAB).

Thanks,
Roland

#10 lore raw

Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

Quoted 8 lines · Roland McGrath
Quoted 3 lines

In addition to Roland's remarks about missing symbol table relocation, I would also assume section headers, if present, should be relocated.

Yes, and also the .symtab as well as .dynsym just in case one ever has one (though I think they are built stripped now, it's not hard to check sh_type for SHT_SYMTAB and call the same routine that works from DT_SYMTAB).

OK, how does this look? Does it need to worry about DT_REL/DT_RELA tags? (Not that there are any.)

J

Subject: Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

Some versions of libc can't deal with a VDSO which doesn't have its ELF headers matching its mapped address. COMPAT_VDSO maps the VDSO at a specific system-wide fixed address. Previously this was all done at build time, on the grounds that the fixed VDSO address is always at the top of the address space. However, a hypervisor may reserve some of that address space, pushing the fixmap address down.

This patch does the adjustment dynamically at runtime, depending on the runtime location of the VDSO fixmap.

[ Patch has been through several hands: Jan Beulich wrote the orignal
version; Zach reworked it, and Jeremy converted it to relocate phdrs rather than sections. ]

Cc Zachary Amsden <[email protected]>
Cc "Jan Beulich" <[email protected]>
Cc Eric W. Biederman <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Roland McGrath <[email protected]>
---
 arch/i386/kernel/entry.S    |    4 -
 arch/i386/kernel/sysenter.c |   95 ++++++++++++++++++++++++++++++++++++-------
 arch/i386/mm/pgtable.c      |    6 --
 include/asm-i386/elf.h      |   28 ++++--------
 include/asm-i386/fixmap.h   |    8 ---
 include/linux/elf.h         |    3 +
 6 files changed, 95 insertions(+), 49 deletions(-)
arch/i386/kernel/entry.S +0 -4
diff -r 97a792fb6127 arch/i386/kernel/entry.S
@@ -305,16 +305,12 @@ sysenter_past_esp:
 	pushl $(__USER_CS)
 	CFI_ADJUST_CFA_OFFSET 4
 	/*CFI_REL_OFFSET cs, 0*/
-#ifndef CONFIG_COMPAT_VDSO
 	/*
 	 * Push current_thread_info()->sysenter_return to the stack.
 	 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
 	 * pushed above; +8 corresponds to copy_thread's esp0 setting.
 	 */
 	pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
-#else
-	pushl $SYSENTER_RETURN
-#endif
 	CFI_ADJUST_CFA_OFFSET 4
 	CFI_REL_OFFSET eip, 0
 
arch/i386/kernel/sysenter.c +128 -15

173 lines not on this page · raw message

arch/i386/mm/pgtable.c +0 -6
diff -r 97a792fb6127 arch/i386/mm/pgtable.c
@@ -144,10 +144,8 @@ void set_pmd_pfn(unsigned long vaddr, un
 }
 
 static int fixmaps;
-#ifndef CONFIG_COMPAT_VDSO
 unsigned long __FIXADDR_TOP = 0xfffff000;
 EXPORT_SYMBOL(__FIXADDR_TOP);
-#endif
 
 void __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t flags)
 {
@@ -173,12 +171,8 @@ void reserve_top_address(unsigned long r
 	BUG_ON(fixmaps > 0);
 	printk(KERN_INFO "Reserving virtual address space above 0x%08x\n",
 	       (int)-reserve);
-#ifdef CONFIG_COMPAT_VDSO
-	BUG_ON(reserve != 0);
-#else
 	__FIXADDR_TOP = -reserve - PAGE_SIZE;
 	__VMALLOC_RESERVE += reserve;
-#endif
 }
 
 pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
include/asm-i386/elf.h +10 -18
diff -r 97a792fb6127 include/asm-i386/elf.h
@@ -133,39 +133,31 @@ extern int dump_task_extended_fpu (struc
 #define ELF_CORE_COPY_XFPREGS(tsk, elf_xfpregs) dump_task_extended_fpu(tsk, elf_xfpregs)
 
 #define VDSO_HIGH_BASE		(__fix_to_virt(FIX_VDSO))
-#define VDSO_BASE		((unsigned long)current->mm->context.vdso)
-
-#ifdef CONFIG_COMPAT_VDSO
-# define VDSO_COMPAT_BASE	VDSO_HIGH_BASE
-# define VDSO_PRELINK		VDSO_HIGH_BASE
-#else
-# define VDSO_COMPAT_BASE	VDSO_BASE
-# define VDSO_PRELINK		0
-#endif
+#define VDSO_CURRENT_BASE	((unsigned long)current->mm->context.vdso)
+#define VDSO_PRELINK		0
 
 #define VDSO_SYM(x) \
-		(VDSO_COMPAT_BASE + (unsigned long)(x) - VDSO_PRELINK)
+		(VDSO_CURRENT_BASE + (unsigned long)(x) - VDSO_PRELINK)
 
 #define VDSO_HIGH_EHDR		((const struct elfhdr *) VDSO_HIGH_BASE)
-#define VDSO_EHDR		((const struct elfhdr *) VDSO_COMPAT_BASE)
+#define VDSO_EHDR		((const struct elfhdr *) VDSO_CURRENT_BASE)
 
 extern void __kernel_vsyscall;
 
 #define VDSO_ENTRY		VDSO_SYM(&__kernel_vsyscall)
 
-#ifndef CONFIG_COMPAT_VDSO
+struct linux_binprm;
+
 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
-struct linux_binprm;
 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
                                        int executable_stack);
-#endif
 
 extern unsigned int vdso_enabled;
 
-#define ARCH_DLINFO						\
-do if (vdso_enabled) {						\
-		NEW_AUX_ENT(AT_SYSINFO,	VDSO_ENTRY);		\
-		NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_COMPAT_BASE);	\
+#define ARCH_DLINFO							\
+do if (vdso_enabled) {							\
+		NEW_AUX_ENT(AT_SYSINFO,	VDSO_ENTRY);			\
+		NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_CURRENT_BASE);	\
 } while (0)
 
 #endif
include/asm-i386/fixmap.h +2 -6
diff -r 97a792fb6127 include/asm-i386/fixmap.h
@@ -19,13 +19,9 @@
  * Leave one empty page between vmalloc'ed areas and
  * the start of the fixmap.
  */
-#ifndef CONFIG_COMPAT_VDSO
 extern unsigned long __FIXADDR_TOP;
-#else
-#define __FIXADDR_TOP  0xfffff000
-#define FIXADDR_USER_START	__fix_to_virt(FIX_VDSO)
-#define FIXADDR_USER_END	__fix_to_virt(FIX_VDSO - 1)
-#endif
+#define FIXADDR_USER_START     __fix_to_virt(FIX_VDSO)
+#define FIXADDR_USER_END       __fix_to_virt(FIX_VDSO - 1)
 
 #ifndef __ASSEMBLY__
 #include <linux/kernel.h>
include/linux/elf.h +6 -0
diff -r 97a792fb6127 include/linux/elf.h
@@ -83,6 +83,12 @@ typedef __s64	Elf64_Sxword;
 #define DT_DEBUG	21
 #define DT_TEXTREL	22
 #define DT_JMPREL	23
+#define DT_ENCODING	32
+#define DT_LOOS		0x6000000D
+#define DT_HIOS		0x6ffff000
+#define DT_VERSYM	0x6ffffff0
+#define DT_VERDEF	0x6ffffffc
+#define DT_VERNEED	0x6ffffffe
 #define DT_LOPROC	0x70000000
 #define DT_HIPROC	0x7fffffff
 
#11 lore raw

Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

Quoted 14 lines
arch/i386/kernel/sysenter.c +14 -0
+	for(; dyn->d_tag != DT_NULL; dyn++)
+		switch(dyn->d_tag) {
+		case DT_PLTGOT:
+		case DT_HASH:
+		case DT_STRTAB:
+		case DT_SYMTAB:
+		case DT_RELA:
+		case DT_INIT:
+		case DT_FINI:
+		case DT_REL:
+		case DT_DEBUG:
+		case DT_JMPREL:
+		case DT_VERSYM:
+		case DT_VERDEF:

arch/i386/kernel/sysenter.c __setup("vdso=", vdso_setup); · line 100

Quoted 10 lines
arch/i386/kernel/sysenter.c +10 -0
+		case DT_VERNEED:
+		case DT_ENCODING ... DT_HIOS:
+			/* tags above DT_ENCODING are even if they're
+			   a pointer, so skip odd ones */
+			if (dyn->d_tag >= DT_ENCODING &&
+			    (dyn->d_tag & 1) == 1)
+				break;
+
+			dyn->d_un.d_ptr += VDSO_HIGH_BASE;
+		}

I'm pretty certain the range OLD_DT_LOOS ... DT_LOOS must be excluded here (the document version I'm looking at is inconsistent in itself here, saying in one place to stop at DT_LOOS, in a second to stop at DT_HIOS, and in a third to include DT_LOOS ... ST_HIOS - the inconsistency goes away if assuming that the stop at DT_LOOS really means stop at OLD_DT_LOOS, and the stop at DT_HIOS misses to special-case the OLD_DT_LOOS ... DT_LOOS range.
Additionally I'm a little worried about excluding DT_ADDRRNGLO ... DT_ADDRRNGHI in case future binutils ever start defaulting to generate any of these (namely DT_GNU_HASH).

Quoted 1 line

+#define DT_ENCODING 32

Hmm, I was about to say this ought to be 31 when I realized the discrepancy between document and binutils. I'll have to ask about this...

Jan

#12 lore raw

Re: [patch 1/2] Relocate VDSO ELF headers to match mapped location with COMPAT_VDSO

In reply to Jeremy Fitzhardinge

Don't change sh_addr in sections with (sh_flags & SHF_ALLOC) == 0. Also, I'd concur with Jan's suggestion about paranoia warnings for unexpected DT_* types (and for unexpected st_shndx >= SHN_LORESERVE).

Otherwise, looks ok to me.

Thanks,
Roland

#13 lore raw

PATCH 2/2 Make COMPAT_VDSO runtime selectable.

In reply to Jeremy Fitzhardinge

Now that relocation of the VDSO for COMPAT_VDSO users is done at runtime rather than compile time, it is possible to enable/disable compat mode at runtime.

This patch allows you to enable COMPAT_VDSO mode with "vdso=2" on the kernel command line, or via sysctl.

The COMPAT_VDSO config option still exists, but if enabled it just makes vdso_enabled default to VDSO_COMPAT.

Cc Zachary Amsden <[email protected]>
Cc "Jan Beulich" <[email protected]>
Cc Eric W. Biederman <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Roland McGrath <[email protected]>
---
 Documentation/kernel-parameters.txt |    1 
 arch/i386/kernel/sysenter.c         |  131 ++++++++++++++++++++++-------------
 include/asm-i386/page.h             |    2 
 3 files changed, 84 insertions(+), 50 deletions(-)

===================================================================

Documentation/kernel-parameters.txt +1 -0
@@ -1807,6 +1807,7 @@ and is between 256 and 4096 characters. 
 			[USBHID] The interval which mice are to be polled at.
 
 	vdso=		[IA-32,SH]
+			vdso=2: enable compat VDSO (default with COMPAT_VDSO)
 			vdso=1: enable VDSO (default)
 			vdso=0: disable VDSO mapping
 

===================================================================

arch/i386/kernel/sysenter.c +83 -48

197 lines not on this page · raw message

===================================================================

include/asm-i386/page.h +0 -2
@@ -143,9 +143,7 @@ extern int page_is_ram(unsigned long pag
 #include <asm-generic/memory_model.h>
 #include <asm-generic/page.h>
 
-#ifndef CONFIG_COMPAT_VDSO
 #define __HAVE_ARCH_GATE_AREA 1
-#endif
 #endif /* __KERNEL__ */
 
 #endif /* _I386_PAGE_H */