From: Mikulas Patocka <mpatocka@redhat.com>
To: David Miller <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] sparc: fix incorrect value returned by copy_from_user_fixup
Date: Tue, 2 Aug 2016 08:20:15 -0400 (EDT) [thread overview]
Message-ID: <alpine.LRH.2.02.1608020806450.8555@file01.intranet.prod.int.rdu2.redhat.com> (raw)
In-Reply-To: <20160801.213312.1130341044241125265.davem@davemloft.net>
On Mon, 1 Aug 2016, David Miller wrote:
> From: Mikulas Patocka <mpatocka@redhat.com>
> Date: Sun, 31 Jul 2016 19:50:57 -0400 (EDT)
>
> > @@ -18,9 +25,9 @@
> > * of the cases, just fix things up simply here.
> > */
> >
> > -static unsigned long compute_size(unsigned long start, unsigned long size, unsigned long *offset)
> > +static unsigned long compute_size(unsigned long start, unsigned long size, unsigned long *offset, unsigned long prefetch)
> > {
> > - unsigned long fault_addr = current_thread_info()->fault_address;
> > + unsigned long fault_addr = current_thread_info()->fault_address - prefetch;
> > unsigned long end = start + size;
> >
> > if (fault_addr < start || fault_addr >= end) {
> > @@ -36,7 +43,7 @@ unsigned long copy_from_user_fixup(void
> > {
> > unsigned long offset;
> >
> > - size = compute_size((unsigned long) from, size, &offset);
> > + size = compute_size((unsigned long) from, size, &offset, COPY_FROM_USER_PREFETCH);
> > if (likely(size))
> > memset(to + offset, 0, size);
> >
>
> I think this might cause a problem. Assume we are not in one of those
> prefetching loops and are just doing a byte at a time, and therefore
> hit the fault exactly at the beginning of the missing page.
>
> You will rewind 0x100 bytes and the caller will restart the copy at
> "faulting address - 0x100".
>
> If someone is using atomic user copies, and using the returned length
> to determine which page in userspace needs to be faulted in, and
> then restart the copy, then we will loop forever.
This isn't guaranteed on x86 neither.
__copy_user_intel reads and writes 64 bytes in one loop iteration (and it
prefetches the data for the next iteration with "movl 64(%4), %%eax". If
it fails, it reports the amount of remaining data at the start of the loop
iteration. The reported value may be 67 bytes lower than the fault
location.
Mikulas
> We must, therefore, find some way to calculate this length _precisely_.
> It must be exactly at the furthest byte successfully copied to the
> destination.
>
next prev parent reply other threads:[~2016-08-02 15:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-31 23:50 Mikulas Patocka
2016-08-02 4:33 ` David Miller
2016-08-02 12:20 ` Mikulas Patocka [this message]
2016-08-02 17:47 ` David Miller
2016-08-04 0:21 ` David Miller
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=alpine.LRH.2.02.1608020806450.8555@file01.intranet.prod.int.rdu2.redhat.com \
--to=mpatocka@redhat.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=sparclinux@vger.kernel.org \
/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
all inboxes | Powered by JetHome®