File module-init-tools-suse.diff of Package module-init-tools

This patch contains suse-specific changes against upstream commit 837014acd25834c885af7859b41198c896d7c00f

diff --git a/depmod.c b/depmod.c
index 647e5e6..a95957f 100644
--- a/depmod.c
+++ b/depmod.c
@@ -195,7 +195,7 @@ static void load_module_symvers(const char *filename)
 
 	/* eg. "0xb352177e\tfind_first_bit\tvmlinux\tEXPORT_SYMBOL" */
 	while (fgets(line, sizeof(line)-1, module_symvers)) {
-		const char *ver, *sym, *where;
+		const char *ver, *sym, *where, *slash;
 
 		ver = strtok(line, " \t");
 		sym = strtok(NULL, " \t");
@@ -203,7 +203,9 @@ static void load_module_symvers(const char *filename)
 		if (!ver || !sym || !where)
 			continue;
 
-		if (streq(where, "vmlinux"))
+		if (streq(where, "vmlinux") ||
+		    (((slash = strrchr(where, '/'))) &&
+		    streq(slash, "/built-in")))
 			add_symbol(sym, strtoull(ver, NULL, 16), NULL);
 	}
 
diff --git a/doc/modprobe.conf.sgml b/doc/modprobe.conf.sgml
index 74fdb7c..45c3172 100644
--- a/doc/modprobe.conf.sgml
+++ b/doc/modprobe.conf.sgml
@@ -205,6 +205,19 @@
 	  </para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term>allow_unsupported_modules <replaceable>[0|1]</replaceable>
+        </term>
+	<listitem>
+	  <para>
+            In SUSE kernels, every kernel module has a flag 'supported'. If
+            this flag is not set loading this module will taint your kernel.
+            Setting this option to 0 disables loading of unsupported modules
+            and avoids tainting the kernel. This is typically set in
+            <filename>/etc/modprobe.d/unsupported-modules</filename>.
+	  </para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
   <refsect1>
diff --git a/doc/modprobe.sgml b/doc/modprobe.sgml
index 85330e1..31da55c 100644
--- a/doc/modprobe.sgml
+++ b/doc/modprobe.sgml
@@ -441,9 +441,28 @@
 	  </para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><option>--allow-unsupported-modules</option>
+        </term>
+        <listitem>
+          <para>
+            Load unsupported modules even if disabled in configuration.
+	  </para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
   <refsect1>
+    <title>RETURN VALUE</title>
+
+    <para>
+      <command>modprobe</command> returns 0 on success, 1 on an unspecified
+      error and 2 if the module is not supported. Use the
+      <option>--allow-unsupported-modules</option> option to force
+      using an unsupported module.
+    </para>
+  </refsect1>
+  <refsect1>
     <title>ENVIRONMENT</title>
     <para>
       The MODPROBE_OPTIONS environment variable can also be used to
diff --git a/logging.c b/logging.c
index 4330269..46257ff 100644
--- a/logging.c
+++ b/logging.c
@@ -57,13 +57,15 @@ void error(const char *fmt, ...)
 	va_end(arglist);
 }
 
+/* can be overriden for different kinds of errors */
+int fatal_exit_code = 1;
 void fatal(const char *fmt, ...)
 {
 	va_list arglist;
 	va_start(arglist, fmt);
 	message("FATAL: ", fmt, &arglist);
 	va_end(arglist);
-	exit(1);
+	exit(fatal_exit_code);
 }
 
 /* If we don't flush, then child processes print before we do */
diff --git a/logging.h b/logging.h
index fb11df0..78b1600 100644
--- a/logging.h
+++ b/logging.h
@@ -10,6 +10,9 @@ extern int quiet;
 /* Do we want informative messages as well as errors? */
 extern int verbose;
 
+/* Exit code returned by fatal() */
+extern int fatal_exit_code;
+
 #ifdef __GNUC__
 #define _printf __attribute__((format(printf, 1, 2)))
 #else
diff --git a/modprobe.c b/modprobe.c
index 26a7163..4ddeea1 100644
--- a/modprobe.c
+++ b/modprobe.c
@@ -51,6 +51,9 @@
 
 int use_binary_indexes = 1; /* default to enabled. */
 
