From: Richard Henderson <rth@twiddle.net>
To: axp-list@redhat.com
Cc: krebs@qkal.sap-ag.de, torvalds@transmeta.com
Subject: Re: BUG kernel macro: copy_to_user
Date: Wed, 14 Apr 1999 00:25:57 -0700 [thread overview]
Message-ID: <19990414002557.A13199@twiddle.net> (raw)
In-Reply-To: <199904080752.JAA0000007399@storm.qkal.sap-ag.de>; from Andreas Krebs on Thu, Apr 08, 1999 at 09:52:30AM +0200
On Thu, Apr 08, 1999 at 09:52:30AM +0200, Andreas Krebs wrote:
> i think i found a serious bug in the __copy_tofrom_user macro define
> in include/asm-alpha/uaccess.h
>
> i was trying to install isdn under alpha linux and noticed that some
> ioctls from isdnctrl failed without any reason, so i looked into the
> isdn_common.c code and notice that calls to copy_to_user failed.
>
> all the calls that failed had in common that the size was NOT constant,
> in this case the call was as follows:
> if (copy_to_user((char *) arg, s, strlen(s) + 1)){
> ret = -EFAULT;
> } else {
> ret = 0;
> }
>
> i checked all addresses, ranges and the statement failed all the time
> until i changed strlen(s)+1 into a constant.
Here's a proper fix for all four instances of this problem.
Rather than play unneeded games with macro evaluation, I've
just turned all the offenders into inline functions.
r~
diff -rup 2.2.5/include/asm-alpha/uaccess.h 2.2.5-axp/include/asm-alpha/uaccess.h
--- 2.2.5/include/asm-alpha/uaccess.h Sun Apr 11 17:48:36 1999
+++ 2.2.5-axp/include/asm-alpha/uaccess.h Tue Apr 13 08:55:50 1999
@@ -358,43 +358,55 @@ __asm__ __volatile__("1: stb %r2,%1\n"
* Complex access routines
*/
-#define __copy_to_user(to,from,n) __copy_tofrom_user_nocheck((to),(from),(n))
-#define __copy_from_user(to,from,n) __copy_tofrom_user_nocheck((to),(from),(n))
-
-#define copy_to_user(to,from,n) __copy_tofrom_user((to),(from),(n),__cu_to)
-#define copy_from_user(to,from,n) __copy_tofrom_user((to),(from),(n),__cu_from)
-
extern void __copy_user(void);
-#define __copy_tofrom_user_nocheck(to,from,n) \
-({ \
- register void * __cu_to __asm__("$6") = (to); \
- register const void * __cu_from __asm__("$7") = (from); \
- register long __cu_len __asm__("$0") = (n); \
- __asm__ __volatile__( \
- "jsr $28,(%3),__copy_user" \
- : "=r" (__cu_len), "=r" (__cu_from), "=r" (__cu_to) \
- : "r" (__copy_user), "0" (__cu_len), \
- "1" (__cu_from), "2" (__cu_to) \
- : "$1","$2","$3","$4","$5","$28","memory"); \
- __cu_len; \
-})
+extern inline long
+__copy_tofrom_user_nocheck(void *to, const void *from, long len)
+{
+ register void * __cu_to __asm__("$6") = to;
+ register const void * __cu_from __asm__("$7") = from;
+ register long __cu_len __asm__("$0") = len;
+
+ __asm__ __volatile__(
+ "jsr $28,__copy_user"
+ : "=r" (__cu_len), "=r" (__cu_from), "=r" (__cu_to)
+ : "0" (__cu_len), "1" (__cu_from), "2" (__cu_to)
+ : "$1","$2","$3","$4","$5","$27","$28","memory");
+
+ return __cu_len;
+}
+
+extern inline long
+__copy_tofrom_user(void *to, const void *from, long len, const void *validate)
+{
+ if (__access_ok((long)validate, len, get_fs())) {
+ register void * __cu_to __asm__("$6") = to;
+ register const void * __cu_from __asm__("$7") = from;
+ register long __cu_len __asm__("$0") = len;
+ __asm__ __volatile__(
+ "jsr $28,__copy_user"
+ : "=r" (__cu_len), "=r" (__cu_from), "=r" (__cu_to)
+ : "0" (__cu_len), "1" (__cu_from), "2" (__cu_to)
+ : "$1","$2","$3","$4","$5","$27","$28","memory");
+ len = __cu_len;
+ }
+ return len;
+}
-#define __copy_tofrom_user(to,from,n,v) \
-({ \
- register void * __cu_to __asm__("$6") = (to); \
- register const void * __cu_from __asm__("$7") = (from); \
- register long __cu_len __asm__("$0") = (n); \
- if (__access_ok(((long)(v)),__cu_len,get_fs())) { \
- __asm__ __volatile__( \
- "jsr $28,(%3),__copy_user" \
- : "=r" (__cu_len), "=r" (__cu_from), "=r" (__cu_to) \
- : "r" (__copy_user), "0" (__cu_len), \
- "1" (__cu_from), "2" (__cu_to) \
- : "$1","$2","$3","$4","$5","$28","memory"); \
- } \
- __cu_len; \
-})
+#define __copy_to_user(to,from,n) __copy_tofrom_user_nocheck((to),(from),(n))
+#define __copy_from_user(to,from,n) __copy_tofrom_user_nocheck((to),(from),(n))
+
+extern inline long
+copy_to_user(void *to, const void *from, long n)
+{
+ return __copy_tofrom_user(to, from, n, to);
+}
+
+extern inline long
+copy_from_user(void *to, const void *from, long n)
+{
+ return __copy_tofrom_user(to, from, n, from);
+}
#define copy_to_user_ret(to,from,n,retval) ({ \
if (copy_to_user(to,from,n)) \
@@ -408,46 +420,48 @@ if (copy_from_user(to,from,n)) \
extern void __do_clear_user(void);
-#define __clear_user(to,n) \
-({ \
- register void * __cl_to __asm__("$6") = (to); \
- register long __cl_len __asm__("$0") = (n); \
- __asm__ __volatile__( \
- "jsr $28,(%2),__do_clear_user" \
- : "=r"(__cl_len), "=r"(__cl_to) \
- : "r"(__do_clear_user), "0"(__cl_len), "1"(__cl_to) \
- : "$1","$2","$3","$4","$5","$28","memory"); \
- __cl_len; \
-})
-
-#define clear_user(to,n) \
-({ \
- register void * __cl_to __asm__("$6") = (to); \
- register long __cl_len __asm__("$0") = (n); \
- if (__access_ok(((long)__cl_to),__cl_len,get_fs())) { \
- __asm__ __volatile__( \
- "jsr $28,(%2),__do_clear_user" \
- : "=r"(__cl_len), "=r"(__cl_to) \
- : "r"(__do_clear_user), "0"(__cl_len), "1"(__cl_to)\
- : "$1","$2","$3","$4","$5","$28","memory"); \
- } \
- __cl_len; \
-})
+extern inline long
+__clear_user(void *to, long len)
+{
+ register void * __cl_to __asm__("$6") = to;
+ register long __cl_len __asm__("$0") = len;
+ __asm__ __volatile__(
+ "jsr $28,__do_clear_user"
+ : "=r"(__cl_len), "=r"(__cl_to)
+ : "0"(__cl_len), "1"(__cl_to)
+ : "$1","$2","$3","$4","$5","$27","$28","memory");
+ return __cl_len;
+}
+
+extern inline long
+clear_user(void *to, long len)
+{
+ if (__access_ok((long)to, len, get_fs())) {
+ register void * __cl_to __asm__("$6") = to;
+ register long __cl_len __asm__("$0") = len;
+ __asm__ __volatile__(
+ "jsr $28,__do_clear_user"
+ : "=r"(__cl_len), "=r"(__cl_to)
+ : "0"(__cl_len), "1"(__cl_to)
+ : "$1","$2","$3","$4","$5","$27","$28","memory");
+ len = __cl_len;
+ }
+ return len;
+}
/* Returns: -EFAULT if exception before terminator, N if the entire
buffer filled, else strlen. */
extern long __strncpy_from_user(char *__to, const char *__from, long __to_len);
-#define strncpy_from_user(to,from,n) \
-({ \
- char * __sfu_to = (to); \
- const char * __sfu_from = (from); \
- long __sfu_ret = -EFAULT; \
- if (__access_ok(((long)__sfu_from),0,get_fs())) \
- __sfu_ret = __strncpy_from_user(__sfu_to,__sfu_from,(n)); \
- __sfu_ret; \
-})
+extern inline long
+strncpy_from_user(char *to, const char *from, long n)
+{
+ long ret = -EFAULT;
+ if (__access_ok((long)from, 0, get_fs()))
+ ret = __strncpy_from_user(to, from, n);
+ return ret;
+}
/* Returns: 0 if bad, string length+1 (memory size) of string if ok */
extern long __strlen_user(const char *);
prev parent reply other threads:[~1999-04-14 7:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-08 7:52 BUG kernel macro: copy_to_user Andreas Krebs
1999-04-08 16:44 ` Richard Henderson
1999-04-09 17:24 ` Matthew Jacob
1999-04-09 17:26 ` I *apologize* Matthew Jacob
1999-04-14 7:25 ` Richard Henderson [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox