Commit e3a9b07a authored by Markos Chandras's avatar Markos Chandras Committed by Ralf Baechle

MIPS: asm: uaccess: Add EVA support for str*_user operations

The str*_user functions are used to securely access NULL terminated
strings from userland. Therefore, it's necessary to use the appropriate
EVA function. However, if the string is in kernel space, then the normal
instructions are being used to access it. The __str*_kernel_asm and
__str*_user_asm symbols are the same for non-EVA mode so there is no
functional change for the non-EVA kernels.
Signed-off-by: default avatarMarkos Chandras <markos.chandras@imgtec.com>
parent 05c65160
...@@ -1246,6 +1246,17 @@ __strncpy_from_user(char *__to, const char __user *__from, long __len) ...@@ -1246,6 +1246,17 @@ __strncpy_from_user(char *__to, const char __user *__from, long __len)
{ {
long res; long res;
if (segment_eq(get_fs(), get_ds())) {
__asm__ __volatile__(
"move\t$4, %1\n\t"
"move\t$5, %2\n\t"
"move\t$6, %3\n\t"
__MODULE_JAL(__strncpy_from_kernel_nocheck_asm)
"move\t%0, $2"
: "=r" (res)
: "r" (__to), "r" (__from), "r" (__len)
: "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
} else {
might_fault(); might_fault();
__asm__ __volatile__( __asm__ __volatile__(
"move\t$4, %1\n\t" "move\t$4, %1\n\t"
...@@ -1256,6 +1267,7 @@ __strncpy_from_user(char *__to, const char __user *__from, long __len) ...@@ -1256,6 +1267,7 @@ __strncpy_from_user(char *__to, const char __user *__from, long __len)
: "=r" (res) : "=r" (res)
: "r" (__to), "r" (__from), "r" (__len) : "r" (__to), "r" (__from), "r" (__len)
: "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory"); : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
}
return res; return res;
} }
...@@ -1283,6 +1295,17 @@ strncpy_from_user(char *__to, const char __user *__from, long __len) ...@@ -1283,6 +1295,17 @@ strncpy_from_user(char *__to, const char __user *__from, long __len)
{ {
long res; long res;
if (segment_eq(get_fs(), get_ds())) {
__asm__ __volatile__(
"move\t$4, %1\n\t"
"move\t$5, %2\n\t"
"move\t$6, %3\n\t"
__MODULE_JAL(__strncpy_from_kernel_asm)
"move\t%0, $2"
: "=r" (res)
: "r" (__to), "r" (__from), "r" (__len)
: "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
} else {
might_fault(); might_fault();
__asm__ __volatile__( __asm__ __volatile__(
"move\t$4, %1\n\t" "move\t$4, %1\n\t"
...@@ -1293,6 +1316,7 @@ strncpy_from_user(char *__to, const char __user *__from, long __len) ...@@ -1293,6 +1316,7 @@ strncpy_from_user(char *__to, const char __user *__from, long __len)
: "=r" (res) : "=r" (res)
: "r" (__to), "r" (__from), "r" (__len) : "r" (__to), "r" (__from), "r" (__len)
: "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory"); : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
}
return res; return res;
} }
...@@ -1302,6 +1326,15 @@ static inline long __strlen_user(const char __user *s) ...@@ -1302,6 +1326,15 @@ static inline long __strlen_user(const char __user *s)
{ {
long res; long res;
if (segment_eq(get_fs(), get_ds())) {
__asm__ __volatile__(
"move\t$4, %1\n\t"
__MODULE_JAL(__strlen_kernel_nocheck_asm)
"move\t%0, $2"
: "=r" (res)
: "r" (s)
: "$2", "$4", __UA_t0, "$31");
} else {
might_fault(); might_fault();
__asm__ __volatile__( __asm__ __volatile__(
"move\t$4, %1\n\t" "move\t$4, %1\n\t"
...@@ -1310,6 +1343,7 @@ static inline long __strlen_user(const char __user *s) ...@@ -1310,6 +1343,7 @@ static inline long __strlen_user(const char __user *s)
: "=r" (res) : "=r" (res)
: "r" (s) : "r" (s)
: "$2", "$4", __UA_t0, "$31"); : "$2", "$4", __UA_t0, "$31");
}
return res; return res;
} }
...@@ -1332,14 +1366,24 @@ static inline long strlen_user(const char __user *s) ...@@ -1332,14 +1366,24 @@ static inline long strlen_user(const char __user *s)
{ {
long res; long res;
if (segment_eq(get_fs(), get_ds())) {
__asm__ __volatile__(
"move\t$4, %1\n\t"
__MODULE_JAL(__strlen_kernel_asm)
"move\t%0, $2"
: "=r" (res)
: "r" (s)
: "$2", "$4", __UA_t0, "$31");
} else {
might_fault(); might_fault();
__asm__ __volatile__( __asm__ __volatile__(
"move\t$4, %1\n\t" "move\t$4, %1\n\t"
__MODULE_JAL(__strlen_user_asm) __MODULE_JAL(__strlen_kernel_asm)
"move\t%0, $2" "move\t%0, $2"
: "=r" (res) : "=r" (res)
: "r" (s) : "r" (s)
: "$2", "$4", __UA_t0, "$31"); : "$2", "$4", __UA_t0, "$31");
}
return res; return res;
} }
...@@ -1349,6 +1393,16 @@ static inline long __strnlen_user(const char __user *s, long n) ...@@ -1349,6 +1393,16 @@ static inline long __strnlen_user(const char __user *s, long n)
{ {
long res; long res;
if (segment_eq(get_fs(), get_ds())) {
__asm__ __volatile__(
"move\t$4, %1\n\t"
"move\t$5, %2\n\t"
__MODULE_JAL(__strnlen_kernel_nocheck_asm)
"move\t%0, $2"
: "=r" (res)
: "r" (s), "r" (n)
: "$2", "$4", "$5", __UA_t0, "$31");
} else {
might_fault(); might_fault();
__asm__ __volatile__( __asm__ __volatile__(
"move\t$4, %1\n\t" "move\t$4, %1\n\t"
...@@ -1358,6 +1412,7 @@ static inline long __strnlen_user(const char __user *s, long n) ...@@ -1358,6 +1412,7 @@ static inline long __strnlen_user(const char __user *s, long n)
: "=r" (res) : "=r" (res)
: "r" (s), "r" (n) : "r" (s), "r" (n)
: "$2", "$4", "$5", __UA_t0, "$31"); : "$2", "$4", "$5", __UA_t0, "$31");
}
return res; return res;
} }
...@@ -1381,6 +1436,16 @@ static inline long strnlen_user(const char __user *s, long n) ...@@ -1381,6 +1436,16 @@ static inline long strnlen_user(const char __user *s, long n)
long res; long res;
might_fault(); might_fault();
if (segment_eq(get_fs(), get_ds())) {
__asm__ __volatile__(
"move\t$4, %1\n\t"
"move\t$5, %2\n\t"
__MODULE_JAL(__strnlen_kernel_asm)
"move\t%0, $2"
: "=r" (res)
: "r" (s), "r" (n)
: "$2", "$4", "$5", __UA_t0, "$31");
} else {
__asm__ __volatile__( __asm__ __volatile__(
"move\t$4, %1\n\t" "move\t$4, %1\n\t"
"move\t$5, %2\n\t" "move\t$5, %2\n\t"
...@@ -1389,6 +1454,7 @@ static inline long strnlen_user(const char __user *s, long n) ...@@ -1389,6 +1454,7 @@ static inline long strnlen_user(const char __user *s, long n)
: "=r" (res) : "=r" (res)
: "r" (s), "r" (n) : "r" (s), "r" (n)
: "$2", "$4", "$5", __UA_t0, "$31"); : "$2", "$4", "$5", __UA_t0, "$31");
}
return res; return res;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment