lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 29 Aug 2008 16:16:12 -0700 (PDT)
From:	Steve VanDeBogart <vandebo-lkml@...dBox.Net>
To:	linux-kernel@...r.kernel.org,
	user-mode-linux-devel@...ts.sourceforge.net, jiayingz@...gle.com,
	dkegel@...gle.com
Subject: [PATCH 3/6] UML and sched: Annotate stacks

Track and tell valgrind about kernel mode stacks.  Valgrind gets confused
without these annotations because it expects processes to only use their
initial stack and stacks created for threads by way of clone.

Signed-off-by: Steve VanDeBogart <vandebo-lkml@...dbox.net>
---

Index: linux-2.6.27-rc5/arch/um/kernel/process.c
===================================================================
--- linux-2.6.27-rc5.orig/arch/um/kernel/process.c	2008-08-29 14:17:31.000000000 -0700
+++ linux-2.6.27-rc5/arch/um/kernel/process.c	2008-08-29 14:41:34.000000000 -0700
@@ -16,6 +16,7 @@
  #include <linux/sched.h>
  #include <linux/tick.h>
  #include <linux/threads.h>
+#include <linux/valgrind.h>
  #include <asm/current.h>
  #include <asm/pgtable.h>
  #include <asm/uaccess.h>
@@ -62,10 +63,40 @@
  	if (atomic)
  		flags = GFP_ATOMIC;
  	page = __get_free_pages(flags, order);
+	/* There are long lived stacks and we won't free them */
+	if (page)
+		VALGRIND_STACK_REGISTER(page + (PAGE_SIZE << order) - 1, page);

  	return page;
  }

+struct thread_info *alloc_thread_info(struct task_struct *tsk)
+{
+	struct thread_info *ti;
+#ifdef CONFIG_DEBUG_STACK_USAGE
+	gfp_t mask = GFP_KERNEL | __GFP_ZERO;
+#else
+	gfp_t mask = GFP_KERNEL;
+#endif
+	ti = (struct thread_info *) __get_free_pages(mask,
+						CONFIG_KERNEL_STACK_ORDER);
+#ifdef CONFIG_VALGRIND_SUPPORT
+	if (ti) {
+		VALGRIND_MALLOCLIKE_BLOCK(ti, sizeof(*ti), 0, 0);
+		ti->valgrind_sid = VALGRIND_STACK_REGISTER((unsigned long)ti
+						+ UM_THREAD_SIZE - 1, ti + 1);
+	}
+#endif
+	return ti;
+}
+
+void free_thread_info(struct thread_info *ti)
+{
+	VALGRIND_STACK_DEREGISTER(ti->valgrind_sid);
+	VALGRIND_FREELIKE_BLOCK(ti, 0);
+	free_pages((unsigned long)ti, CONFIG_KERNEL_STACK_ORDER);
+}
+
  int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  {
  	int pid;
Index: linux-2.6.27-rc5/arch/um/kernel/skas/process.c
===================================================================
--- linux-2.6.27-rc5.orig/arch/um/kernel/skas/process.c	2008-07-13 14:51:29.000000000 -0700
+++ linux-2.6.27-rc5/arch/um/kernel/skas/process.c	2008-08-29 14:32:45.000000000 -0700
@@ -5,6 +5,7 @@

  #include "linux/init.h"
  #include "linux/sched.h"
+#include "linux/valgrind.h"
  #include "as-layout.h"
  #include "kern.h"
  #include "os.h"
@@ -65,6 +66,8 @@
  	}

  	init_new_thread_signals();
+	VALGRIND_STACK_REGISTER((unsigned long)(&init_stack + 1) - 1,
+				&init_thread_info + 1);

  	init_task.thread.request.u.thread.proc = start_kernel_proc;
  	init_task.thread.request.u.thread.arg = NULL;
Index: linux-2.6.27-rc5/include/asm-um/thread_info.h
===================================================================
--- linux-2.6.27-rc5.orig/include/asm-um/thread_info.h	2008-08-29 14:17:37.000000000 -0700
+++ linux-2.6.27-rc5/include/asm-um/thread_info.h	2008-08-29 14:46:02.000000000 -0700
@@ -24,6 +24,9 @@
  						   0-0xFFFFFFFF for kernel */
  	struct restart_block    restart_block;
  	struct thread_info	*real_thread;    /* Points to non-IRQ stack */
+#ifdef CONFIG_VALGRIND_SUPPORT
+	unsigned int valgrind_sid;
+#endif
  };

  #define INIT_THREAD_INFO(tsk)			\
@@ -55,6 +58,11 @@

  #define THREAD_SIZE_ORDER CONFIG_KERNEL_STACK_ORDER

+#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
+
+extern struct thread_info *alloc_thread_info(struct task_struct *tsk);
+extern void free_thread_info(struct thread_info *ti);
+
  #endif

  #define PREEMPT_ACTIVE		0x10000000
Index: linux-2.6.27-rc5/include/linux/sched.h
===================================================================
--- linux-2.6.27-rc5.orig/include/linux/sched.h	2008-08-29 14:17:38.000000000 -0700
+++ linux-2.6.27-rc5/include/linux/sched.h	2008-08-29 14:32:45.000000000 -0700
@@ -1947,8 +1947,14 @@

  static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
  {
+#ifdef CONIG_VALGRIND_SUPPORT
+	unsigned int valgrind_sid = task_thread_info(p)->valgrind_sid;
+#endif
  	*task_thread_info(p) = *task_thread_info(org);
  	task_thread_info(p)->task = p;
+#ifdef CONIG_VALGRIND_SUPPORT
+	task_thread_info(p)->valgrind_sid = valgrind_sid;
+#endif
  }

  static inline unsigned long *end_of_stack(struct task_struct *p)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