diff mbox series

[v2,2/2] mm: usercopy: Warn vmalloc/module address in check_heap_object()

Message ID 20211225120621.13908-3-wangkefeng.wang@huawei.com (mailing list archive)
State New
Headers show
Series mm: Fix kernel BUG in __check_heap_object() on PowerPC64 | expand

Commit Message

Kefeng Wang Dec. 25, 2021, 12:06 p.m. UTC
virt_addr_valid() could be insufficient to validate the virt addr
on some architecture, which could lead to potential BUG which has
been found on arm64/powerpc64.

Let's add WARN_ON to check if the virt addr is passed virt_addr_valid()
but is a vmalloc/module address.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/usercopy.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Christophe Leroy Dec. 26, 2021, 5:33 p.m. UTC | #1
Le 25/12/2021 à 13:06, Kefeng Wang a écrit :
> virt_addr_valid() could be insufficient to validate the virt addr
> on some architecture, which could lead to potential BUG which has
> been found on arm64/powerpc64.
> 
> Let's add WARN_ON to check if the virt addr is passed virt_addr_valid()
> but is a vmalloc/module address.

I think that's the responsibility of the architecture and doesn't 
deserve a WARN_ON() in generic code.

The generic code cannot check all what architectures do wrong.

Eventually you can do some testing at startup, maybe with 
CONFIG_DEBUG_VM_PGTABLE, but I don't think we should have such 
verification in functions like check_heap_object()

> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>   mm/usercopy.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/mm/usercopy.c b/mm/usercopy.c
> index b3de3c4eefba..ce83e0b137dd 100644
> --- a/mm/usercopy.c
> +++ b/mm/usercopy.c
> @@ -228,6 +228,8 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
>   	if (!virt_addr_valid(ptr))
>   		return;
>   
> +	WARN_ON_ONCE(is_vmalloc_or_module_addr(ptr));
> +
>   	/*
>   	 * When CONFIG_HIGHMEM=y, kmap_to_page() will give either the
>   	 * highmem page or fallback to virt_to_page(). The following
Kefeng Wang Dec. 28, 2021, 4:51 a.m. UTC | #2
On 2021/12/27 1:33, Christophe Leroy wrote:
>
> Le 25/12/2021 à 13:06, Kefeng Wang a écrit :
>> virt_addr_valid() could be insufficient to validate the virt addr
>> on some architecture, which could lead to potential BUG which has
>> been found on arm64/powerpc64.
>>
>> Let's add WARN_ON to check if the virt addr is passed virt_addr_valid()
>> but is a vmalloc/module address.
> I think that's the responsibility of the architecture and doesn't
> deserve a WARN_ON() in generic code.
>
> The generic code cannot check all what architectures do wrong.
>
> Eventually you can do some testing at startup, maybe with
> CONFIG_DEBUG_VM_PGTABLE, but I don't think we should have such
> verification in functions like check_heap_object()

Ok, we could find other better place to add a virt_to_valid() check

instead of this one.

>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>> ---
>>    mm/usercopy.c | 2 ++
>>    1 file changed, 2 insertions(+)
>>
>> diff --git a/mm/usercopy.c b/mm/usercopy.c
>> index b3de3c4eefba..ce83e0b137dd 100644
>> --- a/mm/usercopy.c
>> +++ b/mm/usercopy.c
>> @@ -228,6 +228,8 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
>>    	if (!virt_addr_valid(ptr))
>>    		return;
>>    
>> +	WARN_ON_ONCE(is_vmalloc_or_module_addr(ptr));
>> +
>>    	/*
>>    	 * When CONFIG_HIGHMEM=y, kmap_to_page() will give either the
>>    	 * highmem page or fallback to virt_to_page(). The following
diff mbox series

Patch

diff --git a/mm/usercopy.c b/mm/usercopy.c
index b3de3c4eefba..ce83e0b137dd 100644
--- a/mm/usercopy.c
+++ b/mm/usercopy.c
@@ -228,6 +228,8 @@  static inline void check_heap_object(const void *ptr, unsigned long n,
 	if (!virt_addr_valid(ptr))
 		return;
 
+	WARN_ON_ONCE(is_vmalloc_or_module_addr(ptr));
+
 	/*
 	 * When CONFIG_HIGHMEM=y, kmap_to_page() will give either the
 	 * highmem page or fallback to virt_to_page(). The following