From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Russell King - ARM Linux <linux@armlinux.org.uk>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
Mark Rutland <mark.rutland@arm.com>,
Michal Hocko <mhocko@suse.com>,
Andrew Morton <akpm@linux-foundation.org>,
Zhong Jiang <zhongjiang@huawei.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
Laura Abbott <labbott@fedoraproject.org>
Subject: Re: [PATCH] mm: vmalloc: simplify vread/vwrite to use existing mappings
Date: Thu, 8 Jun 2017 16:15:13 +0000 [thread overview]
Message-ID: <CAKv+Gu93O7_BmfFa-5yPr18GoRu=24JOEX3-c4bu3kmUhKrd7w@mail.gmail.com> (raw)
In-Reply-To: <20170608160644.GM4902@n2100.armlinux.org.uk>
On 8 June 2017 at 16:06, Russell King - ARM Linux <linux@armlinux.org.uk> wrote:
> On Wed, Jun 07, 2017 at 06:20:52PM +0000, Ard Biesheuvel wrote:
>> The current safe path iterates over each mapping page by page, and
>> kmap()'s each one individually, which is expensive and unnecessary.
>> Instead, let's use kern_addr_valid() to establish on a per-VMA basis
>> whether we may safely derefence them, and do so via its mapping in
>> the VMALLOC region. This can be done safely due to the fact that we
>> are holding the vmap_area_lock spinlock.
>
> This doesn't sound correct if you look at the definition of
> kern_addr_valid(). For example, x86-32 has:
>
> /*
> * kern_addr_valid() is (1) for FLATMEM and (0) for
> * SPARSEMEM and DISCONTIGMEM
> */
> #ifdef CONFIG_FLATMEM
> #define kern_addr_valid(addr) (1)
> #else
> #define kern_addr_valid(kaddr) (0)
> #endif
>
> The majority of architectures simply do:
>
> #define kern_addr_valid(addr) (1)
>
That is interesting, thanks for pointing it out.
The function read_kcore() [which is where the issue I am trying to fix
originates] currently has this logic:
if (kern_addr_valid(start)) {
unsigned long n;
/*
* Using bounce buffer to bypass the
* hardened user copy kernel text checks.
*/
memcpy(buf, (char *) start, tsz);
n = copy_to_user(buffer, buf, tsz);
/*
* We cannot distinguish between fault on source
* and fault on destination. When this happens
* we clear too and hope it will trigger the
* EFAULT again.
*/
if (n) {
if (clear_user(buffer + tsz - n,
n))
return -EFAULT;
}
} else {
if (clear_user(buffer, tsz))
return -EFAULT;
}
and the implementation I looked at [on arm64] happens to be the only
one that does something non-trivial.
> So, the result is that on the majority of architectures, we're now
> going to simply dereference 'addr' with very little in the way of
> checks.
>
Indeed.
> I think this makes these functions racy - the point at which the
> entry is placed onto the vmalloc list is quite different from the
> point where the page table entries for it are populated (which
> happens with the lock dropped.) So, I think this is asking for
> an oops.
>
Fair enough. I will try to find a different approach then.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2017-06-08 16:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-07 18:20 [PATCH] mm: vmalloc: simplify vread/vwrite to use existing mappings Ard Biesheuvel
2017-06-07 18:22 ` Ard Biesheuvel
2017-06-08 16:06 ` Russell King - ARM Linux
2017-06-08 16:15 ` Ard Biesheuvel [this message]
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='CAKv+Gu93O7_BmfFa-5yPr18GoRu=24JOEX3-c4bu3kmUhKrd7w@mail.gmail.com' \
--to=ard.biesheuvel@linaro.org \
--cc=akpm@linux-foundation.org \
--cc=labbott@fedoraproject.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mm@kvack.org \
--cc=linux@armlinux.org.uk \
--cc=mark.rutland@arm.com \
--cc=mhocko@suse.com \
--cc=zhongjiang@huawei.com \
/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).