diff mbox series

[08/10] mm: move debug checks from __vunmap to remove_vm_area

Message ID 20230119100226.789506-9-hch@lst.de (mailing list archive)
State New
Headers show
Series [01/10] vmalloc: reject vmap with VM_FLUSH_RESET_PERMS | expand

Commit Message

Christoph Hellwig Jan. 19, 2023, 10:02 a.m. UTC
All these checks apply to the free_vm_area interface as well, so move
them to the common routine.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 mm/vmalloc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Comments

Uladzislau Rezki Jan. 19, 2023, 6:49 p.m. UTC | #1
On Thu, Jan 19, 2023 at 11:02:24AM +0100, Christoph Hellwig wrote:
> All these checks apply to the free_vm_area interface as well, so move
> them to the common routine.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  mm/vmalloc.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 096633ba89965a..4cb189bdd51499 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2588,11 +2588,20 @@ struct vm_struct *remove_vm_area(const void *addr)
>  
>  	might_sleep();
>  
> +	if (WARN(!PAGE_ALIGNED(addr), "Trying to vfree() bad address (%p)\n",
> +			addr))
> +		return NULL;
> +
>  	va = find_unlink_vmap_area((unsigned long)addr);
>  	if (!va || !va->vm)
>  		return NULL;
>  	vm = va->vm;
> +
> +	debug_check_no_locks_freed(vm->addr, get_vm_area_size(vm));
> +	debug_check_no_obj_freed(vm->addr, get_vm_area_size(vm));
>  	kasan_free_module_shadow(vm);
> +	kasan_poison_vmalloc(vm->addr, get_vm_area_size(vm));
> +
>  	free_unmap_vmap_area(va);
>  	return vm;
>  }
> @@ -2664,10 +2673,6 @@ static void __vunmap(const void *addr, int deallocate_pages)
>  	if (!addr)
>  		return;
>  
> -	if (WARN(!PAGE_ALIGNED(addr), "Trying to vfree() bad address (%p)\n",
> -			addr))
> -		return;
> -
>  	area = remove_vm_area(addr);
>  	if (unlikely(!area)) {
>  		WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n",
> @@ -2675,11 +2680,6 @@ static void __vunmap(const void *addr, int deallocate_pages)
>  		return;
>  	}
>  
> -	debug_check_no_locks_freed(area->addr, get_vm_area_size(area));
> -	debug_check_no_obj_freed(area->addr, get_vm_area_size(area));
> -
> -	kasan_poison_vmalloc(area->addr, get_vm_area_size(area));
> -
>  	va_remove_mappings(area, deallocate_pages);
>  
>  	if (deallocate_pages) {
> -- 
> 2.39.0
> 
Looks good.

Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>

--
Uladzislau Rezki
diff mbox series

Patch

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 096633ba89965a..4cb189bdd51499 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2588,11 +2588,20 @@  struct vm_struct *remove_vm_area(const void *addr)
 
 	might_sleep();
 
+	if (WARN(!PAGE_ALIGNED(addr), "Trying to vfree() bad address (%p)\n",
+			addr))
+		return NULL;
+
 	va = find_unlink_vmap_area((unsigned long)addr);
 	if (!va || !va->vm)
 		return NULL;
 	vm = va->vm;
+
+	debug_check_no_locks_freed(vm->addr, get_vm_area_size(vm));
+	debug_check_no_obj_freed(vm->addr, get_vm_area_size(vm));
 	kasan_free_module_shadow(vm);
+	kasan_poison_vmalloc(vm->addr, get_vm_area_size(vm));
+
 	free_unmap_vmap_area(va);
 	return vm;
 }
@@ -2664,10 +2673,6 @@  static void __vunmap(const void *addr, int deallocate_pages)
 	if (!addr)
 		return;
 
-	if (WARN(!PAGE_ALIGNED(addr), "Trying to vfree() bad address (%p)\n",
-			addr))
-		return;
-
 	area = remove_vm_area(addr);
 	if (unlikely(!area)) {
 		WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n",
@@ -2675,11 +2680,6 @@  static void __vunmap(const void *addr, int deallocate_pages)
 		return;
 	}
 
-	debug_check_no_locks_freed(area->addr, get_vm_area_size(area));
-	debug_check_no_obj_freed(area->addr, get_vm_area_size(area));
-
-	kasan_poison_vmalloc(area->addr, get_vm_area_size(area));
-
 	va_remove_mappings(area, deallocate_pages);
 
 	if (deallocate_pages) {