Skip to contentSkip to conversation

x86_64,vsyscall: Minor cleanups and fixes

PATCH New Andy Lutomirski 1 participant 4 messages May 22, 2014

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

cover x86_64,vsyscall: Minor cleanups and fixes

This turns the vsyscall page all the way off in vsyscall=none mode and fixes a bug in warn_bad_vsyscall that resulted in corrupt log lines.

With this series applied, vsyscall=none results in a tidier /proc/PID/maps.

Andy Lutomirski (3):
x86_64,vsyscall: Move all of the gate_area code to vsyscall_64.c x86_64,vsyscall: Turn vsyscalls all the way off when vsyscall=none x86_64,vsyscall: Fix warn_bad_vsyscall log output

 arch/x86/kernel/vsyscall_64.c | 69 ++++++++++++++++++++++++++++++++++++++-----
 arch/x86/mm/init_64.c         | 49 ------------------------------
 2 files changed, 61 insertions(+), 57 deletions(-)
Signature · 1 line
1.9.0
#1 lore raw

PATCH 1/3 x86_64,vsyscall: Move all of the gate_area code to vsyscall_64.c

This code exists for the sole purpose of making the vsyscall page look sort of like real userspace memory. Move it so that it lives with the rest of the vsyscall code.

---
 arch/x86/kernel/vsyscall_64.c | 49 +++++++++++++++++++++++++++++++++++++++++++
 arch/x86/mm/init_64.c         | 49 -------------------------------------------
 2 files changed, 49 insertions(+), 49 deletions(-)
arch/x86/kernel/vsyscall_64.c +49 -0
index ea5b570..ad84894 100644
@@ -284,6 +284,55 @@ sigsegv:
 }
 
 /*
+ * A pseudo VMA to allow ptrace access for the vsyscall page.  This only
+ * covers the 64bit vsyscall page now. 32bit has a real VMA now and does
+ * not need special handling anymore:
+ */
+static const char *gate_vma_name(struct vm_area_struct *vma)
+{
+	return "[vsyscall]";
+}
+static struct vm_operations_struct gate_vma_ops = {
+	.name = gate_vma_name,
+};
+static struct vm_area_struct gate_vma = {
+	.vm_start	= VSYSCALL_ADDR,
+	.vm_end		= VSYSCALL_ADDR + PAGE_SIZE,
+	.vm_page_prot	= PAGE_READONLY_EXEC,
+	.vm_flags	= VM_READ | VM_EXEC,
+	.vm_ops		= &gate_vma_ops,
+};
+
+struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
+{
+#ifdef CONFIG_IA32_EMULATION
+	if (!mm || mm->context.ia32_compat)
+		return NULL;
+#endif
+	return &gate_vma;
+}
+
+int in_gate_area(struct mm_struct *mm, unsigned long addr)
+{
+	struct vm_area_struct *vma = get_gate_vma(mm);
+
+	if (!vma)
+		return 0;
+
+	return (addr >= vma->vm_start) && (addr < vma->vm_end);
+}
+
+/*
+ * Use this when you have no reliable mm, typically from interrupt
+ * context. It is less reliable than using a task's mm and may give
+ * false positives.
+ */
+int in_gate_area_no_mm(unsigned long addr)
+{
+	return (addr & PAGE_MASK) == VSYSCALL_ADDR;
+}
+
+/*
  * Assume __initcall executes before all user space. Hopefully kmod
  * doesn't violate that. We'll find out if it does.
  */
arch/x86/mm/init_64.c +0 -49

55 lines not on this page · raw message

Signature · 1 line
1.9.0
#2 lore raw

PATCH 2/3 x86_64,vsyscall: Turn vsyscalls all the way off when vsyscall=none

In reply to Andy Lutomirski

I see no point in having an unusable read-only page sitting at 0xffffffffff600000 when vsyscall=none. Instead, skip mapping it and remove it from /proc/PID/maps.

I kept the ratelimited warning when programs try to use a vsyscall in this mode, since it may help admins avoid confusion.

---
 arch/x86/kernel/vsyscall_64.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
arch/x86/kernel/vsyscall_64.c +9 -5
index ad84894..8d38eb5 100644
@@ -309,6 +309,8 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
 	if (!mm || mm->context.ia32_compat)
 		return NULL;
 #endif
+	if (vsyscall_mode == NONE)
+		return NULL;
 	return &gate_vma;
 }
 
@@ -329,7 +331,7 @@ int in_gate_area(struct mm_struct *mm, unsigned long addr)
  */
 int in_gate_area_no_mm(unsigned long addr)
 {
-	return (addr & PAGE_MASK) == VSYSCALL_ADDR;
+	return vsyscall_mode != NONE && (addr & PAGE_MASK) == VSYSCALL_ADDR;
 }
 
 /*
@@ -380,10 +382,12 @@ void __init map_vsyscall(void)
 	extern char __vsyscall_page;
 	unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
 
-	__set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
-		     vsyscall_mode == NATIVE
-		     ? PAGE_KERNEL_VSYSCALL
-		     : PAGE_KERNEL_VVAR);
+	if (vsyscall_mode != NONE)
+		__set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
+			     vsyscall_mode == NATIVE
+			     ? PAGE_KERNEL_VSYSCALL
+			     : PAGE_KERNEL_VVAR);
+
 	BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
 		     (unsigned long)VSYSCALL_ADDR);
 }
Signature · 1 line
1.9.0
#3 lore raw

PATCH 3/3 x86_64,vsyscall: Fix warn_bad_vsyscall log output

In reply to Andy Lutomirski

This commit:

commit c767a54ba0657e52e6edaa97cbe0b0a8bf1c1655
Author: Joe Perches <[email protected]>
Date: Mon May 21 19:50:07 2012 -0700

x86/debug: Add KERN_<LEVEL> to bare printks, convert printks to pr_<level>

caused warn_bad_vsyscall to output garbage in the middle of the line. Revert the bad part of it.

The printk in question isn't actually bare; the level is "%s".

---
 arch/x86/kernel/vsyscall_64.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/vsyscall_64.c +4 -4
index 8d38eb5..6463f9e 100644
@@ -81,10 +81,10 @@ static void warn_bad_vsyscall(const char *level, struct pt_regs *regs,
 	if (!show_unhandled_signals)
 		return;
 
-	pr_notice_ratelimited("%s%s[%d] %s ip:%lx cs:%lx sp:%lx ax:%lx si:%lx di:%lx\n",
-			      level, current->comm, task_pid_nr(current),
-			      message, regs->ip, regs->cs,
-			      regs->sp, regs->ax, regs->si, regs->di);
+	printk_ratelimited("%s%s[%d] %s ip:%lx cs:%lx sp:%lx ax:%lx si:%lx di:%lx\n",
+			   level, current->comm, task_pid_nr(current),
+			   message, regs->ip, regs->cs,
+			   regs->sp, regs->ax, regs->si, regs->di);
 }
 
 static int addr_to_vsyscall_nr(unsigned long addr)
Signature · 1 line
1.9.0