From 4bca8b2e2c42f1f7bd1763882481b70242960870 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Wed, 6 Aug 2003 21:13:58 -0700 Subject: [PATCH] [PATCH] might_sleep() checks for x86 usercopy functions From: Matt Mackall This only checks in the non-__ versions, as those are occassionally called inside things like kmap_atomic pairs which take a spinlock in with highmem. It's all conditional on CONFIG_DEBUG_SPINLOCK_SLEEP (which isn't quite the right name) so there's no overhead for normal builds. --- arch/i386/lib/usercopy.c | 3 +++ include/asm-i386/uaccess.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/arch/i386/lib/usercopy.c b/arch/i386/lib/usercopy.c index 647b54eef4dc4..2361c79f8b1d3 100644 --- a/arch/i386/lib/usercopy.c +++ b/arch/i386/lib/usercopy.c @@ -149,6 +149,7 @@ do { \ unsigned long clear_user(void __user *to, unsigned long n) { + might_sleep(); if (access_ok(VERIFY_WRITE, to, n)) __do_clear_user(to, n); return n; @@ -188,6 +189,8 @@ long strnlen_user(const char __user *s, long n) unsigned long mask = -__addr_ok(s); unsigned long res, tmp; + might_sleep(); + __asm__ __volatile__( " testl %0, %0\n" " jz 3f\n" diff --git a/include/asm-i386/uaccess.h b/include/asm-i386/uaccess.h index b7744806aed68..d3eabf5b95c7f 100644 --- a/include/asm-i386/uaccess.h +++ b/include/asm-i386/uaccess.h @@ -260,6 +260,7 @@ extern void __put_user_bad(void); ({ \ long __pu_err = -EFAULT; \ __typeof__(*(ptr)) *__pu_addr = (ptr); \ + might_sleep(); \ if (access_ok(VERIFY_WRITE,__pu_addr,size)) \ __put_user_size((x),__pu_addr,(size),__pu_err,-EFAULT); \ __pu_err; \ @@ -469,6 +470,7 @@ __copy_from_user(void *to, const void __user *from, unsigned long n) static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n) { + might_sleep(); if (access_ok(VERIFY_WRITE, to, n)) n = __copy_to_user(to, from, n); return n; @@ -493,6 +495,7 @@ copy_to_user(void __user *to, const void *from, unsigned long n) static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n) { + might_sleep(); if (access_ok(VERIFY_READ, from, n)) n = __copy_from_user(to, from, n); else -- 2.53.0