On 04/12/2021 11:02 AM, Tiezhu Yang wrote:
On 04/11/2021 07:04 PM, Jinyang He wrote:
Commit 04324f44cb69 ("MIPS: Remove get_fs/set_fs") brought a problem for
strnlen_user(). Jump out when checking access_ok() with condition that
(s + strlen(s)) < __UA_LIMIT <= (s + n). The old __strnlen_user_asm()
just checked (ua_limit & s) without checking (ua_limit & (s + n)).
Therefore, find strlen form s to __UA_LIMIT - 1 in that condition.
Signed-off-by: Jinyang He <hejinyang@xxxxxxxxxxx>
---
arch/mips/include/asm/uaccess.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/mips/include/asm/uaccess.h
b/arch/mips/include/asm/uaccess.h
index 91bc7fb..85ba0c8 100644
--- a/arch/mips/include/asm/uaccess.h
+++ b/arch/mips/include/asm/uaccess.h
@@ -630,8 +630,15 @@ static inline long strnlen_user(const char
__user *s, long n)
{
long res;
- if (!access_ok(s, n))
- return -0;
+ if (unlikely(n <= 0))
+ return 0;
+
+ if (!access_ok(s, n)) {
+ if (!access_ok(s, 0))
+ return 0;
+
+ n = __UA_LIMIT - (unsigned long)s - 1;
+ }
might_fault();
__asm__ __volatile__(
The following simple changes are OK to fix this issue?
diff --git a/arch/mips/include/asm/uaccess.h
b/arch/mips/include/asm/uaccess.h
index 91bc7fb..eafc99b 100644
--- a/arch/mips/include/asm/uaccess.h
+++ b/arch/mips/include/asm/uaccess.h
@@ -630,8 +630,8 @@ static inline long strnlen_user(const char __user
*s, long n)
{
long res;
- if (!access_ok(s, n))
- return -0;
+ if (!access_ok(s, 1))
+ return 0;
might_fault();
__asm__ __volatile__(
Thanks,
Tiezhu
Hi all,
Here is some detail info about background and analysis process,
I hope it is useful to understand this issue.
When update kernel with the latest mips-next, we can not login through a
graphical interface, this is because drm radeon GPU driver does not work,
we can not see the boot message "[drm] radeon kernel modesetting enabled."
through the serial console.
drivers/gpu/drm/radeon/radeon_drv.c
static int __init radeon_module_init(void)
{
[...]
DRM_INFO("radeon kernel modesetting enabled.\n");
[...]
}
I use git bisect to find commit 04324f44cb69 ("MIPS: Remove get_fs/set_fs")
is the first bad commit:
$ git bisect log
git bisect start
# good: [666c1fc90cd82184624d4cc5d124c66025f89a47] mips: bmips:
bcm63268: populate device tree nodes
git bisect good 666c1fc90cd82184624d4cc5d124c66025f89a47
# bad: [e86e75596623e1ce5d784db8214687326712a8ae] MIPS: octeon: Add
__raw_copy_[from|to|in]_user symbols
git bisect bad e86e75596623e1ce5d784db8214687326712a8ae
# good: [45deb5faeb9e02951361ceba5ffee721745661c3] MIPS: uaccess:
Remove get_fs/set_fs call sites
git bisect good 45deb5faeb9e02951361ceba5ffee721745661c3
# bad: [5e65c52ec716af6e8f51dacdaeb4a4d872249af1] MIPS: Loongson64:
Use _CACHE_UNCACHED instead of _CACHE_UNCACHED_ACCELERATED
git bisect bad 5e65c52ec716af6e8f51dacdaeb4a4d872249af1
# bad: [04324f44cb69a03fdc8f2ee52386a4fdf6a0043b] MIPS: Remove
get_fs/set_fs
git bisect bad 04324f44cb69a03fdc8f2ee52386a4fdf6a0043b
# first bad commit: [04324f44cb69a03fdc8f2ee52386a4fdf6a0043b] MIPS:
Remove get_fs/set_fs
I analysis and test the changes in the above first bad commit and find out
the following obvious difference which leads to the login issue.
arch/mips/include/asm/uaccess.h
static inline long strnlen_user(const char __user *s, long n)
{
[...]
if (!access_ok(s, n))
return -0;
[...]
}
Thanks,
Tiezhu