kernel-hardening.lists.openwall.com archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Prevent mapping slab pages to userspace
@ 2019-01-25 17:38 Matthew Wilcox
  2019-01-25 18:44 ` Kees Cook
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Matthew Wilcox @ 2019-01-25 17:38 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Matthew Wilcox, linux-mm, linux-kernel, Rik van Riel,
	Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	kernel-hardening, Kees Cook, Michael Ellerman

It's never appropriate to map a page allocated by SLAB into userspace.
A buggy device driver might try this, or an attacker might be able to
find a way to make it happen.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 mm/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memory.c b/mm/memory.c
index e11ca9dd823f..ce8c90b752be 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1451,7 +1451,7 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
 	spinlock_t *ptl;
 
 	retval = -EINVAL;
-	if (PageAnon(page))
+	if (PageAnon(page) || PageSlab(page))
 		goto out;
 	retval = -ENOMEM;
 	flush_dcache_page(page);
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] mm: Prevent mapping slab pages to userspace
  2019-01-25 17:38 [PATCH] mm: Prevent mapping slab pages to userspace Matthew Wilcox
@ 2019-01-25 18:44 ` Kees Cook
  2019-01-25 19:30   ` Matthew Wilcox
  2019-01-28 18:20 ` Andrew Morton
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Kees Cook @ 2019-01-25 18:44 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Andrew Morton, Linux-MM, LKML, Rik van Riel, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, Kernel Hardening,
	Michael Ellerman

On Sat, Jan 26, 2019 at 6:38 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> It's never appropriate to map a page allocated by SLAB into userspace.
> A buggy device driver might try this, or an attacker might be able to
> find a way to make it happen.
>
> Signed-off-by: Matthew Wilcox <willy@infradead.org>
> ---
>  mm/memory.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index e11ca9dd823f..ce8c90b752be 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1451,7 +1451,7 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
>         spinlock_t *ptl;
>
>         retval = -EINVAL;
> -       if (PageAnon(page))
> +       if (PageAnon(page) || PageSlab(page))

Are there other types that should not get mapped? (Or better yet, is
there a whitelist of those that are okay to be mapped?)

Either way, this sounds good. :)

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

>                 goto out;
>         retval = -ENOMEM;
>         flush_dcache_page(page);
> --
> 2.20.1
>


-- 
Kees Cook

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] mm: Prevent mapping slab pages to userspace
  2019-01-25 18:44 ` Kees Cook
@ 2019-01-25 19:30   ` Matthew Wilcox
  0 siblings, 0 replies; 8+ messages in thread
From: Matthew Wilcox @ 2019-01-25 19:30 UTC (permalink / raw)
  To: Kees Cook
  Cc: Andrew Morton, Linux-MM, LKML, Rik van Riel, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, Kernel Hardening,
	Michael Ellerman

On Sat, Jan 26, 2019 at 07:44:40AM +1300, Kees Cook wrote:
> > -       if (PageAnon(page))
> > +       if (PageAnon(page) || PageSlab(page))
> 
> Are there other types that should not get mapped? (Or better yet, is
> there a whitelist of those that are okay to be mapped?)

Funny you should ask; I think the next patch in this series looks like this:

-       if (PageAnon(page) || PageSlab(page))
+       if (PageAnon(page) || PageSlab(page) || page_has_type(page))

but let's see if there's something I've overlooked with this patch.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] mm: Prevent mapping slab pages to userspace
  2019-01-25 17:38 [PATCH] mm: Prevent mapping slab pages to userspace Matthew Wilcox
  2019-01-25 18:44 ` Kees Cook
@ 2019-01-28 18:20 ` Andrew Morton
  2019-01-28 19:00   ` Kees Cook
  2019-01-31  0:37 ` Michael Ellerman
  2019-01-31  6:03 ` Pekka Enberg
  3 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2019-01-28 18:20 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: linux-mm, linux-kernel, Rik van Riel, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, kernel-hardening,
	Kees Cook, Michael Ellerman

On Fri, 25 Jan 2019 09:38:27 -0800 Matthew Wilcox <willy@infradead.org> wrote:

> It's never appropriate to map a page allocated by SLAB into userspace.
> A buggy device driver might try this, or an attacker might be able to
> find a way to make it happen.

It wouldn't surprise me if someone somewhere is doing this.  Rather
than mysteriously breaking their code, how about we emit a warning and
still permit it to proceed, for a while?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] mm: Prevent mapping slab pages to userspace
  2019-01-28 18:20 ` Andrew Morton
@ 2019-01-28 19:00   ` Kees Cook
  2019-01-28 20:08     ` Christopher Lameter
  0 siblings, 1 reply; 8+ messages in thread
From: Kees Cook @ 2019-01-28 19:00 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Matthew Wilcox, Linux-MM, LKML, Rik van Riel, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, Kernel Hardening,
	Michael Ellerman

