summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-10-21 10:31:30 +0200
committerThomas Haller <thaller@redhat.com>2014-10-30 15:34:02 +0100
commit69a5ab8bd24e8dcfcaf706fef4f0b11510057fcb (patch)
tree84a1c7e622c1f909343cd1fe01b2fab342b28d41
parentb6b4f2b4cccfe0330b0c54c118b5b9d727af8d31 (diff)
downloadNetworkManager-th/nm-0-9-10.tar.gz
settings: check file permissions when loading settings pluginsth/nm-0-9-10
Signed-off-by: Thomas Haller <thaller@redhat.com> (cherry picked from commit b7d6e44f3cc6a3aba82a067a9d6121c415a812fe)
-rw-r--r--src/settings/nm-settings.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index c9edc48cac..5760422563 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -26,6 +26,8 @@
#include "config.h"
#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
#include <string.h>
#include <gmodule.h>
#include <pwd.h>
@@ -626,10 +628,13 @@ load_plugins (NMSettings *self, const char **plugins, GError **error)
for (iter = plugins; iter && *iter; iter++) {
GModule *plugin;
- char *full_name, *path;
+ gs_free char *full_name = NULL;
+ gs_free char *path = NULL;
gs_free char *pname = NULL;
GObject *obj;
GObject * (*factory_func) (void);
+ struct stat st;
+ int errsv;
pname = g_strdup (*iter);
g_strstrip (pname);
@@ -658,18 +663,31 @@ load_plugins (NMSettings *self, const char **plugins, GError **error)
full_name = g_strdup_printf ("nm-settings-plugin-%s", pname);
path = g_module_build_path (NMPLUGINDIR, full_name);
+ if (stat (path, &st) != 0) {
+ errsv = errno;
+ LOG (LOGL_WARN, "Could not load plugin '%s' from file '%s': %s", pname, path, strerror (errsv));
+ continue;
+ }
+ if (!S_ISREG (st.st_mode)) {
+ LOG (LOGL_WARN, "Could not load plugin '%s' from file '%s': not a file", pname, path);
+ continue;
+ }
+ if (st.st_uid != 0) {
+ LOG (LOGL_WARN, "Could not load plugin '%s' from file '%s': file must be owned by root", pname, path);
+ continue;
+ }
+ if (st.st_mode & (S_IWGRP | S_IWOTH | S_ISUID)) {
+ LOG (LOGL_WARN, "Could not load plugin '%s' from file '%s': invalid file permissions", pname, path);
+ continue;
+ }
+
plugin = g_module_open (path, G_MODULE_BIND_LOCAL);
if (!plugin) {
- LOG (LOGL_WARN, "Could not load plugin '%s': %s",
- pname, g_module_error ());
- g_free (full_name);
- g_free (path);
+ LOG (LOGL_WARN, "Could not load plugin '%s' from file '%s': %s",
+ pname, full_name, g_module_error ());
continue;
}
- g_free (full_name);
- g_free (path);
-
/* errors after this point are fatal, because we loaded the shared library already. */
if (!g_module_symbol (plugin, "nm_system_config_factory", (gpointer) (&factory_func))) {