From: Jan Kiszka <jan.kiszka@web.de>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@zip.com.au>,
Thomas Gleixner <tglx@linutronix.de>,
Jason Wessel <jason.wessel@windriver.com>
Subject: Re: [2/6] uaccess: add probe_kernel_write()
Date: Sun, 10 Feb 2008 19:53:50 +0100 [thread overview]
Message-ID: <47AF483E.2060202@web.de> (raw)
In-Reply-To: <20080210071326.GB3851@elte.hu>
Ingo Molnar wrote:
> From: Ingo Molnar <mingo@elte.hu>
>
> add probe_kernel_write() - copy & paste of the existing
> probe_kernel_access(), extended to writes.
Along Linus' suggestion to work on larger chunks in kgdb, here are
improved probe_kernel_read/write helpers that take a size argument.
I'm leaving the original probe_kernel_read as is for now, but maybe it
can be converted to probe_kernel_read (I don't want to dive into this as
well :) ).
Signed-off-by: Jan Kiszka <jan.kiszka@web.de>
---
uaccess.h | 38 +++++++++++++++++++++++++++++++-------
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 98cfe02..ef75869 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -85,25 +85,49 @@ static inline unsigned long __copy_from_user_nocache(void *to,
})
/**
+ * probe_kernel_read(): safely attempt to read from a location
+ * @dst: pointer to the buffer that shall take the data
+ * @src: address to read from
+ * @size: size of the data chunk
+ *
+ * Safely read from address @src to the buffer at @dst. If a kernel fault
+ * happens, handle that and return -EFAULT.
+ */
+#define probe_kernel_read(dst, src, size) \
+ ({ \
+ long ret; \
+ mm_segment_t old_fs = get_fs(); \
+ \
+ set_fs(KERNEL_DS); \
+ pagefault_disable(); \
+ ret = __copy_from_user_inatomic((dst), \
+ (__force const void __user *)(src), (size)); \
+ pagefault_enable(); \
+ set_fs(old_fs); \
+ ret ? -EFAULT : 0; \
+ })
+
+/**
* 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
+ * @dst: address to write to
+ * @src: pointer to the data that shall be written
+ * @size: size of the data chunk
*
- * Safely write to address @addr from variable @rdval. If a kernel fault
+ * Safely write to address @dst from the buffer at @src. If a kernel fault
* happens, handle that and return -EFAULT.
*/
-#define probe_kernel_write(addr, rdval) \
+#define probe_kernel_write(dst, src, size) \
({ \
long ret; \
mm_segment_t old_fs = get_fs(); \
\
set_fs(KERNEL_DS); \
pagefault_disable(); \
- ret = __put_user(rdval, \
- (__force typeof(rdval) __user *)(addr)); \
+ ret = __copy_to_user_inatomic( \
+ (__force void __user *)(dst), (src), (size)); \
pagefault_enable(); \
set_fs(old_fs); \
- ret; \
+ ret ? -EFAULT : 0; \
})
#endif /* __LINUX_UACCESS_H__ */
next prev parent reply other threads:[~2008-02-10 18:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-10 7:13 [2/6] uaccess: add probe_kernel_write() Ingo Molnar
2008-02-10 18:53 ` Jan Kiszka [this message]
2008-02-10 19:12 ` Linus Torvalds
2008-02-10 20:05 ` Ingo Molnar
2008-02-11 16:46 ` Randy Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47AF483E.2060202@web.de \
--to=jan.kiszka@web.de \
--cc=akpm@zip.com.au \
--cc=jason.wessel@windriver.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.