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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 20 Jul 2009 13:08:05 -0400
From:	Frederic Weisbecker <fweisbec@...il.com>
To:	Ingo Molnar <mingo@...e.hu>
Cc:	LKML <linux-kernel@...r.kernel.org>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Steven Rostedt <rostedt@...dmis.org>,
	Thomas Gleixner <tglx@...uxtronix.de>,
	Mike Galbraith <efault@....de>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Paul Mackerras <paulus@...ba.org>,
	Arnaldo Carvalho de Melo <acme@...hat.com>,
	Lai Jiangshan <laijs@...fujitsu.com>,
	Anton Blanchard <anton@...ba.org>,
	Li Zefan <lizf@...fujitsu.com>,
	Zhaolei <zhaolei@...fujitsu.com>,
	KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>,
	Mathieu Desnoyers <mathieu.desnoyers@...ymtl.ca>,
	"K . Prasad" <prasad@...ux.vnet.ibm.com>,
	Alan Stern <stern@...land.harvard.edu>
Subject: [RFC][PATCH 3/5] hw-breakpoints: Make user breakpoints API truly generic

Following the API changes on the kernel breakpoints API,
the user breakpoints registration now follows the same pattern.

The target, access length and type and now given as parameters
in the registration helpers to avoid per arch code in generic code.

However, to keep registering or modifying easily a user breakpoint
from arch code with a prefilled arch breakpoint structure, we provide
two new helpers:

- register_user_hw_breakpoint_filled(tsk, bp)
- modify_user_hw_breakpoint_filled(tsk, bp)

Signed-off-by: Frederic Weisbecker <fweisbec@...il.com>
Cc: K.Prasad <prasad@...ux.vnet.ibm.com>
Cc: Alan Stern <stern@...land.harvard.edu>
---
 arch/x86/kernel/ptrace.c            |   21 ++++++-----
 include/asm-generic/hw_breakpoint.h |   12 +++++-
 kernel/hw_breakpoint.c              |   65 +++++++++++++++++++++++++++++-----
 3 files changed, 76 insertions(+), 22 deletions(-)

diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index cabdabc..ef0eb10 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -525,17 +525,18 @@ restore:
 		if (!bp) {
 			rc = -ENOMEM;
 			bp = kzalloc(sizeof(struct hw_breakpoint), GFP_KERNEL);
-			if (bp) {
-				bp->info.address = thread->debugreg[i];
-				bp->triggered = ptrace_triggered;
-				bp->info.len = len;
-				bp->info.type = type;
-				rc = register_user_hw_breakpoint(tsk, bp);
-				if (rc)
-					kfree(bp);
-			}
+			if (!bp)
+				break;
+
+			bp->info.address = thread->debugreg[i];
+			bp->triggered = ptrace_triggered;
+			bp->info.len = len;
+			bp->info.type = type;
+			rc = register_user_hw_breakpoint_filled(tsk, bp);
+			if (rc)
+				kfree(bp);
 		} else
-			rc = modify_user_hw_breakpoint(tsk, bp);
+			rc = modify_user_hw_breakpoint_filled(tsk, bp);
 		if (rc)
 			break;
 	}
diff --git a/include/asm-generic/hw_breakpoint.h b/include/asm-generic/hw_breakpoint.h
index 300fe4c..598e3c4 100644
--- a/include/asm-generic/hw_breakpoint.h
+++ b/include/asm-generic/hw_breakpoint.h
@@ -83,10 +83,18 @@ struct hw_breakpoint {
  * 1-, 2-, and 4-byte lengths may be unavailable.
  */
 
+extern int register_user_hw_breakpoint_filled(struct task_struct *tsk,
+					      struct hw_breakpoint *bp);
 extern int register_user_hw_breakpoint(struct task_struct *tsk,
-					struct hw_breakpoint *bp);
+				       struct hw_breakpoint *bp,
+				       unsigned long addr, int len,
+				       enum breakpoint_type type);
+extern int modify_user_hw_breakpoint_filled(struct task_struct *tsk,
+					    struct hw_breakpoint *bp);
 extern int modify_user_hw_breakpoint(struct task_struct *tsk,
-					struct hw_breakpoint *bp);
+				     struct hw_breakpoint *bp,
+				     unsigned long addr,
+				     int len, enum breakpoint_type type);
 extern void unregister_user_hw_breakpoint(struct task_struct *tsk,
 						struct hw_breakpoint *bp);
 /*
diff --git a/kernel/hw_breakpoint.c b/kernel/hw_breakpoint.c
index 0301245..f9e62e7 100644
--- a/kernel/hw_breakpoint.c
+++ b/kernel/hw_breakpoint.c
@@ -211,16 +211,14 @@ static void __unregister_user_hw_breakpoint(int pos, struct task_struct *tsk)
 }
 
 /**
- * register_user_hw_breakpoint - register a hardware breakpoint for user space
+ * register_user_hw_breakpoint_filled - register a filled hardware breakpoint
+ * for user space.
  * @tsk: pointer to 'task_struct' of the process to which the address belongs
  * @bp: the breakpoint structure to register
- *
- * @bp.info->name or @bp.info->address, @bp.info->len, @bp.info->type and
  * @bp->triggered must be set properly before invocation
- *
  */