+/* Allow loading of unsupported modules? */
+static int allow_unsupported = 1;
+
 /* Limit do_softdep/do_modprobe recursion.
  * This is a simple way to handle dependency loops
  * caused by poorly written softdep commands.
@@ -80,6 +83,7 @@ typedef enum
 	mit_strip_modversion = 256,
 	mit_resolve_alias = 512
 
+	,mit_force_allow_unsupported = 1<<20
 } modprobe_flags_t;
 
 #ifndef MODULE_DIR
@@ -310,6 +314,23 @@ static void clear_magic(struct elf_file *module)
 	}
 }
 
+static int module_supported(struct elf_file *module)
+{
+	struct string_table *tbl;
+	int j;
+
+	/* Grab from new-style .modinfo section. */
+	tbl = module->ops->load_strings(module, ".modinfo", NULL);
+	for (j = 0; tbl && j < tbl->cnt; j++) {
+		const char *p = tbl->str[j];
+		if (streq(p, "supported=yes") ||
+		    streq(p, "supported=external")) {
+			return 1;
+		}
+	}
+	return 0;
+}
+
 struct module_options
 {
 	struct module_options *next;
@@ -947,6 +968,16 @@ static int parse_config_file(const char *filename,
 				if (streq(tmp, "no"))
 					use_binary_indexes = 0;
 			}
+		} else if (strcmp(cmd, "allow_unsupported_modules") == 0) {
+			const char *option = strsep_skipspace(&ptr, "\t ");
+			if (!option)
+				grammar(cmd, filename, linenum);
+			else if (streq(option, "yes") || streq(option, "1"))
+				allow_unsupported = 1;
+			else if (streq(option, "no") || streq(option, "0"))
+				allow_unsupported = 0;
+			else
+				goto syntax_error;
 		} else {
 syntax_error:
 			grammar(cmd, filename, linenum);
@@ -1407,6 +1438,17 @@ static int insmod(struct list_head *list,
 				strerror(errno));
 		goto out;
 	}
+	/* Supported? */
+	if (!allow_unsupported && !module_supported(module)) {
+		if (error == fatal)
+			fatal_exit_code = 2;
+		error("module '%s' is unsupported\n"
+		      "Use --allow-unsupported or set allow_unsupported_modules to 1 in\n"
+		      "/etc/modprobe.d/10-unsupported-modules.conf\n",
+		      mod->filename);
+		goto out;
+	}
+
 	if (flags & mit_strip_modversion)
 		module->ops->strip_section(module, "__versions");
 	if (flags & mit_strip_vermagic)
@@ -1591,6 +1633,17 @@ int do_modprobe(const char *modname,
 	LIST_HEAD(list);
 	int failed = 0;
 
+	if (flags & mit_force_allow_unsupported)
+		allow_unsupported = 1;
+	/* Be nice to people running non-suse kernels and allow
+	 * unsupported modules */
+	if (!allow_unsupported) {
+		if (access("/proc/sys/kernel/", F_OK) == 0 &&
+		    access("/proc/sys/kernel/unsupported", F_OK) == -1 &&
+		    errno == ENOENT)
+			allow_unsupported = 1;
+	}
+
 	matching_aliases = find_aliases(conf->aliases, modname);
 
 	/* No luck?  Try symbol names, if starts with symbol:. */
@@ -1694,6 +1747,7 @@ static struct option options[] = { { "version", 0, NULL, 'V' },
 				   { "force-modversion", 0, NULL, 2 },
 				   { "first-time", 0, NULL, 3 },
 				   { "dump-modversions", 0, NULL, 4 },
+				   { "allow-unsupported-modules", 0, NULL, 128 },
 				   { NULL, 0, NULL, 0 } };
 
 int main(int argc, char *argv[])
@@ -1800,6 +1854,9 @@ int main(int argc, char *argv[])
 		case 4:
 			dump_modver = 1;
 			break;
+		case 128:
+			flags |= mit_force_allow_unsupported;
+			break;
 		default:
 			print_usage(argv[0]);
 		}
diff --git a/modprobe.d.5 b/modprobe.d.5
index d0ed026..a83566a 100644
--- a/modprobe.d.5
+++ b/modprobe.d.5
@@ -1 +1 @@
-.so modprobe.conf.5
+.so man5/modprobe.conf.5
diff --git a/zlibsupport.c b/zlibsupport.c
index 597820e..0f78524 100644
--- a/zlibsupport.c
+++ b/zlibsupport.c
@@ -12,6 +12,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "zlibsupport.h"
 #include "logging.h"
