On Mon, 1 Feb 2016, Jessica Yu wrote:

> +/* Called from the module loader during module coming/going states */
> +extern int klp_module_enable(struct module *mod);
> +extern void klp_module_disable(struct module *mod);

We do not use 'extern' keyword in header files. It is redundant. 
Unfortunately, the situation differs among header files and it is hard to 
be consistent.

> +     /*
> +      * Each module has to know that the coming handler has
> +      * been called. We never know what module will get
> +      * patched by a new patch.
> +      */
> +     mod->klp_alive = true;

This comment should fixed too.

Note: we still need klp_alive, because the race is still there even 
without notifiers.

> +void klp_module_disable(struct module *mod)
>  {
> -     int ret;
> -     struct module *mod = data;
>       struct klp_patch *patch;
>       struct klp_object *obj;
>  
> -     if (action != MODULE_STATE_COMING && action != MODULE_STATE_GOING)
> -             return 0;
> +     if (mod->state != MODULE_STATE_GOING)
> +             return;

This is similar to what Petr proposed. We must be in MODULE_STATE_GOING 
here. We could WARN here and return.

> diff --git a/kernel/module.c b/kernel/module.c
> index b05d466..71c77ed 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -3375,6 +3378,10 @@ static int complete_formation(struct module *mod, 
> struct load_info *info)
>       mutex_unlock(&module_mutex);
>  
>       ftrace_module_enable(mod);
> +     err = klp_module_enable(mod);
> +     if (err)
> +             goto out;
> +

if (err)
        return err;

module_mutex is already unlocked so no need to jump to out.

Apart from these minor things and Petr's remarks it looks ok.

Thanks for fixing this.
Miroslav

Reply via email to