-int register_user_hw_breakpoint(struct task_struct *tsk,
-					struct hw_breakpoint *bp)
+int register_user_hw_breakpoint_filled(struct task_struct *tsk,
+				       struct hw_breakpoint *bp)
 {
 	struct thread_struct *thread = &(tsk->thread);
 	int i, rc = -ENOSPC;
@@ -246,15 +244,40 @@ int register_user_hw_breakpoint(struct task_struct *tsk,
 	spin_unlock_bh(&hw_breakpoint_lock);
 	return rc;
 }
+EXPORT_SYMBOL_GPL(register_user_hw_breakpoint_filled);
+
+/**
+ * register_user_hw_breakpoint - register a filled hardware breakpoint
+ * for user space.
+ * @tsk: pointer to 'task_struct' of the process to which the address belongs
+ * @bp: the breakpoint structure to register
+ * @addr: target of the breakpoint
+ * @len: length of the memory target access
+ * @type: type of the breakpoint (read-write/read/write/execute)
+ * @bp->triggered must be set properly before invocation
+ */
+int register_user_hw_breakpoint(struct task_struct *tsk,
+				struct hw_breakpoint *bp,
+				unsigned long addr,
+				int len, enum breakpoint_type type)
+{
+	int ret;
+
+	ret = arch_fill_hw_breakpoint(bp, addr, len, type);
+	if (ret)
+		return ret;
+
+	return register_user_hw_breakpoint_filled(tsk, bp);
+}
 EXPORT_SYMBOL_GPL(register_user_hw_breakpoint);
 
 /**
- * modify_user_hw_breakpoint - modify a user-space hardware breakpoint
+ * modify_user_hw_breakpoint_filled - modify a filled user-space hardware breakpoint
  * @tsk: pointer to 'task_struct' of the process to which the address belongs
- * @bp: the breakpoint structure to unregister
- *
+ * @bp: the breakpoint structure to update
  */
-int modify_user_hw_breakpoint(struct task_struct *tsk, struct hw_breakpoint *bp)
+int modify_user_hw_breakpoint_filled(struct task_struct *tsk,
+				     struct hw_breakpoint *bp)
 {
 	struct thread_struct *thread = &(tsk->thread);
 	int i, ret = -ENOENT;
@@ -269,6 +292,28 @@ int modify_user_hw_breakpoint(struct task_struct *tsk, struct hw_breakpoint *bp)
 	spin_unlock_bh(&hw_breakpoint_lock);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(modify_user_hw_breakpoint_filled);
+
+/**
+ * modify_user_hw_breakpoint - modify a user-space hardware breakpoint
+ * @tsk: pointer to 'task_struct' of the process to which the address belongs
+ * @bp: the breakpoint structure to update
+ * @addr: target of the breakpoint
+ * @len: length of the memory target access
+ * @type: type of the breakpoint (read-write/read/write/execute)
+ */
+int modify_user_hw_breakpoint(struct task_struct *tsk, struct hw_breakpoint *bp,
+			      unsigned long addr, int len,
+			      enum breakpoint_type type)
+{
+	int ret;
+
+	ret = arch_fill_hw_breakpoint(bp, addr, len, type);
+	if (ret)
+		return ret;
+
+	return register_user_hw_breakpoint_filled(tsk, bp);
+}
 EXPORT_SYMBOL_GPL(modify_user_hw_breakpoint);
 
 /**
-- 
1.6.2.3

--
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