On Tue, Jan 29, 2019 at 7:21 AM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Fri, 25 Jan 2019 09:38:27 -0800 Matthew Wilcox <willy@infradead.org> wrote:
>
> > It's never appropriate to map a page allocated by SLAB into userspace.
> > A buggy device driver might try this, or an attacker might be able to
> > find a way to make it happen.
>
> It wouldn't surprise me if someone somewhere is doing this.  Rather
> than mysteriously breaking their code, how about we emit a warning and
> still permit it to proceed, for a while?

It seems like a fatal condition to me? There's nothing to check that
such a page wouldn't get freed by the slab while still mapped to
userspace, right?

But I'll take warning over not checking. :)

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] mm: Prevent mapping slab pages to userspace
  2019-01-28 19:00   ` Kees Cook
@ 2019-01-28 20:08     ` Christopher Lameter
  0 siblings, 0 replies; 8+ messages in thread
From: Christopher Lameter @ 2019-01-28 20:08 UTC (permalink / raw)
  To: Kees Cook
  Cc: Andrew Morton, Matthew Wilcox, Linux-MM, LKML, Rik van Riel,
	Pekka Enberg, David Rientjes, Joonsoo Kim, Kernel Hardening,
	Michael Ellerman

On Tue, 29 Jan 2019, Kees Cook wrote:

> It seems like a fatal condition to me? There's nothing to check that
> such a page wouldn't get freed by the slab while still mapped to
> userspace, right?

Lets just fail the code.  Currently this may work with SLUB. But SLAB and
SLOB overlay fields with mapcount. So you would have a corrupted page
struct if you mapped a slab page to user space.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] mm: Prevent mapping slab pages to userspace
  2019-01-25 17:38 [PATCH] mm: Prevent mapping slab pages to userspace Matthew Wilcox
  2019-01-25 18:44 ` Kees Cook
  2019-01-28 18:20 ` Andrew Morton
@ 2019-01-31  0:37 ` Michael Ellerman
  2019-01-31  6:03 ` Pekka Enberg
  3 siblings, 0 replies; 8+ messages in thread
From: Michael Ellerman @ 2019-01-31  0:37 UTC (permalink / raw)
  To: Matthew Wilcox, Andrew Morton
  Cc: linux-mm, linux-kernel, Rik van Riel, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, kernel-hardening,
	Kees Cook

Matthew Wilcox <willy@infradead.org> writes:

> It's never appropriate to map a page allocated by SLAB into userspace.
> A buggy device driver might try this, or an attacker might be able to
> find a way to make it happen.
>
> Signed-off-by: Matthew Wilcox <willy@infradead.org>
> ---
>  mm/memory.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index e11ca9dd823f..ce8c90b752be 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1451,7 +1451,7 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
>  	spinlock_t *ptl;
>  
>  	retval = -EINVAL;
> -	if (PageAnon(page))
> +	if (PageAnon(page) || PageSlab(page))
>  		goto out;
>  	retval = -ENOMEM;
>  	flush_dcache_page(page);


Thanks for turning this into an actual patch.

cheers

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] mm: Prevent mapping slab pages to userspace
  2019-01-25 17:38 [PATCH] mm: Prevent mapping slab pages to userspace Matthew Wilcox
                   ` (2 preceding siblings ...)
  2019-01-31  0:37 ` Michael Ellerman
@ 2019-01-31  6:03 ` Pekka Enberg
  3 siblings, 0 replies; 8+ messages in thread
From: Pekka Enberg @ 2019-01-31  6:03 UTC (permalink / raw)
  To: Matthew Wilcox, Andrew Morton
  Cc: linux-mm, linux-kernel, Rik van Riel, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, kernel-hardening,
	Kees Cook, Michael Ellerman

On 25/01/2019 19.38, Matthew Wilcox wrote:
> It's never appropriate to map a page allocated by SLAB into userspace.
> A buggy device driver might try this, or an attacker might be able to
> find a way to make it happen.
> 
> Signed-off-by: Matthew Wilcox <willy@infradead.org>

Acked-by: Pekka Enberg <penberg@kernel.org>

A WARN_ON_ONCE() would be nice here to let those buggy drivers know that 
they will no longer work.

> ---
>   mm/memory.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index e11ca9dd823f..ce8c90b752be 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1451,7 +1451,7 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
>   	spinlock_t *ptl;
>   
>   	retval = -EINVAL;
> -	if (PageAnon(page))
> +	if (PageAnon(page) || PageSlab(page))
>   		goto out;
>   	retval = -ENOMEM;
>   	flush_dcache_page(page);
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-01-31  6:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-25 17:38 [PATCH] mm: Prevent mapping slab pages to userspace Matthew Wilcox
2019-01-25 18:44 ` Kees Cook
2019-01-25 19:30   ` Matthew Wilcox
2019-01-28 18:20 ` Andrew Morton
2019-01-28 19:00   ` Kees Cook
2019-01-28 20:08     ` Christopher Lameter
2019-01-31  0:37 ` Michael Ellerman
2019-01-31  6:03 ` Pekka Enberg

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).