lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7c865af8-a178-a10f-bdcb-7750ab27c2ce@huawei.com>
Date:   Sat, 6 Jul 2019 14:17:52 +0800
From:   Zhiqiang Liu <liuzhiqiang26@...wei.com>
To:     Jessica Yu <jeyu@...nel.org>, <rusty@...tcorp.com.au>,
        <kay.sievers@...y.org>, <clabbe.montjoie@...il.com>
CC:     LKML <linux-kernel@...r.kernel.org>, <wangxiaogang3@...wei.com>,
        <zhoukang7@...wei.com>, Mingfangsen <mingfangsen@...wei.com>
Subject: Re: [PATCH v2] module: add usage links when calling ref_module func

Friendly ping ...

On 2019/7/3 10:09, Zhiqiang Liu wrote:
> From: Zhiqiang Liu <liuzhiqiang26@...wei.com>
> 
> Users can call ref_module func in their modules to construct
> relationships with other modules. However, the holders
> '/sys/module/<mod-name>/holders' of the target module donot include
> the users` module. So lsmod command misses detailed info of 'Used by'.
> 
> When load module, the process is given as follows,
> load_module()
> 	-> mod_sysfs_setup()
> 		-> add_usage_links
> 	-> do_init_module
> 		-> mod->init()
> 
> add_usage_links func creates holders of target modules linking to
> this module. If ref_module is called in mod->init() func, the usage
> links cannot be added.
> 
> Here, we will add usage link of a to b's holder_dir.
> 
> V1->V2:
> - remove incorrect Fixes tag
> - fix error handling of sysfs_create_link as suggested by Jessica Yu
> 
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@...wei.com>
> Suggested-by: Jessica Yu <jeyu@...nel.org>
> Reviewed-by: Kang Zhou <zhoukang7@...wei.com>
> ---
>  kernel/module.c | 18 ++++++++++++++----
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/module.c b/kernel/module.c
> index 80c7c09584cf..672abce2222c 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -837,25 +837,26 @@ static int already_uses(struct module *a, struct module *b)
>   *    'b' can walk the list to see who sourced them), and of 'a'
>   *    targets (so 'a' can see what modules it targets).
>   */
> -static int add_module_usage(struct module *a, struct module *b)
> +static struct module_use *add_module_usage(struct module *a, struct module *b)
>  {
>  	struct module_use *use;
> 
>  	pr_debug("Allocating new usage for %s.\n", a->name);
>  	use = kmalloc(sizeof(*use), GFP_ATOMIC);
>  	if (!use)
> -		return -ENOMEM;
> +		return NULL;
> 
>  	use->source = a;
>  	use->target = b;
>  	list_add(&use->source_list, &b->source_list);
>  	list_add(&use->target_list, &a->target_list);
> -	return 0;
> +	return use;
>  }
> 
>  /* Module a uses b: caller needs module_mutex() */
>  int ref_module(struct module *a, struct module *b)
>  {
> +	struct module_use *use;
>  	int err;
> 
>  	if (b == NULL || already_uses(a, b))
> @@ -866,9 +867,18 @@ int ref_module(struct module *a, struct module *b)
>  	if (err)
>  		return err;
> 
> -	err = add_module_usage(a, b);
> +	use = add_module_usage(a, b);
> +	if (!use) {
> +		module_put(b);
> +		return -ENOMEM;
> +	}
> +
> +	err = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
>  	if (err) {
>  		module_put(b);
> +		list_del(&use->source_list);
> +		list_del(&use->target_list);
> +		kfree(use);
>  		return err;
>  	}
>  	return 0;
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