[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20080210071326.GB3851@elte.hu>
Date: Sun, 10 Feb 2008 08:13:26 +0100
From: Ingo Molnar <mingo@...e.hu>
To: linux-kernel@...r.kernel.org
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Andrew Morton <akpm@....com.au>,
Thomas Gleixner <tglx@...utronix.de>,
Jason Wessel <jason.wessel@...driver.com>
Subject: [2/6] uaccess: add probe_kernel_write()
From: Ingo Molnar <mingo@...e.hu>
add probe_kernel_write() - copy & paste of the existing
probe_kernel_access(), extended to writes.
Signed-off-by: Ingo Molnar <mingo@...e.hu>
Reviewed-by: Thomas Gleixner <tglx@...utronix.de>
---
include/linux/uaccess.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
Index: linux-kgdb.q/include/linux/uaccess.h
===================================================================
--- linux-kgdb.q.orig/include/linux/uaccess.h
+++ linux-kgdb.q/include/linux/uaccess.h
@@ -84,4 +84,26 @@ static inline unsigned long __copy_from_
ret; \
})
+/**
+ * probe_kernel_write(): safely attempt to write to a location
+ * @addr: address to write to - its type is type typeof(rdval)*
+ * @rdval: write to this variable
+ *
+ * Safely write to address @addr from variable @rdval. If a kernel fault
+ * happens, handle that and return -EFAULT.
+ */
+#define probe_kernel_write(addr, rdval) \
+ ({ \
+ long ret; \
+ mm_segment_t old_fs = get_fs(); \
+ \
+ set_fs(KERNEL_DS); \
+ pagefault_disable(); \
+ ret = __put_user(rdval, \
+ (__force typeof(rdval) __user *)(addr)); \
+ pagefault_enable(); \
+ set_fs(old_fs); \
+ ret; \
+ })
+
#endif /* __LINUX_UACCESS_H__ */
--
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