Re: [PATCH v2] module: check if memory leak by module.

From: Andrey Ryabinin
Date: Wed Mar 29 2017 - 07:05:57 EST


On 03/29/2017 09:02 AM, Maninder Singh wrote:

> diff --git a/kernel/module.c b/kernel/module.c
> index f953df9..98a8018 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -2117,9 +2117,31 @@ void __weak module_arch_freeing_init(struct module *mod)
> {
> }
>
> +static void check_memory_leak(struct module *mod)
> +{
> + struct vmap_area *va;
> +
> + rcu_read_lock();
> + list_for_each_entry_rcu(va, &vmap_area_list, list) {

vmap_area_list is protected by spin_lock(&vmap_area_lock); not the RCU.

Also some other points:
1) kmemleak already detects leaks of that kind.

2) All this could be implemented in userspace, e.g. in rmmod tool
- Read /proc/vmalloc and find areas belonging to the module
- unload module
- read /proc/vmalloc and check if anything left from that module

3) This might produce false positives. E.g. module may defer vfree() in workqueue, so the
actual vfree() call happens after module unloaded.