Re: [PATCH 1/2] modprobe: check for EPERM instead of EEXIST on insertion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Dave,

On Tue, Jan 10, 2012 at 11:40 PM, Dave Reisner <d@xxxxxxxxxxxxxx> wrote:
> kmod_module_insert_module will never return -EEXIST given the check for
> initstate prior to the call. Check for EPERM instead and throw an
> appropriate error when an unprivileged user attempts to load a module.

As we talked on IRC:

There is a race condition that we want to avoid. This is why we check
before and after we try to remove the module, since it could be
removed between the check and the syscall.


> ---
>  TODO                  |    2 --
>  tools/kmod-modprobe.c |   10 ++++------
>  2 files changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/TODO b/TODO
> index 5dd906d..6bd5736 100644
> --- a/TODO
> +++ b/TODO
> @@ -21,8 +21,6 @@ Features:
>    - deal with dependency loop
>    - break dependency loop when all it needs is to check if the module is
>      already loaded
> -   - check if user has permission to load module and print an error instead of
> -     returning 0
>
>  * Add manpages: copy them from module-init-tools and make the necessary changes
>
> diff --git a/tools/kmod-modprobe.c b/tools/kmod-modprobe.c
> index 7d9c667..5289c44 100644
> --- a/tools/kmod-modprobe.c
> +++ b/tools/kmod-modprobe.c
> @@ -807,12 +807,10 @@ static int insmod_do(struct kmod_module *mod, const char *extra_opts)
>                        flags |= KMOD_INSERT_FORCE_VERMAGIC;
>
>                err = kmod_module_insert_module(mod, flags, opts);
> -               if (err == -EEXIST) {
> -                       if (!first_time)
> -                               err = 0;
> -                       else
> -                               ERR("Module %s already in kernel.\n",
> -                                       kmod_module_get_name(mod));
> +               if (err == -EPERM) {
> +                       ERR("could not insert '%s': %s\n", kmod_module_get_name(mod),
> +                                       strerror(-err));
> +                       goto error;

It suffice to add this code without removing the other check.


Lucas de Marchi
--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux