[PATCH] apply blacklist to builtin aliases only

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

 



modprobe.conf(5) says:
"the blacklist keyword indicates that all of that particular module's internal 
aliases are to be ignored"

However, currently the keyword causes even manually defined aliases to be 
ignored.

Attached patches add a testcase and a fix for the issue. Since I removed 
apply_blacklist(), I added reverse_aliases() to prevent the module load order 
from changing (as modules.order handling depends on this).

The third patch makes the testsuite more strict about module load order, as 
modules.order handling expects modules to be loaded in the order they are 
mentioned in modules.alias.

-- 
Anssi Hannula
>From 7c27ae5b899137f4c67d6c9852b73b63f6418763 Mon Sep 17 00:00:00 2001
From: Anssi Hannula <anssi.hannula@xxxxxx>
Date: Wed, 5 May 2010 19:59:00 +0300
Subject: [PATCH 1/3] tests: add a testcase for a blacklist against a manual alias target

---
 tests/test-modprobe/26blacklist.sh |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/tests/test-modprobe/26blacklist.sh b/tests/test-modprobe/26blacklist.sh
index 482ee93..e63db67 100755
--- a/tests/test-modprobe/26blacklist.sh
+++ b/tests/test-modprobe/26blacklist.sh
@@ -35,6 +35,10 @@ echo "alias bar foo" >> $MODULE_DIR/modules.alias
 echo "blacklist foo" >> tests/tmp/etc/modprobe.d/modprobe.conf
 [ "`modprobe bar 2>&1`" = "FATAL: Module bar not found." ]
 
+# Blacklist doesn't affect aliases in config file.
+echo "alias bar foo" >> tests/tmp/etc/modprobe.d/modprobe.conf
+[ "`modprobe bar 2>&1`" = "INIT_MODULE: $SIZE2 " ]
+
 # Remove blacklist, all works.
 rm -f tests/tmp/etc/modprobe.d/modprobe.conf
 RESULT="`modprobe bar 2>&1`"
-- 
1.6.4.4

>From b36f7dd5c6df5b617b1bc9cb1ad4a482dd1ec428 Mon Sep 17 00:00:00 2001
From: Anssi Hannula <anssi.hannula@xxxxxx>
Date: Wed, 5 May 2010 20:02:31 +0300
Subject: [PATCH 2/3] modprobe: do not apply blacklist for manually defined aliases

modprobe.conf(5) says that a blacklist entry will cause all the
internal aliases to be ignored. Fix modprobe to actually behave so.
---
 modprobe.c |   38 +++++++++++++++++++-------------------
 1 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/modprobe.c b/modprobe.c
index 26a7163..e8f325c 100644
--- a/modprobe.c
+++ b/modprobe.c
@@ -458,21 +458,19 @@ find_blacklist(const char *modname, const struct module_blacklist *blacklist)
 	return 0;
 }
 
-/* delete backlisted elems from a list of aliases */
-static void
-apply_blacklist(struct module_alias **aliases,
-		const struct module_blacklist *blacklist)
+/* Reverse a module alias list. */
+static struct module_alias *
+reverse_aliases(struct module_alias *alias)
 {
 	struct module_alias *result = NULL;
-	struct module_alias *alias = *aliases;
+	struct module_alias *new_next = NULL;
 	while (alias) {
-		char *modname = alias->module;
-		if (!find_blacklist(modname, blacklist))
-			result = add_alias(alias->aliasname, modname, result);
+		result = alias;
 		alias = alias->next;
+		result->next = new_next;
+		new_next = result;
 	}
-	free_aliases(*aliases);
-	*aliases = result;
+	return result;
 }
 
 /* Find install commands if any. */
