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 <[email protected]>
---
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
On Sat, Jan 26, 2019 at 6:38 AM Matthew Wilcox <[email protected]> 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 <[email protected]>
> ---
> 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 <[email protected]>
-Kees
> goto out;
> retval = -ENOMEM;
> flush_dcache_page(page);
> --
> 2.20.1
>
--
Kees Cook
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.
On Fri, 25 Jan 2019 09:38:27 -0800 Matthew Wilcox <[email protected]> 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?
On Tue, Jan 29, 2019 at 7:21 AM Andrew Morton <[email protected]> wrote:
>
> On Fri, 25 Jan 2019 09:38:27 -0800 Matthew Wilcox <[email protected]> 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
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.
Matthew Wilcox <[email protected]> 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 <[email protected]>
> ---
> 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
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 <[email protected]>
Acked-by: Pekka Enberg <[email protected]>
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);
>