2005-04-17 00:20:36 +02:00
|
|
|
#ifndef __PARISC_UACCESS_H
|
|
|
|
#define __PARISC_UACCESS_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* User space memory access functions
|
|
|
|
*/
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/cache.h>
|
2010-02-01 20:56:33 +01:00
|
|
|
#include <asm/errno.h>
|
2009-05-14 00:56:30 +02:00
|
|
|
#include <asm-generic/uaccess-unaligned.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2014-10-21 21:29:09 +02:00
|
|
|
#include <linux/bug.h>
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#define VERIFY_READ 0
|
|
|
|
#define VERIFY_WRITE 1
|
|
|
|
|
|
|
|
#define KERNEL_DS ((mm_segment_t){0})
|
|
|
|
#define USER_DS ((mm_segment_t){1})
|
|
|
|
|
2015-01-06 16:45:34 +01:00
|
|
|
#define segment_eq(a, b) ((a).seg == (b).seg)
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#define get_ds() (KERNEL_DS)
|
|
|
|
#define get_fs() (current_thread_info()->addr_limit)
|
|
|
|
#define set_fs(x) (current_thread_info()->addr_limit = (x))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that since kernel addresses are in a separate address space on
|
2005-05-01 17:59:08 +02:00
|
|
|
* parisc, we don't need to do anything for access_ok().
|
2005-04-17 00:20:36 +02:00
|
|
|
* We just let the page fault handler do the right thing. This also means
|
|
|
|
* that put_user is the same as __put_user, etc.
|
|
|
|
*/
|
|
|
|
|
2013-11-19 23:31:35 +01:00
|
|
|
static inline long access_ok(int type, const void __user * addr,
|
|
|
|
unsigned long size)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2013-11-19 23:31:35 +01:00
|
|
|
return 1;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define put_user __put_user
|
|
|
|
#define get_user __get_user
|
|
|
|
|
2006-12-20 00:35:57 +01:00
|
|
|
#if !defined(CONFIG_64BIT)
|
2014-10-21 21:29:09 +02:00
|
|
|
#define LDD_KERNEL(ptr) BUILD_BUG()
|
|
|
|
#define LDD_USER(ptr) BUILD_BUG()
|
2015-01-06 16:45:34 +01:00
|
|
|
#define STD_KERNEL(x, ptr) __put_kernel_asm64(x, ptr)
|
|
|
|
#define STD_USER(x, ptr) __put_user_asm64(x, ptr)
|
2006-12-19 22:33:58 +01:00
|
|
|
#define ASM_WORD_INSN ".word\t"
|
2005-04-17 00:20:36 +02:00
|
|
|
#else
|
2015-01-06 16:45:34 +01:00
|
|
|
#define LDD_KERNEL(ptr) __get_kernel_asm("ldd", ptr)
|
|
|
|
#define LDD_USER(ptr) __get_user_asm("ldd", ptr)
|
|
|
|
#define STD_KERNEL(x, ptr) __put_kernel_asm("std", x, ptr)
|
|
|
|
#define STD_USER(x, ptr) __put_user_asm("std", x, ptr)
|
2006-12-19 22:33:58 +01:00
|
|
|
#define ASM_WORD_INSN ".dword\t"
|
2005-04-17 00:20:36 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The exception table contains two values: the first is an address
|
|
|
|
* for an instruction that is allowed to fault, and the second is
|
2013-10-13 21:11:30 +02:00
|
|
|
* the address to the fixup routine. Even on a 64bit kernel we could
|
|
|
|
* use a 32bit (unsigned int) address here.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct exception_table_entry {
|
2013-10-13 21:11:30 +02:00
|
|
|
unsigned long insn; /* address of insn that is allowed to fault. */
|
|
|
|
unsigned long fixup; /* fixup routine */
|
2005-04-17 00:20:36 +02:00
|
|
|
};
|
|
|
|
|
2007-01-28 14:52:57 +01:00
|
|
|
#define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr )\
|
|
|
|
".section __ex_table,\"aw\"\n" \
|
|
|
|
ASM_WORD_INSN #fault_addr ", " #except_addr "\n\t" \
|
|
|
|
".previous\n"
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* The page fault handler stores, in a per-cpu area, the following information
|
|
|
|
* if a fixup routine is available.
|
|
|
|
*/
|
|
|
|
struct exception_data {
|
|
|
|
unsigned long fault_ip;
|
|
|
|
unsigned long fault_space;
|
|
|
|
unsigned long fault_addr;
|
|
|
|
};
|
|
|
|
|
2015-01-06 16:45:34 +01:00
|
|
|
#define __get_user(x, ptr) \
|
|
|
|
({ \
|
|
|
|
register long __gu_err __asm__ ("r8") = 0; \
|
|
|
|
register long __gu_val __asm__ ("r9") = 0; \
|
|
|
|
\
|
|
|
|
if (segment_eq(get_fs(), KERNEL_DS)) { \
|
|
|
|
switch (sizeof(*(ptr))) { \
|
|
|
|
case 1: __get_kernel_asm("ldb", ptr); break; \
|
|
|
|
case 2: __get_kernel_asm("ldh", ptr); break; \
|
|
|
|
case 4: __get_kernel_asm("ldw", ptr); break; \
|
|
|
|
case 8: LDD_KERNEL(ptr); break; \
|
|
|
|
default: BUILD_BUG(); break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
switch (sizeof(*(ptr))) { \
|
|
|
|
case 1: __get_user_asm("ldb", ptr); break; \
|
|
|
|
case 2: __get_user_asm("ldh", ptr); break; \
|
|
|
|
case 4: __get_user_asm("ldw", ptr); break; \
|
|
|
|
case 8: LDD_USER(ptr); break; \
|
|
|
|
default: BUILD_BUG(); break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
(x) = (__force __typeof__(*(ptr))) __gu_val; \
|
|
|
|
__gu_err; \
|
2005-04-17 00:20:36 +02:00
|
|
|
})
|
|
|
|
|
2015-01-06 16:45:34 +01:00
|
|
|
#define __get_kernel_asm(ldx, ptr) \
|
2007-01-28 14:52:57 +01:00
|
|
|
__asm__("\n1:\t" ldx "\t0(%2),%0\n\t" \
|
|
|
|
ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_get_user_skip_1)\
|
2005-04-17 00:20:36 +02:00
|
|
|
: "=r"(__gu_val), "=r"(__gu_err) \
|
|
|
|
: "r"(ptr), "1"(__gu_err) \
|
|
|
|
: "r1");
|
|
|
|
|
2015-01-06 16:45:34 +01:00
|
|
|
#define __get_user_asm(ldx, ptr) \
|
2007-01-28 14:52:57 +01:00
|
|
|
__asm__("\n1:\t" ldx "\t0(%%sr3,%2),%0\n\t" \
|
2015-01-06 16:45:34 +01:00
|
|
|
ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_get_user_skip_1)\
|
2005-04-17 00:20:36 +02:00
|
|
|
: "=r"(__gu_val), "=r"(__gu_err) \
|
|
|
|
: "r"(ptr), "1"(__gu_err) \
|
|
|
|
: "r1");
|
|
|
|
|
2015-01-06 16:45:34 +01:00
|
|
|
#define __put_user(x, ptr) \
|
2005-04-17 00:20:36 +02:00
|
|
|
({ \
|
|
|
|
register long __pu_err __asm__ ("r8") = 0; \
|
|
|
|
__typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x); \
|
|
|
|
\
|
2015-01-06 16:45:34 +01:00
|
|
|
if (segment_eq(get_fs(), KERNEL_DS)) { \
|
2005-04-17 00:20:36 +02:00
|
|
|
switch (sizeof(*(ptr))) { \
|
2015-01-06 16:45:34 +01:00
|
|
|
case 1: __put_kernel_asm("stb", __x, ptr); break; \
|
|
|
|
case 2: __put_kernel_asm("sth", __x, ptr); break; \
|
|
|
|
case 4: __put_kernel_asm("stw", __x, ptr); break; \
|
|
|
|
case 8: STD_KERNEL(__x, ptr); break; \
|
2014-10-21 21:29:09 +02:00
|
|
|
default: BUILD_BUG(); break; \
|
2005-04-17 00:20:36 +02:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
switch (sizeof(*(ptr))) { \
|
2015-01-06 16:45:34 +01:00
|
|
|
case 1: __put_user_asm("stb", __x, ptr); break; \
|
|
|
|
case 2: __put_user_asm("sth", __x, ptr); break; \
|
|
|
|
case 4: __put_user_asm("stw", __x, ptr); break; \
|
|
|
|
case 8: STD_USER(__x, ptr); break; \
|
2014-10-21 21:29:09 +02:00
|
|
|
default: BUILD_BUG(); break; \
|
2005-04-17 00:20:36 +02:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
__pu_err; \
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The "__put_user/kernel_asm()" macros tell gcc they read from memory
|
|
|
|
* instead of writing. This is because they do not write to any memory
|
2006-04-22 22:47:21 +02:00
|
|
|
* gcc knows about, so there are no aliasing issues. These macros must
|
|
|
|
* also be aware that "fixup_put_user_skip_[12]" are executed in the
|
|
|
|
* context of the fault, and any registers used there must be listed
|
|
|
|
* as clobbers. In this case only "r1" is used by the current routines.
|
|
|
|
* r8/r9 are already listed as err/val.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
|
2015-01-06 16:45:34 +01:00
|
|
|
#define __put_kernel_asm(stx, x, ptr) \
|
2005-04-17 00:20:36 +02:00
|
|
|
__asm__ __volatile__ ( \
|
2007-01-28 14:52:57 +01:00
|
|
|
"\n1:\t" stx "\t%2,0(%1)\n\t" \
|
2015-01-06 16:45:34 +01:00
|
|
|
ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_put_user_skip_1)\
|
2005-04-17 00:20:36 +02:00
|
|
|
: "=r"(__pu_err) \
|
2006-04-22 22:47:21 +02:00
|
|
|
: "r"(ptr), "r"(x), "0"(__pu_err) \
|
|
|
|
: "r1")
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2015-01-06 16:45:34 +01:00
|
|
|
#define __put_user_asm(stx, x, ptr) \
|
2005-04-17 00:20:36 +02:00
|
|
|
__asm__ __volatile__ ( \
|
2007-01-28 14:52:57 +01:00
|
|
|
"\n1:\t" stx "\t%2,0(%%sr3,%1)\n\t" \
|
2015-01-06 16:45:34 +01:00
|
|
|
ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_put_user_skip_1)\
|
2005-04-17 00:20:36 +02:00
|
|
|
: "=r"(__pu_err) \
|
|
|
|
: "r"(ptr), "r"(x), "0"(__pu_err) \
|
|
|
|
: "r1")
|
|
|
|
|
|
|
|
|
2006-12-20 00:35:57 +01:00
|
|
|
#if !defined(CONFIG_64BIT)
|
2006-12-19 22:33:58 +01:00
|
|
|
|
2015-01-06 16:45:34 +01:00
|
|
|
#define __put_kernel_asm64(__val, ptr) do { \
|
2005-04-17 00:20:36 +02:00
|
|
|
__asm__ __volatile__ ( \
|
2007-01-28 14:52:57 +01:00
|
|
|
"\n1:\tstw %2,0(%1)" \
|
2013-04-22 14:53:43 +02:00
|
|
|
"\n2:\tstw %R2,4(%1)\n\t" \
|
2015-01-06 16:45:34 +01:00
|
|
|
ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_put_user_skip_2)\
|
|
|
|
ASM_EXCEPTIONTABLE_ENTRY(2b, fixup_put_user_skip_1)\
|
2005-04-17 00:20:36 +02:00
|
|
|
: "=r"(__pu_err) \
|
2013-04-22 14:53:43 +02:00
|
|
|
: "r"(ptr), "r"(__val), "0"(__pu_err) \
|
2005-04-17 00:20:36 +02:00
|
|
|
: "r1"); \
|
|
|
|
} while (0)
|
|
|
|
|
2015-01-06 16:45:34 +01:00
|
|
|
#define __put_user_asm64(__val, ptr) do { \
|
2005-04-17 00:20:36 +02:00
|
|
|
__asm__ __volatile__ ( \
|
2007-01-28 14:52:57 +01:00
|
|
|
"\n1:\tstw %2,0(%%sr3,%1)" \
|
2013-04-22 14:53:43 +02:00
|
|
|
"\n2:\tstw %R2,4(%%sr3,%1)\n\t" \
|
2015-01-06 16:45:34 +01:00
|
|
|
ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_put_user_skip_2)\
|
|
|
|
ASM_EXCEPTIONTABLE_ENTRY(2b, fixup_put_user_skip_1)\
|
2005-04-17 00:20:36 +02:00
|
|
|
: "=r"(__pu_err) \
|
2013-04-22 14:53:43 +02:00
|
|
|
: "r"(ptr), "r"(__val), "0"(__pu_err) \
|
2005-04-17 00:20:36 +02:00
|
|
|
: "r1"); \
|
|
|
|
} while (0)
|
|
|
|
|
2006-12-20 00:35:57 +01:00
|
|
|
#endif /* !defined(CONFIG_64BIT) */
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Complex access routines -- external declarations
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern unsigned long lcopy_to_user(void __user *, const void *, unsigned long);
|
|
|
|
extern unsigned long lcopy_from_user(void *, const void __user *, unsigned long);
|
|
|
|
extern unsigned long lcopy_in_user(void __user *, const void __user *, unsigned long);
|
2012-05-26 10:48:19 +02:00
|
|
|
extern long strncpy_from_user(char *, const char __user *, long);
|
2015-01-06 16:45:34 +01:00
|
|
|
extern unsigned lclear_user(void __user *, unsigned long);
|
|
|
|
extern long lstrnlen_user(const char __user *, long);
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Complex access routines -- macros
|
|
|
|
*/
|
2013-11-19 23:31:35 +01:00
|
|
|
#define user_addr_max() (~0UL)
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#define strnlen_user lstrnlen_user
|
|
|
|
#define strlen_user(str) lstrnlen_user(str, 0x7fffffffL)
|
|
|
|
#define clear_user lclear_user
|
|
|
|
#define __clear_user lclear_user
|
|
|
|
|
|
|
|
unsigned long copy_to_user(void __user *dst, const void *src, unsigned long len);
|
|
|
|
#define __copy_to_user copy_to_user
|
2010-02-01 20:56:33 +01:00
|
|
|
unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long len);
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned long copy_in_user(void __user *dst, const void __user *src, unsigned long len);
|
|
|
|
#define __copy_in_user copy_in_user
|
|
|
|
#define __copy_to_user_inatomic __copy_to_user
|
|
|
|
#define __copy_from_user_inatomic __copy_from_user
|
|
|
|
|
2010-02-01 20:56:33 +01:00
|
|
|
extern void copy_from_user_overflow(void)
|
|
|
|
#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
|
|
|
|
__compiletime_error("copy_from_user() buffer size is not provably correct")
|
|
|
|
#else
|
|
|
|
__compiletime_warning("copy_from_user() buffer size is not provably correct")
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
static inline unsigned long __must_check copy_from_user(void *to,
|
|
|
|
const void __user *from,
|
|
|
|
unsigned long n)
|
|
|
|
{
|
|
|
|
int sz = __compiletime_object_size(to);
|
|
|
|
int ret = -EFAULT;
|
|
|
|
|
|
|
|
if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
|
|
|
|
ret = __copy_from_user(to, from, n);
|
|
|
|
else
|
|
|
|
copy_from_user_overflow();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-01-13 20:52:46 +01:00
|
|
|
struct pt_regs;
|
parisc: fix kernel crash (protection id trap) when compiling ruby1.9
On Wed, Dec 17, 2008 at 11:46:05PM +0100, Helge Deller wrote:
>
Honestly, I can't decide whether to apply this. It really should never
happen in the kernel, since the kernel can guarantee it won't get the
access rights failure (highest privilege level, and can set %sr and
%protid to whatever it wants.)
It really genuinely is a bug that probably should panic the kernel. The
only precedent I can easily see is x86 fixing up a bad iret with a
general protection fault, which is more or less analogous to code 27
here.
On the other hand, taking the exception on a userspace access really
isn't all that critical, and there's fundamentally little reason for the
kernel not to SIGSEGV the process, and continue...
Argh.
(btw, I've instrumented my do_sys_poll with a pile of assertions that
%cr8 << 1 == %sr3 == current->mm.context... let's see if where we're
getting corrupted is deterministic, though, I would guess that it won't
be.)
Signed-off-by: Kyle McMartin <kyle@mcmartin.ca>
2008-12-20 03:29:06 +01:00
|
|
|
int fixup_exception(struct pt_regs *regs);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#endif /* __PARISC_UACCESS_H */
|