From: Mike Rapoport <rppt@kernel.org>
To: Christian Lamparter <chunkeey@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Russell King <linux@armlinux.org.uk>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] arm: use mmap_write_(un)lock for copy_to_user
Date: Tue, 29 Sep 2020 12:26:51 +0300 [thread overview]
Message-ID: <20200929092651.GD2142832@kernel.org> (raw)
In-Reply-To: <20200926192854.22164-1-chunkeey@gmail.com>
On Sat, Sep 26, 2020 at 09:28:54PM +0200, Christian Lamparter wrote:
> changes ARM's copy_to_user to use mmap_*write*_lock
> variants. This is because the data is written to
> user-space and not read.
The mmap lock protects internals of 'struct mm_struct' and they do not
change when the data is copied regardless of its direction.
> Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
> ---
> arch/arm/lib/uaccess_with_memcpy.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
> index 106f83a5ea6d..7491c13fdf0e 100644
> --- a/arch/arm/lib/uaccess_with_memcpy.c
> +++ b/arch/arm/lib/uaccess_with_memcpy.c
> @@ -101,7 +101,7 @@ __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
> atomic = faulthandler_disabled();
>
> if (!atomic)
> - mmap_read_lock(current->mm);
> + mmap_write_lock(current->mm);
> while (n) {
> pte_t *pte;
> spinlock_t *ptl;
> @@ -109,11 +109,11 @@ __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
>
> while (!pin_page_for_write(to, &pte, &ptl)) {
> if (!atomic)
> - mmap_read_unlock(current->mm);
> + mmap_write_unlock(current->mm);
> if (__put_user(0, (char __user *)to))
> goto out;
> if (!atomic)
> - mmap_read_lock(current->mm);
> + mmap_write_lock(current->mm);
> }
>
> tocopy = (~(unsigned long)to & ~PAGE_MASK) + 1;
> @@ -133,7 +133,7 @@ __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
> spin_unlock(ptl);
> }
> if (!atomic)
> - mmap_read_unlock(current->mm);
> + mmap_write_unlock(current->mm);
>
> out:
> return n;
> --
> 2.28.0
>
--
Sincerely yours,
Mike.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-09-29 9:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-26 19:28 [PATCH] arm: use mmap_write_(un)lock for copy_to_user Christian Lamparter
2020-09-29 9:26 ` Mike Rapoport [this message]
2020-09-29 9:31 ` Russell King - ARM Linux admin
2020-09-29 18:56 ` Christian Lamparter
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=20200929092651.GD2142832@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=chunkeey@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux@armlinux.org.uk \
/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).