linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: Fix strnlen_user access check
@ 2021-04-11 11:04 Jinyang He
  2021-04-12  3:02 ` Tiezhu Yang
  2021-04-12 13:47 ` Jinyang He
  0 siblings, 2 replies; 15+ messages in thread
From: Jinyang He @ 2021-04-11 11:04 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel

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@loongson.cn>
---
 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__(
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread
* [PATCH] MIPS: Fix strnlen_user access check
@ 2021-04-15 21:26 Thomas Bogendoerfer
  2021-04-16  7:22 ` Thomas Bogendoerfer
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Bogendoerfer @ 2021-04-15 21:26 UTC (permalink / raw)
  To: linux-mips, linux-kernel

Commit 04324f44cb69 ("MIPS: Remove get_fs/set_fs") changed the access_ok
for strnlen_user to check the whole range, which broke some callers
of strndup_user(). Restore the old behaviour and just check the first byte.

Fixes: 04324f44cb69 ("MIPS: Remove get_fs/set_fs")
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/include/asm/uaccess.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
index ab47e597656a..783fecce65c8 100644
--- a/arch/mips/include/asm/uaccess.h
+++ b/arch/mips/include/asm/uaccess.h
@@ -614,8 +614,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__(
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-04-16  7:23 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-11 11:04 [PATCH] MIPS: Fix strnlen_user access check Jinyang He
2021-04-12  3:02 ` Tiezhu Yang
2021-04-12  6:06   ` Jinyang He
2021-04-12  7:08   ` Tiezhu Yang
2021-04-12 14:27   ` Thomas Bogendoerfer
2021-04-13  1:15     ` Jinyang He
2021-04-13  8:34       ` David Laight
2021-04-13 11:14       ` Thomas Bogendoerfer
2021-04-13 12:37         ` David Laight
2021-04-13 15:19           ` Thomas Bogendoerfer
2021-04-13 16:01             ` David Laight
2021-04-14  7:59               ` Thomas Bogendoerfer
2021-04-12 13:47 ` Jinyang He
2021-04-15 21:26 Thomas Bogendoerfer
2021-04-16  7:22 ` Thomas Bogendoerfer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).