@@ -19,52 +21,35 @@
 
 #ifdef CONFIG_USE_ZLIB
 #include <zlib.h>
+#endif
 
-void *grab_contents(gzFile *gzfd, unsigned long *size)
+#ifdef CONFIG_USE_ZLIB
+static int check_gz_magic(int fd)
 {
-	unsigned int max = 16384;
-	void *buffer = NOFAIL(malloc(max));
-	int ret;
+	unsigned char magic[2];
 
-	*size = 0;
-	while ((ret = gzread(gzfd, buffer + *size, max - *size)) > 0) {
-		*size += ret;
-		if (*size == max)
-			buffer = NOFAIL(realloc(buffer, max *= 2));
-	}
-	if (ret < 0) {
-		free(buffer);
-		buffer = NULL;
-	}
-
-	return buffer;
+	if (read(fd, magic, 2) != 2)
+		return -1;
+	lseek(fd, 0, SEEK_SET);
+	if (magic[0] == 0x1f && magic[1] == 0x8b)
+		return 1;
+	return 0;
 }
 
-/* gzopen handles uncompressed files transparently. */
-void *grab_file(const char *filename, unsigned long *size)
+static char *tmpdir(void)
 {
-	gzFile gzfd;
-	void *buffer;
-
-	errno = 0;
-	gzfd = gzopen(filename, "rb");
-	if (!gzfd) {
-		if (errno == ENOMEM)
-			fatal("Memory allocation failure in gzopen\n");
-		return NULL;
-	}
-	buffer = grab_contents(gzfd, size);
-	gzclose(gzfd);
-	return buffer;
-}
+	static char *TMPDIR;
 
-void release_file(void *data, unsigned long size)
-{
-	free(data);
+	if (TMPDIR)
+		return TMPDIR;
+	TMPDIR = getenv("TMPDIR");
+	if (!TMPDIR)
+		TMPDIR = "/tmp";
+	return TMPDIR;
 }
-#else /* ... !CONFIG_USE_ZLIB */
+#endif
 
-void *grab_fd(int fd, unsigned long *size)
+void *do_grab_fd(int fd, unsigned long *size)
 {
 	struct stat st;
 	void *map;
@@ -80,6 +65,60 @@ void *grab_fd(int fd, unsigned long *size)
 	return map;
 }
 
+void *grab_fd(int fd, unsigned long *size)
+{
+#ifdef CONFIG_USE_ZLIB
+	int magic = check_gz_magic(fd);
+	if (magic == -1)
+		return NULL;
+	if (magic) {
+		gzFile gzfd;
+		int tmp;
+		char buffer[4096];
+		char *template;
+		int r, w;
+		void *ret = NULL;
+
+		template = NOFAIL(malloc(strlen(tmpdir()) + sizeof("/m-i-t.XXXXXX")));
+		sprintf(template, "%s/m-i-t.XXXXXX", tmpdir());
+		gzfd = gzdopen(dup(fd), "rb");
+		if (!gzfd) {
+			if (errno == ENOMEM)
+				fatal("Memory allocation failure in gzdopen\n");
+			goto out_template;
+		}
+		tmp = mkstemp(template);
+		if (tmp == -1)
+			goto out_template;
+
+		while ((r = gzread(gzfd, buffer, sizeof(buffer))) > 0) {
+			char *p = buffer;
+			do {
+				w = write(tmp, p, r);
+				if (w > 0) {
+					r -= w;
+					p += w;
+				}
+			} while (w > 0 || (w == -1 && errno == EINTR));
+			if (w == -1)
+				goto out;
+		}
+		if (r < 0)
+			goto out;
+		gzclose(gzfd);
+		ret = do_grab_fd(tmp, size);
+out:
+		close(tmp);
+		unlink(template);
+out_template:
+		free(template);
+		return ret;
+	} else
+#endif
+		return do_grab_fd(fd, size);
+}
+
+
 void *grab_file(const char *filename, unsigned long *size)
 {
 	int fd;
@@ -97,4 +136,4 @@ void release_file(void *data, unsigned long size)
 {
 	munmap(data, size);
 }
-#endif
+
openSUSE Build Service is sponsored by