lkml.org 
[lkml]   [2019]   [Dec]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
SubjectRe: [PATCH 1/2] kasan: fix crashes on access to memory mapped by vm_map_ram()
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 4d3b3d60d893..a5412f14f57f 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -1073,6 +1073,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
> struct vmap_area *va, *pva;
> unsigned long addr;
> int purged = 0;
> + int ret = -EBUSY;
>
> BUG_ON(!size);
> BUG_ON(offset_in_page(size));
> @@ -1139,6 +1140,10 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
> va->va_end = addr + size;
> va->vm = NULL;
>
> + ret = kasan_populate_vmalloc(addr, size);
> + if (ret)
> + goto out;
> +
But it introduces another issues when is CONFIG_KASAN_VMALLOC=y. If
the kasan_populate_vmalloc() gets failed for some reason it just
leaves the function, that will lead to waste of vmap space.

> spin_lock(&vmap_area_lock);
> insert_vmap_area(va, &vmap_area_root, &vmap_area_list);
> spin_unlock(&vmap_area_lock);
>
ret = kasan_populate_vmalloc(addr, size);
if (ret) {
free_vmap_area(va);
return ERR_PTR(-EBUSY);;
}

> @@ -1169,8 +1174,9 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
> pr_warn("vmap allocation for size %lu failed: use vmalloc=<size> to increase size\n",
> size);
>
> +out:
> kmem_cache_free(vmap_area_cachep, va);
> - return ERR_PTR(-EBUSY);
> + return ERR_PTR(ret);
> }
>

\
 
 \ /
  Last update: 2019-12-04 23:41    [W:0.061 / U:13.960 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site