[PATCH] probe_kernel_address() needs to do set_fs()
authorAndrew Morton <akpm@osdl.org>
Thu, 7 Dec 2006 04:36:40 +0000 (20:36 -0800)
committerLinus Torvalds <torvalds@woody.osdl.org>
Thu, 7 Dec 2006 16:39:34 +0000 (08:39 -0800)
probe_kernel_address() purports to be generic, only it forgot to select
KERNEL_DS, so it presently won't work right on all architectures.

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/linux/uaccess.h

index 67918c22339c5334836ed102e3be0e3ffd5695ed..76c3fe325101cc90660af3ee05902a02359633c7 100644 (file)
@@ -65,14 +65,22 @@ static inline unsigned long __copy_from_user_nocache(void *to,
  * do_page_fault() doesn't attempt to take mmap_sem.  This makes
  * probe_kernel_address() suitable for use within regions where the caller
  * already holds mmap_sem, or other locks which nest inside mmap_sem.
+ * This must be a macro because __get_user() needs to know the types of the
+ * args.
+ *
+ * We don't include enough header files to be able to do the set_fs().  We
+ * require that the probe_kernel_address() caller will do that.
  */
 #define probe_kernel_address(addr, retval)             \
        ({                                              \
                long ret;                               \
+               mm_segment_t old_fs = get_fs();         \
                                                        \
+               set_fs(KERNEL_DS);                      \
                pagefault_disable();                    \
                ret = __get_user(retval, addr);         \
                pagefault_enable();                     \
+               set_fs(old_fs);                         \
                ret;                                    \
        })