@@ -997,6 +995,7 @@ static int read_aliases_file(const char *filename,
 static int read_aliases(const char *filename,
 			const char *name,
 			int dump_only,
+			struct module_blacklist *blacklist,
 			struct module_alias **aliases)
 {
 	char *line;
@@ -1025,13 +1024,14 @@ static int read_aliases(const char *filename,
 		}
 
 		if (streq(cmd, "alias")) {
-			char *wildcard = strsep_skipspace(&ptr, "\t ");
-			char *realname = strsep_skipspace(&ptr, "\t ");
+			char *wildcard = underscores(strsep_skipspace(&ptr, "\t "));
+			char *realname = underscores(strsep_skipspace(&ptr, "\t "));
 			if (!wildcard || !realname)
 				goto syntax_error;
-			if (fnmatch(underscores(wildcard),name,0) == 0)
+			if (fnmatch(wildcard,name,0) == 0 &&
+			    !find_blacklist(realname, blacklist))
 				*aliases = add_alias(wildcard,
-						     underscores(realname),
+						     realname,
 						     *aliases);
 		} else {
 syntax_error:
@@ -1598,7 +1598,7 @@ int do_modprobe(const char *modname,
 		char *symfilename;
 
 		nofail_asprintf(&symfilename, "%s/modules.symbols", dirname);
-		read_aliases(symfilename, modname, 0, &matching_aliases);
+		read_aliases(symfilename, modname, 0, conf->blacklist, &matching_aliases);
 		free(symfilename);
 	}
 	if (!matching_aliases) {
@@ -1614,7 +1614,7 @@ int do_modprobe(const char *modname,
 
 			nofail_asprintf(&aliasfilename, "%s/modules.alias",
 					dirname);
-			read_aliases(aliasfilename, modname, 0,
+			read_aliases(aliasfilename, modname, 0, conf->blacklist,
 				     &matching_aliases);
 			free(aliasfilename);
 			/* builtin module? */
@@ -1626,7 +1626,7 @@ int do_modprobe(const char *modname,
 		}
 	}
 
-	apply_blacklist(&matching_aliases, conf->blacklist);
+	matching_aliases = reverse_aliases(matching_aliases);
 	if(flags & mit_resolve_alias) {
 		struct module_alias *aliases = matching_aliases;
 
@@ -1845,8 +1845,8 @@ int main(int argc, char *argv[])
 		nofail_asprintf(&aliasfilename, "%s/modules.alias", dirname);
 		nofail_asprintf(&symfilename, "%s/modules.symbols", dirname);
 
-		read_aliases(aliasfilename, "", 1, &conf.aliases);
-		read_aliases(symfilename, "", 1, &conf.aliases);
+		read_aliases(aliasfilename, "", 1, NULL, &conf.aliases);
+		read_aliases(symfilename, "", 1, NULL, &conf.aliases);
 
 		goto out;
 	}
-- 
1.6.4.4

>From 2de5b868bcf6f15dc50893f49fdb71719f91901d Mon Sep 17 00:00:00 2001
From: Anssi Hannula <anssi@xxxxxxxxxxxx>
Date: Wed, 5 May 2010 20:26:08 +0300
Subject: [PATCH 3/3] tests: enforce module load order if multiple aliases exist

For correct behaviour with modules.order, the modules have to be loaded
in the order the aliases are mentioned in modules.alias.
---
 tests/test-modprobe/10alias.sh     |    5 ++---
 tests/test-modprobe/26blacklist.sh |    3 +--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/tests/test-modprobe/10alias.sh b/tests/test-modprobe/10alias.sh
index c5abf43..5525bfe 100755
--- a/tests/test-modprobe/10alias.sh
+++ b/tests/test-modprobe/10alias.sh
@@ -47,10 +47,9 @@ echo "options bar option1" > tests/tmp/etc/modprobe.d/modprobe.conf
 echo "options alias-$BITNESS option2" >> tests/tmp/etc/modprobe.d/modprobe.conf
 [ "`modprobe bar 2>&1`" = "INIT_MODULE: $SIZE option2 option1" ]
 
-# Duplicated alias: both get probed (either order)
+# Duplicated alias: both get probed (first alias is loaded first)
 echo "alias bar foo" >> $MODULE_DIR/modules.alias
 OUT="`modprobe bar 2>&1`"
 
 [ "$OUT" = "INIT_MODULE: $SIZE option2 option1
-INIT_MODULE: $SIZE2 option1" ] || [ "$OUT" = "INIT_MODULE: $SIZE2 option1
-INIT_MODULE: $SIZE option2 option1" ]
+INIT_MODULE: $SIZE2 option1" ]
diff --git a/tests/test-modprobe/26blacklist.sh b/tests/test-modprobe/26blacklist.sh
index e63db67..976390f 100755
--- a/tests/test-modprobe/26blacklist.sh
+++ b/tests/test-modprobe/26blacklist.sh
@@ -43,5 +43,4 @@ echo "alias bar foo" >> tests/tmp/etc/modprobe.d/modprobe.conf
 rm -f tests/tmp/etc/modprobe.d/modprobe.conf
 RESULT="`modprobe bar 2>&1`"
 [ "$RESULT" = "INIT_MODULE: $SIZE 
-INIT_MODULE: $SIZE2 " ] || [ "$RESULT" = "INIT_MODULE: $SIZE2
-INIT_MODULE: $SIZE " ]
+INIT_MODULE: $SIZE2 " ]
-- 
1.6.4.4


[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