From: Dave Reisner Date: Tue, 10 Jan 2012 18:36:27 +0000 (-0500) Subject: modprobe: check for EPERM on insertion X-Git-Tag: v4~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b54f1bf06aa450cdb4616ba9caed3c700588977f;p=thirdparty%2Fkmod.git modprobe: check for EPERM on insertion Throw an appropriate error when an unprivileged user attempts to load a module. --- diff --git a/TODO b/TODO index 2d45006c..bd29f25b 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 7d9c667f..698f5fff 100644 --- a/tools/kmod-modprobe.c +++ b/tools/kmod-modprobe.c @@ -807,12 +807,21 @@ 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) { + switch (err) { + case -EEXIST: + /* we checked for EEXIST with an earlier call to retrieve the initstate, + * but to avoid a race condition, we don't make any assumptions and + * handle the error again here */ if (!first_time) err = 0; else ERR("Module %s already in kernel.\n", kmod_module_get_name(mod)); + goto error; + case -EPERM: + ERR("could not insert '%s': %s\n", kmod_module_get_name(mod), + strerror(-err)); + goto error; } }