From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: Jinyang He <hejinyang@loongson.cn>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] MIPS: Fix strnlen_user access check
Date: Mon, 12 Apr 2021 11:02:19 +0800 [thread overview]
Message-ID: <cbe5e79b-ee6c-5c59-0051-28e4d1152666@loongson.cn> (raw)
In-Reply-To: <1618139092-4018-1-git-send-email-hejinyang@loongson.cn>
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@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__(
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
next prev parent reply other threads:[~2021-04-12 3:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-11 11:04 [PATCH] MIPS: Fix strnlen_user access check Jinyang He
2021-04-12 3:02 ` Tiezhu Yang [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cbe5e79b-ee6c-5c59-0051-28e4d1152666@loongson.cn \
--to=yangtiezhu@loongson.cn \
--cc=hejinyang@loongson.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=tsbogend@alpha.franken.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).