From: Peter Zijlstra <peterz@infradead.org>
To: Uladzislau Rezki <urezki@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
jroedel@suse.de, vbabka@suse.cz,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] mm/vmalloc: Sanitize __get_vm_area() arguments
Date: Fri, 3 Apr 2020 20:53:00 +0200 [thread overview]
Message-ID: <20200403185300.GD20730@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200403181818.GA5538@pc636>
On Fri, Apr 03, 2020 at 08:18:18PM +0200, Uladzislau Rezki wrote:
> On Fri, Apr 03, 2020 at 06:32:53PM +0200, Peter Zijlstra wrote:
> >
> > __get_vm_area() is an exported symbol, make sure the callers stay in
> > the expected memory range. When calling this function with memory
> > ranges outside of the VMALLOC range *bad* things can happen.
> >
> > (I noticed this when I managed to corrupt the kernel text by accident)
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> > mm/vmalloc.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -2130,6 +2130,13 @@ static struct vm_struct *__get_vm_area_n
> > struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
> > unsigned long start, unsigned long end)
> > {
> > + /*
> > + * Ensure callers stay in the vmalloc range.
> > + */
> > + if (WARN_ON(start < VMALLOC_START || start > VMALLOC_END ||
> > + end < VMALLOC_START || end > VMALLOC_END))
> > + return NULL;
> > +
> > return __get_vm_area_node(size, 1, flags, start, end, NUMA_NO_NODE,
> > GFP_KERNEL, __builtin_return_address(0));
> > }
> Peter, could you please clarify what kind of issues you had and how you
> tested?
Well, I had a bug and corrupted text; but then I tested:
__get_vm_area(PAGE_SIZE, VM_ALLOC, __START_KERNEL_map,
__START_KERNEL_map + KERNEL_IMAGE_SIZE);
and that *works*.
> __get_vm_area() is not limited by allocating only with vmalloc space,
> it can use whole virtual address space/range, i.e. 1 - ULONG_MAX.
Yeah, I know, I'm saying it perhaps should be, because not limiting it
while exposing it to modules seems risky at best, downright dangerous if
you consider map_vm_area() is also exported.
And while I know the machinery works for the complete virtual address
space, architectures do set aside explicit VA ranges for specific
purposes, we had better respect that, esp. for modules.
next prev parent reply other threads:[~2020-04-03 18:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-03 16:32 Peter Zijlstra
2020-04-03 18:18 ` Uladzislau Rezki
2020-04-03 18:53 ` Peter Zijlstra [this message]
2020-04-04 19:00 ` Uladzislau Rezki
2020-04-06 13:01 ` Christoph Hellwig
2020-04-06 14:06 ` Peter Zijlstra
2020-04-17 12:57 ` Sakari Ailus
2020-04-17 13:14 ` Peter Zijlstra
2020-04-17 13:38 ` Sakari Ailus
2020-04-04 15:35 William Kucharski
2020-04-04 18:52 ` Uladzislau Rezki
2020-04-05 5:25 ` William Kucharski
2020-04-05 17:23 ` Uladzislau Rezki
2020-04-05 19:21 ` Uladzislau Rezki
2020-04-05 20:49 ` William Kucharski
2020-04-06 12:59 ` Uladzislau Rezki
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=20200403185300.GD20730@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=jroedel@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=tglx@linutronix.de \
--cc=urezki@gmail.com \
--cc=vbabka@suse.cz \
/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