#define __do_strncpy_from_user(dst, src, count, res) \
do { \
int __d0, __d1, __d2; \
- might_sleep(); \
- if (current->mm) \
- might_lock_read(¤t->mm->mmap_sem); \
+ might_fault(); \
__asm__ __volatile__( \
" testl %1,%1\n" \
" jz 2f\n" \
#define __do_clear_user(addr,size) \
do { \
int __d0; \
- might_sleep(); \
- if (current->mm) \
- might_lock_read(¤t->mm->mmap_sem); \
+ might_fault(); \
__asm__ __volatile__( \
"0: rep; stosl\n" \
" movl %2,%0\n" \
unsigned long mask = -__addr_ok(s);
unsigned long res, tmp;
- might_sleep();
- if (current->mm)
- might_lock_read(¤t->mm->mmap_sem);
+ might_fault();
__asm__ __volatile__(
" testl %0, %0\n"
#define __do_strncpy_from_user(dst,src,count,res) \
do { \
long __d0, __d1, __d2; \
- might_sleep(); \
- if (current->mm) \
- might_lock_read(¤t->mm->mmap_sem); \
+ might_fault(); \
__asm__ __volatile__( \
" testq %1,%1\n" \
" jz 2f\n" \
unsigned long __clear_user(void __user *addr, unsigned long size)
{
long __d0;
- might_sleep();
- if (current->mm)
- might_lock_read(¤t->mm->mmap_sem);
+ might_fault();
/* no memory constraint because it doesn't change any memory gcc knows
about */
asm volatile(
#include <linux/thread_info.h>
#include <linux/prefetch.h>
#include <linux/string.h>
-#include <linux/lockdep.h>
-#include <linux/sched.h>
#include <asm/asm.h>
#include <asm/page.h>
int __ret_gu; \
unsigned long __val_gu; \
__chk_user_ptr(ptr); \
- might_sleep(); \
- if (current->mm) \
- might_lock_read(¤t->mm->mmap_sem); \
+ might_fault(); \
switch (sizeof(*(ptr))) { \
case 1: \
__get_user_x(1, __ret_gu, __val_gu, ptr); \
int __ret_pu; \
__typeof__(*(ptr)) __pu_val; \
__chk_user_ptr(ptr); \
- might_sleep(); \
- if (current->mm) \
- might_lock_read(¤t->mm->mmap_sem); \
+ might_fault(); \
__pu_val = x; \
switch (sizeof(*(ptr))) { \
case 1: \
#define __put_user_size(x, ptr, size, retval, errret) \
do { \
retval = 0; \
- might_sleep(); \
- if (current->mm) \
- might_lock_read(¤t->mm->mmap_sem); \
+ might_fault(); \
__chk_user_ptr(ptr); \
switch (size) { \
case 1: \
#define __get_user_size(x, ptr, size, retval, errret) \
do { \
retval = 0; \
- might_sleep(); \
- if (current->mm) \
- might_lock_read(¤t->mm->mmap_sem); \
+ might_fault(); \
__chk_user_ptr(ptr); \
switch (size) { \
case 1: \
static __always_inline unsigned long __must_check
__copy_to_user(void __user *to, const void *from, unsigned long n)
{
- might_sleep();
- if (current->mm)
- might_lock_read(¤t->mm->mmap_sem);
+ might_fault();
return __copy_to_user_inatomic(to, from, n);
}
static __always_inline unsigned long
__copy_from_user(void *to, const void __user *from, unsigned long n)
{
- might_sleep();
- if (current->mm)
- might_lock_read(¤t->mm->mmap_sem);
+ might_fault();
if (__builtin_constant_p(n)) {
unsigned long ret;
static __always_inline unsigned long __copy_from_user_nocache(void *to,
const void __user *from, unsigned long n)
{
- might_sleep();
- if (current->mm)
- might_lock_read(¤t->mm->mmap_sem);
+ might_fault();
if (__builtin_constant_p(n)) {
unsigned long ret;
{
int ret = 0;
- might_sleep();
- if (current->mm)
- might_lock_read(¤t->mm->mmap_sem);
+ might_fault();
if (!__builtin_constant_p(size))
return copy_user_generic(dst, (__force void *)src, size);
switch (size) {
{
int ret = 0;
- might_sleep();
- if (current->mm)
- might_lock_read(¤t->mm->mmap_sem);
+ might_fault();
if (!__builtin_constant_p(size))
return copy_user_generic((__force void *)dst, src, size);
switch (size) {
{
int ret = 0;
- might_sleep();
- if (current->mm)
- might_lock_read(¤t->mm->mmap_sem);
+ might_fault();
if (!__builtin_constant_p(size))
return copy_user_generic((__force void *)dst,
(__force void *)src, size);
(__x < 0) ? -__x : __x; \
})
+#ifdef CONFIG_PROVE_LOCKING
+void might_fault(void);
+#else
+static inline void might_fault(void)
+{
+ might_sleep();
+}
+#endif
+
extern struct atomic_notifier_head panic_notifier_list;
extern long (*panic_blink)(long time);
NORET_TYPE void panic(const char * fmt, ...)
}
up_read(¤t->mm->mmap_sem);
}
+
+#ifdef CONFIG_PROVE_LOCKING
+void might_fault(void)
+{
+ might_sleep();
+ /*
+ * it would be nicer only to annotate paths which are not under
+ * pagefault_disable, however that requires a larger audit and
+ * providing helpers like get_user_atomic.
+ */
+ if (!in_atomic() && current->mm)
+ might_lock_read(¤t->mm->mmap_sem);
+}
+EXPORT_SYMBOL(might_fault);
+#endif